开发者

How to draw screenshot captured from glReadPixels to wxWidgets dialog/panel

I have an OpenGL window, and a wxWidget dialog. I want to mirror the OpenGL to the dialog. So what I intend to do is:

  1. Capture the screenshot of the opengl
  2. Display it onto the wxwidgets dialog.

Any idea?

Update: This is how I currently use glReadPixels (I also temporarily use FreeImage to save to BMP file, but I expect the file saving to be removed if ther开发者_JS百科e's a way to channel it directly to the 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);

You can now use the image for displaying, saving as jpg png bmp whatever you like. For just displaying in a dialog, you don't need to save it to the harddisc though but of course, you can. Just create the image on the heap then. http://docs.wxwidgets.org/stable/wx_wximage.html#wximagector

Hope it helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜