我試圖將一個屏幕區域從opengl保存到位圖中。我試過使用FreeImage和SDL_Image,並且他們都要求我交換紅色和藍色通道。當然,這使我懷疑glReadPixels是這裏的問題... 我有這樣的示例代碼:glReadPixels藍色和紅色交換
bool CaptureScreenRegionToFile (uint32_t In_X, uint32_t In_Y, uint32_t In_Width, uint32_t In_Height, std::string In_Filename)
{
GLubyte* ImageData = (GLubyte*) malloc (In_Width * In_Height * 3);
glPixelStorei (GL_PACK_ALIGNMENT, 1);
glReadPixels (In_X, In_Y, In_Width, In_Height, GL_RGB, GL_UNSIGNED_BYTE, ImageData);
if (CheckError() == false)
{
free (ImageData);
return false;
}
SDL_Surface *Surface;
// JTP TODO Known bug here. Red and blue are swapped, for some reason...
Surface = SDL_CreateRGBSurfaceFrom (ImageData, In_Width, In_Height, 3 * 8, In_Width * 3, 0x00FF0000, 0x0000FF00, 0x000000FF, 0);
SDL_SaveBMP (Surface, In_Filename.c_str());
SDL_FreeSurface (Surface);
free (ImageData);
return true;
}
除非我調用CreateRGBSurfaceFrom後手動交換紅色和藍色通道,它的顏色會在BMP上交換。 glReadPixels應該這樣做嗎?我是否正確地調用它? 這裏有什麼問題?
[可能相關的問題](http://stackoverflow.com/questions/5123387/loading-a-bmp-into-an-opengl-textures-switches-the-red-and-blue-colors-c-win )。 – DarkDust