Jump to content
  • Advertisement
Sign in to follow this  
Tyrahell

OpenGL Offscreen texture rendering to bitmap

This topic is 3033 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Regards, I'm trying to create an offscreen rendering on my OpenGL app. To get an offscreen rendering, i store my render into a texture and i wish to export this texture to an image. After one day reading tutorial about FBO, DIB, Offscreen rendering & Render to texture, im stuck at the "texture to image" step. Please, can you help me to save my offscreen rendered texture to a bitmap ? /////////////////////////////////////////////////////////////////////////////// // Define static variable static unsigned char texture[3 * SIZE * SIZE]; static unsigned int texture_id; static int window_width = 512; static int window_height = 512; // OpenGL settings glEnable(GL_DEPTH_TEST); // Texture setting glEnable(GL_TEXTURE_2D); glGenTextures(1, &texture_id); glBindTexture(GL_TEXTURE_2D, texture_id); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, SIZE, SIZE, 0, GL_RGB, GL_UNSIGNED_BYTE, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glLoadIdentity(); glTranslatef(0, 0, -10); glRotatef(30, 1, 0, 0); /* Define a view-port adapted to the texture */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(20, 1, 5, 15); glViewport(0, 0, SIZE, SIZE); glMatrixMode(GL_MODELVIEW); /* Render to buffer */ glClearColor(1, 1, 1, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //DrawCube glBegin(GL_LINE_LOOP); glTexCoord2i(0, 0); glVertex3f(-1, -1, -1); glTexCoord2i(0, 1); glVertex3f(-1, -1, 1); glTexCoord2i(1, 1); glVertex3f(-1, 1, 1); glTexCoord2i(1, 0); glVertex3f(-1, 1, -1); glTexCoord2i(0, 0); glVertex3f( 1, -1, -1); glTexCoord2i(0, 1); glVertex3f( 1, -1, 1); glTexCoord2i(1, 1); glVertex3f( 1, 1, 1); glTexCoord2i(1, 0); glVertex3f( 1, 1, -1); glTexCoord2i(0, 0); glVertex3f(-1, -1, -1); glTexCoord2i(0, 1); glVertex3f(-1, -1, 1); glTexCoord2i(1, 1); glVertex3f( 1, -1, 1); glTexCoord2i(1, 0); glVertex3f( 1, -1, -1); glTexCoord2i(0, 0); glVertex3f(-1, 1, -1); glTexCoord2i(0, 1); glVertex3f(-1, 1, 1); glTexCoord2i(1, 1); glVertex3f( 1, 1, 1); glTexCoord2i(1, 0); glVertex3f( 1, 1, -1); glTexCoord2i(0, 0); glVertex3f(-1, -1, -1); glTexCoord2i(0, 1); glVertex3f(-1, 1, -1); glTexCoord2i(1, 1); glVertex3f( 1, 1, -1); glTexCoord2i(1, 0); glVertex3f( 1, -1, -1); glTexCoord2i(0, 0); glVertex3f(-1, -1, 1); glTexCoord2i(0, 1); glVertex3f(-1, 1, 1); glTexCoord2i(1, 1); glVertex3f( 1, 1, 1); glTexCoord2i(1, 0); glVertex3f( 1, -1, 1); glEnd(); //Ending texture glFlush(); /* Copy buffer to texture */ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 5, 5, 0, 0, SIZE - 10, SIZE - 10); //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// This code create texture like this (render on the different side of my cube) : http://j.imagehost.org/0367/texture.jpg How can i export this texture to a bitmap ? ++Tyra =)

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!