我正在尝试将 opengl 中的屏幕区域保存到位图中。我尝试过使用 FreeImage 和 SDL_Image,它们都要求我交换红色和蓝色通道。当然,这让我怀疑 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 应该这样做吗?我正确地调用它吗?这里有什么问题?