About pixel-space and object-space!

Hi there,

I want to know if i can mix glPerspective and glOrtho in my program. ie, i need draw four pictures
on the four corners of my client area and a ball in the middle, the ball must rotate repeatedly.
if i only use glOrtho and the pixel space, the ball cannt work(i am not sure about this, can anybody
tell me if i was right?), because it has a depth(z) component. so i want to do the following:

first:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, w, 0.0, h, 0.1f, 100.0f);

//draw the four pictures at here

second:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)w/(GLfloat)h, 0.1f, 100.0f);

//draw the ball and rotate it.

could this works well? Thanks a lot!

Hi Davie,

I want to know if i can mix glPerspective and glOrtho in my program

Yes you can mix both projection in the way you’re doing it.

Hi Exoide,

Thanks for your reply! but when i do this, i can only see the
ball and the four pictures disappear. I dont know why, i will
check it later. thx again!

Hi Davie,

If you were seeing your four pictures before maybe you should reset your model-view matrix after changing the projection to perspective projection.

Here’s your code:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)w/(GLfloat)h, 0.1f, 100.0f);

try adding the following lines after the code above

glMatrixMode(GL_MODELVIEW);
glPushMatrix(); // Only in case you need to restore the previous model-view matrix
glLoadIdentity();

Hi Exoide,

Thanks for your help!