Black screenshots under vista

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;
}

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

I agree about using the back buffer. If you want to try glFlush, you should call it before glReadPixels.

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).

will try gl_back thanks!

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.

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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.