PDA

View Full Version : How to load image BACK from OpenGL?



Gerwazy
10-27-2011, 11:36 AM
Hi,

I have succeed in loading an image to OpenGl as a texture (I use Gdk::Pixbuf from GTKmm library), but I have no idea how to get modified image from OpenGl and load it to Gdk::Pixbuf...

I want to modify images in OpenGl and then save them on hard disk.


Some code:


Glib::RefPtr<Gdk::Pixbuf> pixmap = Gdk::Pixbuf::create_from_file("image.jpg");
GLuint texture[1];
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, pixmap->get_width(), pixmap->get_height(), 0, GL_RGB, GL_UNSIGNED_BYTE, pixmap->get_pixels() );

BionicBytes
10-27-2011, 02:11 PM
You can use glreadpixels to read back the contents of your framebuffer to memory.

Dan Bartlett
10-27-2011, 03:16 PM
Yeah, use glReadPixels to read from framebuffer, or if it's already in a texture object, then use glGetTexImage (http://www.opengl.org/sdk/docs/man/xhtml/glGetTexImage.xml) to retrieve texture data.