changing to a different type of projection on the fly...

Started by
3 comments, last by dfanuk 22 years ago
Hello In my program I need to change to ortho2D type projection to draw something after drawing some things in Perspective projection. so this is my code from DrawGLScene, it comes after I''ve drawn some quads and text: Code: glPushMatrix(); glMatrixMode(GL_PROJECTION); gluOrtho2D(97, 542, 433, 124); //switch to ortho projection to draw the lines glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f,0.0f,-6.0f); //do some stuff glPopMatrix(); The problem at the mo is that I get a blank screen. If I comment out the above code I get the things I had previously drawn but if I leave it in I get nothing but the colour I have set the background to. any ideas what I am doing wrong? thanks Gareth <>< ps I have put 97, 542, 433, 124 because I want a small section on my screen only, but before I came up with that idea I had it at 0, 640, 480, 0 I''m not sure about this either
Advertisement
Hi,
I think you should call glMatrixMode(GL_PROJECTION) *before* glPushMatrix() and before glPopMatrix()...

----
David Sporn AKA Sporniket

[edited by - davidsporn on April 18, 2002 11:24:22 AM]
ah right, ok thanks

what about the pop matrix line, is that in the right place?

I just had a thought, should I be specifying a viewport in this bit of code too?

glViewport(97, 542, 433, 124);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
gluOrtho2D(0.0, 640.0, 480.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glTranslatef(0.0f,0.0f,-6.0f);

//do stuff here

glPopMatrix();

I just tried this new code and it just does the same as before

thanks,
Gareth
<><
You need glLoadIdenity after glPushMatrix, since gluOrtho does not replace the matrix, but multiplies the projection matrix with the current matrix and then replaces the current matrix with this resulting matrix.

-Lev

[edited by - Lev Povalahev on April 18, 2002 11:48:09 AM]
You also need to specify the projection matrix mode before the popmatrix call, otherwise OGL will pop the modelview matrix.

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

/ Yann

This topic is closed to new replies.

Advertisement