【问题标题】:How to draw screenshot captured from glReadPixels to wxWidgets dialog/panel如何将从 glReadPixels 捕获的屏幕截图绘制到 wxWidgets 对话框/面板
【发布时间】:2011-10-19 19:07:27
【问题描述】:

我有一个 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;

【问题讨论】:

  • 你如何调用 glReadPixels?您可以使用返回的数据创建一个 wxImage 并从那里获取它。
  • @Bart:我已经更新了帖子以包含代码。如果您能告诉我如何根据返回的数据创建 wxImage,我将不胜感激。

标签: c++ opengl wxwidgets glreadpixels


【解决方案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

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-31
    • 1970-01-01
    相关资源
    最近更新 更多