Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Trouble getting back buffer with glCopyTexImage2D


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 pondwater   Members   -  Reputation: 191

Like
0Likes
Like

Posted 18 January 2013 - 06:33 PM

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?

 



Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 8429

Like
0Likes
Like

Posted 18 January 2013 - 06:45 PM

Some general comment...

  1. You don't need to allocate an empty buffer to create an empty texture. You can just pass a null pointer to glTexImage to just allocate the texture memory.
  2. You should use glCopyTexSubImage to update an existing texture. glCopyTexImage creates an entirely new texture from scratch which is not what you want to do in this case.
  3. You don't need to enable texturing just to bind and create your texture. The texture enable state is only used for applying texturing when drawing, but not for managing the texture object.

... and a possible cause of your error.

  1. You should clear the depth buffer also. What you draw to the frame buffer is cleared after copying to the texture and before drawing the quad, but the depth buffer is not cleared and what remains in there from rendering the texture-image bay prevent the quad from being drawn.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS