I'm attempting to capture the back buffer on a texture, and then in an attempt to make sure its working, simply redraw the texture on the screen. I've copied the appropriate sections of code line for line from a tutorial example. The example compiles and works, mine doesn't. I can't for the life of me understand why.
Here the is initialization code that creates the empty texture:
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f); // set clear color to black
unsigned int *empty = new unsigned int[((glutGet(GLUT_WINDOW_WIDTH) * glutGet(GLUT_WINDOW_HEIGHT))* 4 * sizeof(unsigned int))];
glEnable( GL_TEXTURE_2D );
glGenTextures( 1, &texture_buffer );
glBindTexture( GL_TEXTURE_2D, texture_buffer);
glTexImage2D( GL_TEXTURE_2D, 0, 4, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT), 0, GL_RGBA, GL_UNSIGNED_BYTE, empty);
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);
glBindTexture(GL_TEXTURE_2D, 0);
glBindTexture( GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
delete [] empty;
Here is the code that draws the scene, grabs it off the back buffer, then for testing, attempts to draw the texture to the screen:
glClear( GL_COLOR_BUFFER_BIT );
state->draw();
glFlush();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture_buffer);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT), 0);
glClear( GL_COLOR_BUFFER_BIT );
glBegin( GL_QUADS );
glTexCoord2f(0,1); glVertex2f(WORLD_LEFT, WORLD_TOP);
glTexCoord2f(1,1); glVertex2f(WORLD_RIGHT, WORLD_TOP);
glTexCoord2f(1,0); glVertex2f(WORLD_RIGHT, WORLD_BOTTOM);
glTexCoord2f(0,0); glVertex2f(WORLD_LEFT, WORLD_BOTTOM);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
glutSwapBuffers();
Anything seem out of place?