5

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 there'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;
huy
  • 4,782
  • 6
  • 36
  • 42
  • 1
    How are you calling glReadPixels? You could use the data returned to create a wxImage and take it from there. – Bart Aug 04 '11 at 14:18
  • @Bart: I have updated the post to include the code. I'd appreciate if you could show me how to create a wxImage from the data returned. – huy Aug 05 '11 at 04:29

1 Answers1

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

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