Jump to content
  • Advertisement
Sign in to follow this  
soconne

glGetTexImage returning wierd results

This topic is 4830 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

I have the following code:
// grab image from the screen
GLuint texID;
glGenTextures(1, &texID);
glBindTexture(GL_TEXTURE_2D, texID);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, size, size, 0);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->m_buffer);

This works perfectly fine, it grabs the screen data and returns the data correctly. But if I replace the border variable in gLCopyTexImage2D with a "1" instead of a "0", the data returned by glGetTexImage is a solid color, sometimes light green, sometimes black. Its very strange. Any ideas ?

Share this post


Link to post
Share on other sites
Advertisement
From MSDN:

Quote:
The width of the texture image. Must be 2^n + 2 * border for some integer n.


Could this be a problem?

Share this post


Link to post
Share on other sites
Yeah that was the problem, thanks. But now that I made my texture 2n + 2*border, the thing I was trying to do no longer functions correctly.

I'm basically rendering terrain to the screen, but positioning the camera above the terrain, then copying the framebuffer to a texture. When using glCopyTexImage2D, if I set the "border" value to 0, then the edge of the copied framebuffer was using pixels NOT associated with the screen.

So how I do make it so that the texture does not do this? Here's a screenshot

Share this post


Link to post
Share on other sites
The texture is being filtered, because you're doing this:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);


Try this instead:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

Share this post


Link to post
Share on other sites
THanks for your help but I figured out what it was. I was resizing the viewport to have an extra row and column, so when I copied the backbuffer I got that blue color. It works now, I simply set the viewport to the correct size.

Share this post


Link to post
Share on other sites
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!