3D effects in a 2D game using OpenGL

I am working on a 2D game using OpenGL ES. I use spelling projection, as this makes 2D material simple. Now I would like to create a simple 3D effect, say, rotate the sprite around the Y axis (something like a stream of covers). If I understand things correctly, this cannot be done in orthoprojection. Can this be done without messing up the rest of the code? How to switch the projection in the middle of the frame, process the current image of the frame as a background and draw 3D material over the background?

+4
source share
1 answer

Yes, it is possible: just save the old projection matrix, load the new one and restore the old one when 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 with the depth buffer - you may need to play with the depth buffer settings when switching between 2D and 3D rendering so things can be drawn correctly.

+6
source