PDA

View Full Version : problems with 2d controls over 3d rendering



mithun_daa
12-09-2003, 02:01 PM
i wanna have a 2d compass in my 3d scene to show which direction im headed. i have followed the steps at the following link http://www.opengl.org/developers/faqs/technical/transformations.htm#tran0030

im not using overlays. i am drawing it over my 3d rendering.

'display routine

draw in 3d space
......
glDisable (GL_DEPTH_TEST)

'my 2d control

glMatrixMode GL_PROJECTION
glLoadIdentity
gluOrtho2D 0, intWidth, 0, intHeight
glMatrixMode GL_MODELVIEW
glLoadIdentity
glPushMatrix
glTranslated intWidth - 100, intHeight - 100, 0
glRotated intRotatey, 0, 0, 1
glMaterialfv faceFrontAndBack, mprAmbientAndDiffuse, ambient_color(0)
glBegin bmLines
glVertex2f 0, -50
glVertex2f 0, 50
glEnd
glPopMatrix
glFinish
SwapBuffers mlngPic1hDC

now the problem is that when it renders the scene for the first time, only the 2D control is visible. when i zoom in/out, the scene is rendered again with my 2d control being rendered right, but, exactly once the whole scene goes black and comes on again. is ther something im missing out? or is my whole approach wrong?
thank u

514VOID
12-09-2003, 07:35 PM
Maybe swapbuffer then glfinish would help?

mithun_daa
12-10-2003, 06:40 AM
Originally posted by 514VOID:
Maybe swapbuffer then glfinish would help?

nope, it doesnt help

obirsoy
12-10-2003, 06:56 AM
I think the correct order should be
glMatrixMode(GL_MODELVIEW);
glPushMatrix(); // these two lines
glLoadIdentity(); // are swaped
.
glPopMatrix();

You are also changing your projection matrix. Are you setting it back to your 3D projection?
You can also use
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho2D(....);
.
.
glMatrixMode(GL_PROJECTION); // Edit ...
glPopMatrix(); // note this is not the one that pops the modelview matrix


[This message has been edited by obirsoy (edited 12-10-2003).]

mithun_daa
12-10-2003, 07:42 AM
alright, herez the new order
glMatrixMode GL_PROJECTION
glPushMatrix
glLoadIdentity
gluOrtho2D 0, intWidth, 0, intHeight
glMatrixMode GL_MODELVIEW
glPushMatrix
glLoadIdentity
glPushMatrix
glTranslated intWidth - 100, intHeight - 100, 0
glRotated intRotatey, 0, 0, 1
glBegin bmLines
glVertex2f 0, -50
glVertex2f 0, 50

glEnd
glPopMatrix
glPopMatrix
glPopMatrix
glFinish
SwapBuffers mlngPic1hDC

is this right? if it is then its still not workin. the one thing that i observed is that whenever my 2d control changes, my 3d rendering disappears, untill i zoom in/out.
thank u

in this case i dont need to set the projection matrix again for 3d rendering right?

[This message has been edited by mithun_daa (edited 12-10-2003).]

mithun_daa
12-10-2003, 07:58 AM
Originally posted by mithun_daa:
alright, herez the new order
glMatrixMode GL_PROJECTION
glPushMatrix
glLoadIdentity
gluOrtho2D 0, intWidth, 0, intHeight
glMatrixMode GL_MODELVIEW
glPushMatrix
glLoadIdentity
glPushMatrix
glTranslated intWidth - 100, intHeight - 100, 0
glRotated intRotatey, 0, 0, 1
glBegin bmLines
glVertex2f 0, -50
glVertex2f 0, 50

glEnd
glPopMatrix
glPopMatrix
glPopMatrix
glFinish
SwapBuffers mlngPic1hDC

is this right? if it is then its still not workin. the one thing that i observed is that whenever my 2d control changes, my 3d rendering disappears, untill i zoom in/out.
thank u

in this case i dont need to set the projection matrix again for 3d rendering right?

[This message has been edited by mithun_daa (edited 12-10-2003).]

i fixed it. thank u. u were right, i wasnt settin the projection mat. again. thank u.