Capture OpenGL screen pixels
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
Code:
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
Re: Capture OpenGL screen pixels
How about simply calling QGLWidget::renderPixmap() instead?
Re: Capture OpenGL screen pixels
I'm using QImage QGLWidget::grabFrameBuffer(bool withAlpha = false)
http://doc.trolltech.com/4.5/qglwidg...rabFrameBuffer
Re: Capture OpenGL screen pixels
You can also use QPixmap::grabWindow() and set the coordinates to your QGLWidget. I use this because I only need to render part of the OpenGL scene.