opengl line not the same size after mirroring

hallo people,

at the moment i am testing different opengl actions in openframeworks.
for example i draw a line then translate/mirror the scene like this:

  
  
ofPushMatrix();  
ofTranslate(centerX,centerY);  
  
    for(int j=0;j<2;j++){  
        glBegin(GL_LINE_STRIP);  
        glVertex2f(0,0);  
        glVertex2f(objectHeight/2,objectHeight/2);  
        glVertex2f(objectHeight/2,objectHeight+underLength-1);  
        glVertex2f(objectHeight/2-1,objectHeight+underLength);  
        glEnd();  
        ofTranslate(3,0);  
          
        ofRotateZ(180);  
        ofRotateX(180);  
        ofTranslate(objectHeight,0);  
    }  
  
ofPopMatrix();  
  

now i have the problem that the second object dont looks like the first drawn.
it seems that all horicontal values are shorten around 1 pixel. i hope that you can understand what i mean.
does anyone have an idea what is going wrong here?

and maybe someone can tell me if there is a way in opengl to duplicate a once painted object to draw it twice.

i hope that it is ok to ask an opengl related question here.

//robert

hallo again,

here is a pic of what i mean:

the picture schows the painted line 500% increased

here is the code to the above picture:

  
  
ofPushMatrix();  
    ofTranslate(centerX,centerY);  
  
    for(int j=0;j<2;j++){  
        glBegin(GL_LINE_STRIP);  
        glVertex2f(0,0);  
        glVertex2f(10/2,10/2);  
        glVertex2f(10/2,10+10-1);  
        glVertex2f(10/2-1,10+10);  
        glEnd();  
  
        ofRotateZ(180);  
        ofRotateX(180);  
        ofTranslate(10,0);  
    }  
  
    ofPopMatrix();  
  

maybe this describes better what i mean.
can someone tell me what i do wrong?

i think you might be having rounding issues, since you’re passing ints rather than floats. try this:

  
  
        glBegin(GL_LINE_STRIP);  
        glVertex2f(0,0);  
        glVertex2f(10.0/2,10.0/2);  
        glVertex2f(10.0/2,10.0+10-1);  
        glVertex2f(10.0/2-1,10.0+10);  
        glEnd();  
  
        ofRotateZ(180);  
        ofRotateX(180);  
        ofTranslate(10,0);  
  

hey damian,

thanks for the idea with the rounding.
i used float values but this had no effect.
than i used an angel of 181° for the rotation. now i get the right result.

  
  
        glBegin(GL_LINE_STRIP);  
        glVertex2f(0,0);  
        glVertex2f(5.0,5.0);  
        glVertex2f(5.0,19.0);  
        glVertex2f(4.0,20.0);  
        glEnd();  
  
        ofRotateZ(181);  
        ofRotateX(181);  
        ofTranslate(10,0);  
  

can it be that the the line is 1 pixel behind the position it schould be, when i rotate 180°?

i am still confused about the above described.
the confusing is that i can also draw a line backwards instead of mirroring and it also has not the same size and pixel positions as the orginal forward drawn line.
this is not a problem if i dont work pixelaccurate but i need each pixel at the right position. maybe opengl is not the right tool for pixelaccurate drawing…please tell me!

just out of curiosity, could you try glScalef(-1, 1, 1); instead of two rotations?

hey memo i tried also your method. thanks for it. but the effect was the same.
maybe it is not possible to draw such a thin 1 pixel line in opengl in such a precise way.

i tried 4 different methods with mirroring and without and some other ways…

this is the result.
here is the code:

  
  
void testApp::draw(){  
  
    ofPushMatrix();  
    ofTranslate(1024/2+60,768/2);  
  
    glBegin(GL_LINES);  
        glVertex2f(30,0);  
        glVertex2f(35.0,5.0);  
    glEnd();  
    glBegin(GL_LINES);  
        glVertex2f(35.0,5.0);  
        glVertex2f(35.0,19.0);  
    glEnd();  
    glBegin(GL_LINES);  
        glVertex2f(35.0,19.0);  
        glVertex2f(34.0,20.0);  
    glEnd();  
    glBegin(GL_LINES);  
        glVertex2f(20,0);  
        glVertex2f(15.0,5.0);  
    glEnd();  
    glBegin(GL_LINES);  
        glVertex2f(15.0,5.0);  
        glVertex2f(15.0,19.0);  
    glEnd();  
    glBegin(GL_LINES);  
        glVertex2f(15.0,19.0);  
        glVertex2f(16.0,20.0);  
    glEnd();  
    ofPopMatrix();  
  
    ofPushMatrix();  
    ofTranslate(1024/2+30,768/2);  
  
    glBegin(GL_LINE_STRIP);  
        glVertex2f(30,0);  
        glVertex2f(35.0,5.0);  
        glVertex2f(35.0,19.0);  
        glVertex2f(34.0,20.0);  
    glEnd();  
    glBegin(GL_LINE_STRIP);  
        glVertex2f(20,0);  
        glVertex2f(15.0,5.0);  
        glVertex2f(15.0,19.0);  
        glVertex2f(16.0,20.0);  
    glEnd();  
    ofPopMatrix();  
  
    ofPushMatrix();  
    ofTranslate(1024/2,768/2);  
  
    for(int j=0;j<2;j++){  
        glBegin(GL_LINE_STRIP);  
        glVertex2f(0,0);  
        glVertex2f(5.0,5.0);  
        glVertex2f(5.0,19.0);  
        glVertex2f(4.0,20.0);  
        glEnd();  
  
        ofRotateZ(180);  
        ofRotateX(180);  
        ofTranslate(10,0);  
    }  
  
    ofPopMatrix();  
  
    ofPushMatrix();  
    ofTranslate(1024/2+30,768/2);  
  
    for(int j=0;j<2;j++){  
        glBegin(GL_LINE_STRIP);  
        glVertex2f(0,0);  
        glVertex2f(5.0,5.0);  
        glVertex2f(5.0,19.0);  
        glVertex2f(4.0,20.0);  
        glEnd();  
  
        glScalef(-1, 1, 1);  
        ofTranslate(10,0);  
    }  
    ofPopMatrix();  
}  
  

hey hey,

it was a hard way to find this stupid reason but now i have the answer. i found it here:

http://www.gamedev.net/community/forums-…–id=556634

a line is not a line, it is a rect. so i positioned it not on 0 but rather on 0.5 and the problem is away.

Rectangle:
A-----B
| |
| |
C-----D

Line made from rectangle:

|A|
| |
| |

B

maybe this helps someone…