GL_CLAMP - what I'm doing wrong?

Started by
3 comments, last by Tommato 12 years, 10 months ago
[font=Helvetica][size=2]Hi All[/font][font=Helvetica][size=2]
[/font][font=Helvetica][size=2]
[/font][font=Helvetica][size=2]I'm using:[/font][font=Helvetica][size=2]
[/font][font=Helvetica][size=2]
[/font][font=Helvetica][size=2]glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);[/font][font=Helvetica][size=2]
[/font][font=Helvetica][size=2]glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);[/font][font=Helvetica][size=2]
[/font][font=Helvetica][size=2]
[/font][font=Helvetica][size=2]If I set alpha = 0 for "edge" pixels - all is as expected (left [/font][font=Helvetica][size=2]picture - no texture outside region). However, with alpha = 255 [/font][font=Helvetica][size=2](middle picture) OpenGL still uses/applies some alpha. I can't [/font][font=Helvetica][size=2]figure out where this alpha comes from? No probs with software [/font][font=Helvetica][size=2]render (right picture)[/font]
[font=Helvetica][size=2]
[/font]
[font=Helvetica][size=2][/font][font=Helvetica][size=2][attachment=2531:OpenGL.png]
[/font][font=Helvetica][size=2]
[/font][font=Helvetica][size=2]What I'm doing wrong?[/font][font=Helvetica][size=2]
[/font][font=Helvetica][size=2]
[/font][font=Helvetica][size=2]Thanks[/font]
[font=Helvetica][size=2][/font][font=Helvetica][size=2]
[/font][font=Helvetica][size=2]Tom[/font]
Advertisement
This could be due to the mip-map level being used. The one pixel alpha border becomes interpolated at lower levels giving an alpha value between the 2 pixels closest to the edge.

(Actually I think this would cause the opposite of your case?)

[font="Helvetica"] [/font][font="Helvetica"]If I set alpha = 0 for "edge" pixels[/font]

Define "edge pixels". Does your texture have an actual OpenGL texture border, do you set the constant border colour ?

If the answer to these questions is no or I don't know, then GL_CLAMP isn't doing what you think it is doing. Use GL_CLAMP_TO_EDGE in this case.

Oh, and GL_CLAMP is deprecated anyway.
http://www.opengl.org/wiki/Common_Mistakes#Texture_edge_color_problem
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Define "edge pixels". Does your texture have an actual OpenGL texture border, do you set the constant border colour ?

If the answer to these questions is no or I don't know, then GL_CLAMP isn't doing what you think it is doing. Use GL_CLAMP_TO_EDGE in this case.

Oh, and GL_CLAMP is deprecated anyway.
Thank you, GL_CLAMP_TO_EDGE does solve ny prob!
If I need no texture outside, then I set "edge" pixels of image (alpha = 0) before call glTexImage2D (with "border" param = 0). Maybe there is a better way to do this?

Thanks
Tom


This topic is closed to new replies.

Advertisement