-3

Does anybody have experience with using the freeimage library to save the opengl buffer?

Here is my code:

void screenshot(const char *ptr){
    GLint viewPort[4]; 
    glGetIntegerv(GL_VIEWPORT, viewPort);  
    GLubyte *pixels=new GLubyte[3*winWidth*winHeight];
    glPixelStorei(GL_PACK_ALIGNMENT, 1);
    glReadPixels(0, 0, viewPort[2],viewPort[3], GL_RGB, GL_UNSIGNED_BYTE, pixels);  
    FIBITMAP* image = FreeImage_ConvertFromRawBits(pixels,viewPort[2], viewPort[3],3*viewPort[2] 
    ,24,FI_RGBA_RED, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK,false);
    FreeImage_Save(FIF_BMP, image, ptr, 0);
    FreeImage_Unload(image);
    delete pixels;
}

Why do I always get a black image?

genpfault
  • 51,148
  • 11
  • 85
  • 139

1 Answers1

0

You don't set from which buffer to read from. If you want to take the screenshot after the buffer swap, then you must read from the front buffer. If you want to take the screenshot before the buffer swap, read from the back buffer.

datenwolf
  • 159,371
  • 13
  • 185
  • 298