PDA

View Full Version : Capture OpenGL screen pixels



Windsoarer
30th April 2009, 21:59
The problem I face is really simple : I'd like to implement some code to capture an OpenGl display on the screen to an image file.

It should be something like



Step 1 : NbBytes = size.width() * size.height() * screen_pixel_format/8;
Step 2 : uchar *pPixelData = new uchar[NbBytes];
Step 3 : glReadPixels(0,0,size.width(),size.height(),GL_BGR _EXT,GL_UNSIGNED_BYTE,pPixelData);
Step 4 : QImage Image(pPixelData, size.width(),size.height(), NbBytes/ size.height(), QImage::Format_RGB888);
Step 5 : Image.save(FileName);


Step 0 would be to find out what is the screen's pixel format, and which pixel format OpenGl is using : 8, 16, or 24 bits ? Is there way to get this information in Qt ?

Thanks

wysota
4th May 2009, 12:59
How about simply calling QGLWidget::renderPixmap() instead?

fanat9
4th May 2009, 16:31
I'm using QImage QGLWidget::grabFrameBuffer(bool withAlpha = false)

http://doc.trolltech.com/4.5/qglwidget.html#grabFrameBuffer

rbp
5th May 2009, 04:24
You can also use QPixmap::grabWindow() (http://doc.trolltech.com/4.5/qpixmap.html#grabWindow) and set the coordinates to your QGLWidget. I use this because I only need to render part of the OpenGL scene.