huy*_*huy 5 c++ opengl wxwidgets glreadpixels
我有一个OpenGL窗口和一个wxWidget对话框.我想将OpenGL镜像到对话框中.所以我打算做的是:
任何的想法?
更新:这是我目前使用glReadPixels的方式(我也暂时使用FreeImage保存到BMP文件,但如果有办法直接将它传递给wxImage,我希望删除文件保存)
// Make the BYTE array, factor of 3 because it's RBG.
BYTE* pixels = new BYTE[ 3 * width * height];
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
// Convert to FreeImage format & save to file
FIBITMAP* image = FreeImage_ConvertFromRawBits(pixels, width, height, 3 * width, 24, 0x0000FF, 0xFF0000, 0x00FF00, false);
FreeImage_Save(FIF_BMP, image, "C:/test.bmp", 0);
// Free memory
delete image;
delete pixels;
Run Code Online (Sandbox Code Playgroud)
小智 1
// Add Image Support for all types
wxInitAllImageHandlers();
BYTE* pixels = new BYTE[ 3 * width * height];
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
// width height pixels alpha
wxImage img(with, height, pixels, NULL); // I am not sure if NULL is permitted on the alpha channel, but you can test that yourself :).
// Second method:
wxImage img(width, heiht, true);
img.SetData(pixels);
Run Code Online (Sandbox Code Playgroud)
您现在可以使用图像进行显示,保存为 jpg png bmp 任何您喜欢的格式。对于仅在对话框中显示,您不需要将其保存到硬盘,但当然可以。然后只需在堆上创建图像即可。 http://docs.wxwidgets.org/stable/wx_wximage.html#wximagector
希望能帮助到你