Re: [GtkGLExt] capturing an opengl image, or painting OpenGL into a pixbuf?



Hi Thomas

Thanks a lot. Using glReadPixels() i managed to
create snap shots of OpenGL Scenes:

void IQScene::save_image() {
    // allocate buffer
    unsigned char *pImage = new unsigned char[get_width()*get_height()*3];

    // get the pixels
    glReadPixels(0, 0,  get_width(), get_height(), GL_RGB,
GL_UNSIGNED_BYTE, pImage);

    // create a pixbuf from the pixel data
    Glib::RefPtr< Gdk::Pixbuf > pixbuf;
    pixbuf = Gdk::Pixbuf::create_from_data(pImage,
Gdk::COLORSPACE_RGB, false, 8,  get_width(), get_height(),
3*get_width());

    // save the image
    pixbuf->save( "image.png", "png" );

    // free the buffer
   delete[] pImage;
}

Thanks!
  Jody

On Tue, May 22, 2012 at 6:58 PM, Thomas Zimmermann
<tdz users sourceforge net> wrote:
> Hi Jody,
>
> You're probably creating a Pixmap from the drawing area's X Window, not
> from its GL buffer. Have a look at glReadPixels [1]; it'll copy the
> frame buffer to main memory, so you can save it to a file.
>
> Best regards,
> Thomas
>
> [1] http://www.opengl.org/sdk/docs/man/xhtml/glReadPixels.xml
>
> Am Dienstag, den 22.05.2012, 16:18 +0200 schrieb jody:
>> Hi
>> I am trying to find a way to capture and save to file the current
>> contents of a Gtk::GL::DrawingArea.
>> Googling for this i found a method by Samuel Pelaez:
>>
>> (IQScene is a Gtk::GL::DrawingArea)
>> void IQScene::save_image() {
>>
>>     // First, get the Config
>>     Glib::RefPtr< Gdk::GL::Config > glconfig;
>>     glconfig = get_gl_config();
>>
>>     // Second, create a Gdk::Pixmap
>>     Glib::RefPtr< Gdk::Pixmap > pixmap;
>>     pixmap = Gdk::Pixmap::create(get_window(),
>>                                  get_width(), get_height(),
>>                                  glconfig->get_depth() );
>>
>>     // Create a Gdk::Drawable from pixmap
>>     Glib::RefPtr< Gdk::Drawable > drawable( pixmap );
>>
>>     // Now create the Gdk::Pixbuf
>>     Glib::RefPtr< Gdk::Pixbuf > pixbuf;
>>     pixbuf = Gdk::Pixbuf::create( drawable,0,0,get_width(),get_height() );
>>
>>     // And finally save the image
>>     pixbuf->save( "image.jpg", "jpeg" );
>> }
>>
>> When i use this method, an image with the dimensions of my IQScene is created.
>> However the ontents of the image is different, everytime the method is called.
>> It usually consists of little fragments from menu bars, other widgets
>> of my application, or the terminal window.
>>
>> Does anybody see where the problem could be?
>>
>> Or is there maybe a possibility to draw OpenGL directly into a pixbuf?
>>
>> Thank You
>>   Jody
>> _______________________________________________
>> gtkglext-list mailing list
>> gtkglext-list gnome org
>> http://mail.gnome.org/mailman/listinfo/gtkglext-list
>
> --
> GnuPG:          http://tdz.users.sourceforge.net/tdz.asc
> Fingerprint:    16FF F599 82F8 E5AA 18C6 5220 D9DA D7D4 4EF1 DF08
>
> jsapigen - A free glue-code generator for Mozilla SpiderMonkey. See
> http://jsapigen.sourceforge.net for more information.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]