PDA

View Full Version : save opengl image by using freeimage library



ZXJ106
10-15-2014, 08:36 PM
Hi, I ran into a problem with saving opengl created window by using freeimage library, my code is as follow:

GLint viewPort[4];
glGetIntegerv(GL_VIEWPORT, viewPort);
GLubyte *pixels=new GLubyte[3*winWidth*winHeight];
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);

but what I got is just a black .bmp image, is there wrong with my code, could anyone help me plz?