gpt4 book ai didi

c++ - 如何绘制从 glReadPixels 捕获的屏幕截图到 wxWidgets 对话框/面板

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:49:30 25 4
gpt4 key购买 nike

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

最佳答案

  // 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

希望对你有帮助

关于c++ - 如何绘制从 glReadPixels 捕获的屏幕截图到 wxWidgets 对话框/面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6938596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com