PDA

View Full Version : Black screenshots under vista



mlfarrell
02-25-2010, 04:50 PM
Any ideas as to why this code doesn't work. I get completely black screenshots on vista even with aero disabled



void *get_screenshot()
{
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
GLint w = viewport[2], h = viewport[3];

//just do the reading code right here
void *pixels = (void *)malloc(w*h*3);

glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
glReadBuffer(GL_FRONT);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, (void *)pixels);
glPopClientAttrib();
//glFlush(); havent gotten to test this yet. could this be what i'm missing?
return pixels;
}

bool save_screenshot(string filename, void *pixels)
{
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
GLint w = viewport[2], h = viewport[3];

const char *ext = get_path_extension(filename.c_str());
if(!ext || string(ext) != "jpg")
filename += ".jpg";
bool ret = false;
ret = write_jpeg(filename.c_str(), w, h, (JSAMPLE *)pixels);
free(pixels);
return ret;
}

zeoverlord
02-25-2010, 06:17 PM
well first your reading the front buffer, now i don't know how that will effect things but i prefer the back buffer as it's guaranteed to contain the data you need if you call it just before you swap the buffers.

If you want some working simple code then go here.
http://www.flashbang.se/index.php?id=69

it creates uncompressed tga's but it works really well

James W. Walker
02-25-2010, 06:21 PM
I agree about using the back buffer. If you want to try glFlush, you should call it before glReadPixels.

zeoverlord
02-25-2010, 06:38 PM
well you could, but glReadPixels will do that automatically, in fact it will basically call a glFinish, glFlush is all but deprecated as its basically only a hint to start rendering which i have found no good use for (as that happens automatically).

mlfarrell
02-25-2010, 07:07 PM
will try gl_back thanks!

James W. Walker
02-25-2010, 07:10 PM
well you could, but glReadPixels will do that automatically, in fact it will basically call a glFinish, glFlush is all but deprecated as its basically only a hint to start rendering which i have found no good use for (as that happens automatically).

I've heard that theory, but in practice I've found that I sometimes need glFlush. Maybe certain drivers don't do the right thing.

feilee
03-03-2010, 01:22 AM
i got problem when compile opengl project in codeblock.
every time i compile,the glut.h will come out and say there is 3 error in my code.
but i have try the code in other computer and can be compiled.Is it the problem of my laptop or the glut.h library i download has problem.please reply me.thanks.