Hello! I am working on a 2D game using OpenGL ES. I am using the orthographic projection, since it makes the 2D stuff easy. Now I would like to create a simple 3D effect, say rotate a sprite around the Y axis (something like cover flow). If I understand things correctly, this can’t be done in the ortho projection. Is it possible to do it without messing up the rest of the code? Like switch the projection in the middle of the frame, treat the current frame image as a background and draw the 3D stuff above the background?
+5
A:
Yes, this is possible: just save the old projection matrix, load a new one, and restore the old one when you're done.
void DrawScene()
{
Draw2DStuff();
glMatrixMode(GL_PROJECTION);
glPushMatrix(); // Save old projection matrix
gluPerspective(...); // Load new projection matrix
Draw3DStuff();
glMatrixMode(GL_PROJECTION);
glPopMatrix(); // Restore old projection matrix
}
Just be careful about the depth buffer - you may need to play around with the depth buffer settings when switching between 2D and 3D rendering in order for things to get drawn correctly.
Adam Rosenfield
2008-12-02 20:33:05