Sign in to follow this  
JonW

OpenGL Junk pixels at edges of textures

Recommended Posts

Hi, In my ortho-perspective OpenGL app I am getting strange pixels at the top and right edges of all of my textures on the screen. These pixels appear in the very last row and column, respectively. It only happens when I apply the full texture, ie letting u or v go all the way to 1.0. I thought these were somehow coming from my source data but that doesn't appear to be the case. I tried creating and displaying a texture that had 0 alpha for the edge pixels, and those pixels still appeared. Here is my texture creation code (I use the same function for all textures): glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_nWidth, m_nHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_pData); And my OpenGL states: glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glShadeModel(GL_SMOOTH); glClearDepth(1.0f); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); I can post other sections if needed. Any ideas? Thanks, Jon

Share this post


Link to post
Share on other sites
Try:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

Share this post


Link to post
Share on other sites
Thanks, that did the trick.

But why was the texture repeat the problem, if I only used texture coordinates from 0.0 to 1.0?

Share this post


Link to post
Share on other sites
This bit of code sticks out to me straight away:

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);


Whatever it does, i've never used it in any OpenGL app and my textures always looked fine =)

Other than that, everything else looks ok to me though, sorry if thats no help at all.

edit: fixed... erm, nevermind then, disregard everything I posted =p

Share this post


Link to post
Share on other sites
I found the answer to my question in my last post (emphasis mine):

Quote:

A useful (and sometimes misunderstood) feature of OpenGL is the texture border. OpenGL supports either a constant texture border color or a border that is a portion of the edge of the texture image. The key to understanding texture borders is understanding how textures are sampled when the texture coordinate values are near the edges of the [0,1] range and the texture wrap mode is set to GL_CLAMP. For point sampled filters, the computation is quite simple: the border is never sampled. However, when the texture filter is linear and the texture coordinate reaches the extremes (0.0 or 1.0), the resulting texel value is a 50% mix of the border color and the outer texel of the texture image at that edge (25% and 75% at the corners).


I got this from http://www.ii.uni.wroc.pl/~anl/cgfiles/Sig99AdvOpenGLnotes/node64.html

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this