glGetTexImage returning wierd results

Started by
3 comments, last by soconne 18 years, 8 months ago
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 ?
Author Freeworld3Dhttp://www.freeworld3d.org
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?
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
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

Author Freeworld3Dhttp://www.freeworld3d.org
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);
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.
Author Freeworld3Dhttp://www.freeworld3d.org

This topic is closed to new replies.

Advertisement