PDA

View Full Version : Problem: glCopyPixels doesn't work right



Pa3PyX
08-19-2002, 09:49 PM
Anyone has a clue on the following problem? I'm trying to use glCopyPixels to copy a portion of the front buffer to my current drawing back buffer, using approx. the following code:

/* Do some regular drawing to back buffer */
...
/* Display the back buffer and set what was front buffer to now be the back buffer */
SwapBuffers(DC);
/* Set viewport */
...
/* Set projection and modelview matrices to identity, set orthogonal projection */
...
/* Front buffer contents is defined (I see a meaningful image on the screen, one that was drawn previously), and the window is initialized to use double buffering, so both GL_FRONT and GL_BACK are defined) */
/* Disable alpha test, depth test and texturing */
glDisable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_2D);
/* Set front buffer to read from */
glReadBuffer(GL_FRONT);
/* Set back buffer to write into */
glDrawBuffer(GL_BACK);
/* Set current raster position - I verified that it is inside the viewport, so no prob with that, and it is located in the lower left corner of the screen */
glRasterPos2i(x, y);
/* Wait for all framebuffer changes to complete */
glFinish();
/* Copy a rectangular region from the front buffer to back buffer */
glCopyPixels(0, 0, 150, 150, GL_COLOR);
/* (Or even tried 1, 1 instead of 0, 0) */
/* Wait for the copying changes to complete */
glFinish();
/* Display the changes */
SwapBuffers(DC);
// Restore application settings
glEnable(GL_DEPTH_TEST);
glEnable(GL_ALPHA_TEST);
glEnable(GL_TEXTURE_2D);
// Loop to the beginning


No matter how hard I try - additional precautions like glFinish, making sure raster position is valid - and it is, since glDrawPixels works fine in this setup - but not glCopyPixels. When I attempt this, instead of seeing that rectangular region unchanged on the screen (like the intention is), I see it get filled with garbage after the very first iteration (Windows's software OpenGL implementation).

Furthermore, if I try hardware accelerated OpenGL, the program just crashes - throws me right to desktop, without any warnings or explanations.

System: Windows 98 SE
Video board: 3Dfx Voodoo 3

Any ideas of what's going on, and how to accomplish copying the contents of one frame buffer to another?

Also, let me make sure my assumption is correct. AFAIK, SwapBuffers() call exchanges front and back buffers. That is, the entire contents of the front buffer now becomes the contents of the back buffer, and vice versa.