5

我有一个 OpenGL 窗口和一个 wxWidget 对话框。我想将 OpenGL 镜像到对话框。所以我打算做的是:

  1. 捕获opengl的屏幕截图
  2. 将它显示在 wxwidgets 对话框中。

任何想法?

更新:这就是我目前使用 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;
4

1 回答 1

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);

您现在可以使用图像进行显示,保存为 jpg png bmp 任何您喜欢的格式。对于仅在对话框中显示,您不需要将其保存到硬盘,但当然可以。然后在堆上创建图像。 http://docs.wxwidgets.org/stable/wx_wximage.html#wximagector

希望能帮助到你

于 2011-08-06T21:53:15.593 回答