Author Message

<  advanced  ~  opengl line not the same size after mirroring

PostPosted: Sun Nov 08, 2009 1:31 am
Joined: Sat Feb 21, 2009 6:02 pmPosts: 56
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:

Code:
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


Offline Profile
PostPosted: Sun Nov 08, 2009 4:13 pm
Joined: Sat Feb 21, 2009 6:02 pmPosts: 56
hallo again,

here is a pic of what i mean:
Image
the picture schows the painted line 500% increased

here is the code to the above picture:
Code:
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?


Offline Profile
PostPosted: Tue Nov 10, 2009 10:05 am
User avatarJoined: Fri Jul 04, 2008 9:31 amPosts: 414Location: Vienna, Austria
i think you might be having rounding issues, since you're passing ints rather than floats. try this:
Code:
        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);



_________________
damian stewart | skype: damiansnz | damian [at] frey [dot] co [dot] nz
frey | live art with machines | http://www.frey.co.nz
Offline Profile
PostPosted: Tue Nov 10, 2009 12:12 pm
Joined: Sat Feb 21, 2009 6:02 pmPosts: 56
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.
Code:
        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);

Image

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


Offline Profile
PostPosted: Tue Nov 17, 2009 1:49 pm
Joined: Sat Feb 21, 2009 6:02 pmPosts: 56
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!


Offline Profile
PostPosted: Wed Nov 18, 2009 9:20 pm
User avatarJoined: Tue May 27, 2008 10:03 amPosts: 691Location: London, UK
just out of curiosity, could you try glScalef(-1, 1, 1); instead of two rotations?


Offline Profile
PostPosted: Thu Nov 19, 2009 6:42 pm
Joined: Sat Feb 21, 2009 6:02 pmPosts: 56
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...
Image
this is the result.
here is the code:
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();
}


Offline Profile
PostPosted: Tue Dec 29, 2009 6:23 pm
Joined: Sat Feb 21, 2009 6:02 pmPosts: 56
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...


Offline Profile

Display posts from previous:  Sort by:

All times are UTC
Page 1 of 1
8 posts
Users browsing this forum: No registered users and 1 guest
Search for:
Post new topic  Reply to topic
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
cron