PDA

View Full Version : screen shot



Zork
11-10-2002, 01:19 AM
I'm a totally OpenGL beginner so I don't know how rgb and alpha values are stored in OpenGL's
buffers.So, let's suppose I have something on screen and I want to save the screen or a portion of the screen in a raw format.How can I do this?Does anybody know of a good tutorial targeted to this thing?
I think is rather simple, but I am a newbie and it doesn't say how to do it in the Red Book.

Bob
11-10-2002, 02:40 AM
Taking a screen shot is actually quite simple. You read the pixels with glReadPixels into your own buffer and then save it. For a 800x600 window, it looks something like this.



unsigned char *buf = new unsigned char[600*800*3]; // 3 for RGB, change to 4 for RGBA
glReadPixels(0, 0, 800, 600, GL_RGB, GL_UNSIGNED_BYTE, buf); // change RGB to RGBA if you want the alpha channel.

buf is now filled with whatever was in buffer set for reading in OpenGL. You have to be carefull with what buffer is actually set for reading. The default read buffer in a double buffered application is the back buffer. That means, if you want to read the contents of the screen, you have to change the read buffer to the front buffer.



glReadBuffer(GL_FRONT);

Zork
11-10-2002, 03:39 AM
Thanks! It works!