Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load image BACK from OpenGL?

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 the save them on hard disk.

There is 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() );
like image 231
Marco Avatar asked Feb 23 '23 14:02

Marco


2 Answers

Render textured quad to the framebuffer and then glReadPixels().

like image 147
genpfault Avatar answered Feb 25 '23 02:02

genpfault


As long as you don't use OpenGL ES, but real desktop OpenGL, you can just use glGetTexImage.

like image 37
Christian Rau Avatar answered Feb 25 '23 04:02

Christian Rau