Archived

This topic is now archived and is closed to further replies.

Switch between 2D and 3D

This topic is 5233 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I want to draw a 2D interface in front of my 3D world. So I wanted to switch into 2D (via gluOrtho2D) after some research I came up with the following code - sadly it doesn''t work. It draws something but right in between of it all and defenetly not as it should be (somehow screwed up Can you see the problem or do you have another idea to do a 2D interface - thanx in advance! //switch to 2D glPushAttrib(GL_CURRENT_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0, _display->getWidth(), 0, _display->getHeight()); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); //return to 3D glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopAttrib();

Share this post


Link to post
Share on other sites
You may have switched the projection matrix to a 2d setup, but you''ve probably left depth testing enabled, so your 3d depths are interfering with your 2d drawing. Either disable the depth test, or call glClear() and reset the depth buffer before your 2d drawing.

Share this post


Link to post
Share on other sites
glPushAttrib(GL_CURRENT_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, _display->getWidth(), 0, _display->getHeight());
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();

Share this post


Link to post
Share on other sites
Thanx to both of you. Implemented that the same way as above and then wanted to draw a rectangle (maybe I should add that my GL display is 800x600):

glColor3f(0.0f, 0.6f, 0.0f);
glBegin(GL_QUADS);
glVertex2i(0, 0);
glVertex2i(0, 600);
glVertex2i(400, 600);
glVertex2i(400, 0);
glEnd();

The weird thing is that the rectangle has the wrong size (much too thin) and that it draws it behind a model that''s also in the scene (when I disable the model the shape doesn''t change so it should not be caused by any code from that part). So I added glDisable(GL_DEPTH_TEST) but still no change.

I guess it is a error from somewhere else that causes this defunct - but every test I could do (disable some part of the code and stuff) didn''t cause any change. *scratches his head*
Any suggestions?

Share this post


Link to post
Share on other sites