PDA

View Full Version : glCopyPixels



bubbaJr
01-22-2005, 06:42 PM
I have been trying for the past several hours to use glReadBuffer, glDrawBuffer, and glCopyPixels to copy one framebuffer to another. I am running Visual C++ .NET on Windows 2000. Also had similar bad luck at work using Visual Studio and Windows 2000.

Just found out that I don't have access to the following buffers: GL_BACK, GL_RIGHT, GL_FRONT_RIGHT, and GL_AUX0 - 3. So I won't try to use any of those buffers.

In my program, I'm writing bitmapped text to the GL_LEFT buffer after using:

glDrawBuffer(GL_LEFT)

And in the display callback function I've got:

void Display(void)
{
glReadBuffer(GL_LEFT);

glDrawBuffer(GL_FRONT_LEFT);

glRasterPos2i( 0, 0 );
glCopyPixels( 0, 0, 640, 480, GL_COLOR );
glFlush();
}

The bitmapped data is not appearing on the window after the callback is invoked. I've created the window using glut. Maybe I can't do this type of thing inside a glut callback function?

This is such a simple concept, it's got to work.

Thanks,
Arnold - we will pump you up

Relic
01-24-2005, 12:52 AM
It's not so simple as you think.
FYI, back buffers are only available in a double buffered pixelformat; right buffers are only available in a stereo pixelformat, which is only supported on professional workstation boards. AUX buffers are not supported on all OpenGL implementations.

You have a single buffered pixelformat, GL_LEFT is the same as GL_FRONT_LEFT then.
You want to copy a pixel grid from the lower left corner with 640*480 pixels size to the 3D(!) RasterPosition at (0,0,0).
You correctly set a glFlush after the copy operation, which is necessary in single buffered pixelformats to get the rendering displayed.

What is drawn at the lower left corner before the CopyPixels? All OpenGL rendering should be done in the Display() callback!

First, make sure the RasterPos coordinate (0,0,0) is in your viewing frustum (try drawing a point there) or you won't see any rendering. In the standard ortho projection with the identity modelview and projection matrix this is in the center of the window and in the center of the depth between zNear and zFar.

Make sure the coordinate is not at the window's lower left corner or you copy onto itself and won't see any change.

Make sure you have anything disabled which changes the copy operation from a source copy to a different raster operation. That is: disable depth test, disable lighting, disable logicop, disable texturing; for paranoia set the color to white before the rasterpos command (necessary if you use glBitmap to render your graphics).

bubbaJr
01-24-2005, 04:18 AM
Relic -

Thanks for your assistance.

In your reply you said: "All OpenGL rendering should be done in the Display() callback!" Which leads me to believe I should explain my concept for my design. Then maybe you can tell me if I'm using the right tools, i.e. glut. I'm probably stuck with windows.

My program will be writing to 4 displays. Each of the 4 displays will have unique contents, each different from one another. I feel it would be desirable to provide 4 regions of the framebuffer, 1 region for each display. We would draw into each region (NOT inside the display callback) then periodically transfer (inside the display callback) the contents of each region to each display. That's why I was trying to do glReadBuffer, glDrawBuffer, glCopyPixels. Note that there will be no mouse and no keyboard, and so no mouse or keyboard events/callbacks. So - the display callback - am not quite sure what to do with this. I suppose I could simply call glutPostRedisplay when I need to transfer pixels from a non-visible buffer to a visible one. I was also toying with the idea of discarding the display callback and periodically transferring the contents using a function dedicated to doing just that. If I have no event callbacks at all, then maybe I don't need glut at all.

I was using glut for the following reasons:

1. it's easy to use.
2. it simplifies window creation/management.
3. it allows me to look good when I'm really not.

Should I abandon glut altogether? I really don't want to. Would like to retain glut and have a program that's a mixture of glut and OpenGL.

Thanks
A.B.

MMMovania
01-24-2005, 06:23 AM
Hello,
From your discussion, I presume you are trying to create viewports of some kind.Have you tried creating sub windows in glut for that.Have a look at http://www.lighthouse3d.com/opengl/glut/index.php?subwinrender for help on this. Lets hope this helps. Thanx.