I am using OpenGL in 2D mode to make a game with a static environment from a fixed camera perspective.
I want to
- Pre-render the static environment.
- Store the resulting 2D image to the GPU including both colour and depth channels
- Recall the pixels quickly.
Here is what I think I am supposed to do:
Create a frame buffer object
Create two renderbuffer objects: one colour, one depth, both 256x256 pixels
Attach both renderbuffers to the appropriate attachment points on the framebuffer.
Bind the virtual frame buffer, draw an image with depth parameters specified.
use glCopyPixels() to copy it to the screen. <–XX DANGER: THIS IS WHERE THINGS GO WRONG
steps_1_through_4_above(); //create an FBO w/ 2xRBOs, and draw a picture to it. glLoadIdentity (); glOrtho (0, 256, 256, 0, 0, 1); glViewport(0,0,256,256); glMatrixMode (GL_MODELVIEW); glPixelTransferi(GL_MAP_COLOR,true); glRasterPos2i(256,256); glCopyPixels(0,0,256,256,GL_COLOR);
My problem is specifically that I cannot seem to figure out how to copy the pixels from one frame buffer to another one.
I think I’ve isolated the problem to specifically this and nothing else that is obvious. steps 1 through 4 are working properly, and I am properly invoking my OSes double-buffer switching routine in order to actually display the results. I get a black square but not the image I rendered, which I checked with some alternate code that renders to a texture (a technique I am familiar with).
I believe my problem is a misunderstanding with glCopyPixels(). I could not find a working example of glCopyPixels() copying from a virtual frame buffer object to the screen, so finally I ask for advice.
How do I copy pixels from one frame buffer object to another including the depth and colour components?