Hi,
I am trying to copy the contents of the backbuffer into a texture to reuse it later. However, all my attempts failed, because I have not enough know-how of how to capture textures from the backbuffer.
Could some please fill-in/correct the code below? I need help with steps 4 and 6.
#define CX 144
#define CY 144
GLuint img;
// Step 1: create window
glutInitWindowSize (CX, CY);
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow ("glut");
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
// Step 2: clear the scene
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Step 3: draw a red square
glColor3f(1, 0, 0);
glMatrixMode (GL_MODELVIEW);
glRectf (-0.2f, -0.2f, 0.2f, 0.2f);
// Step 4: save backbuffer contents into texture (save the whole visible area)
glGenTextures(1,&img);
glBindTexture(GL_TEXTURE_2D,img);
// And now? Use glCopyTexImage2D? Use glCopyTexSubImage2D? How does it work?
// Step 5: clear the scene again
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Step 6: draw a quad with the size of the whole screen using the captured texture
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,img);
glBegin(GL_QUADS);
glTexCoord2f(?,?); glVertex2i(-1,1);
glTexCoord2f(?,?); glVertex2i(1,1);
glTexCoord2f(?,?); glVertex2i(1,-1);
glTexCoord2f(?,?); glVertex2i(-1,-1);
glEnd();
glDisable(GL_TEXTURE_2D);