I’m not sure why this is happening, but if I try to do a glReadPixels with a large screen, my program dies horribly inside OpenGL (Win32). If I cut back the size to something smaller it works fine (say 640x480). The size I’m trying to do is 1280x1024. The malloc on the pixels is working fine (I tried new and a couple of other things, but Windows is fine giving me the 1.5mb of memory I ask for). It’s just glReadPixels fails if the size is too big. Anyone have any ideas? Maybe there’s something extra I have to setup here before I do my screen capture? Here’s the code I’m using, pretty straight forward:
// Get the pixels from the screen
// 640x480 works but large values like
// 1280x1024 dont
int w = m_ClientRect.right;
int h = m_ClientRect.bottom;
int imageSize = 3 * w * h;
unsigned char *pPixelData = (unsigned char *)malloc(imageSize);
if(pPixelData != NULL)
{
// Copy from OpenGL
glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pPixelData);
// Create and save the image
…
// Cleanup
free(pPixelData);
}
Thanks!
liB