1
votes

I have a texture being drawn to a quad. The texture is the repeating pattern in the top-left corner of this screenshot: http://img828.imageshack.us/img828/3305/blahpv.png The opengl texture is only 3px by 9px and the texture coordinates I'm passing are very large numbers and it loops over the 3x9 texture by using GL_REPEAT. Any explanation for the weird interference pattern seen in the screenshot? The texture looks fine (repeating perfectly) when the quad is exactly perpendicular to the camera... the screenshot is with the quad rotated by a couple degrees. The anomalies seem to change as the quad changes its distance to the camera or when the rotation changes, so I think it has something to do with texture sampling and floating point roundoff, but I'm not sure how to fix it.

Update #1:

I'm not using shaders but this is how I'm currently doing it in python for each vertex:

(x0, y0, z0) = gluProject(vert[0].x, vert[0].y, 0.0)
x0 /= maskTextureWidth # 3.0
y0 /= maskTextureHeight # 9.0
glMultiTexCoord2f(GL_TEXTURE1_ARB, x0, y0)
glVertex2f(vert[0].x, vert[0].y)
3

3 Answers

0
votes

Well, not knowing the rotation you applied, we can only assume this is some sort of Moire pattern barely forming (where the interfering grids are your texture and the rasterization grid).

Why do you call this anomalies (or more to the point, what do you want as a result) ?

If all you want is something that just looks better, I'd suggest turning on trilinear filtering on your texture.

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
0
votes

Ok, so what you what is to rotate the quad, but not the texture, right ?

You can do this easily in your shaders (some parts are missing, like the sampler declaration)

Vertex shader :

 out vec2 UV;
 main(){
     gl_Position = MVP * Position;
     UV = gl_Position.xy / gl_Position.w;
 }

Fragment shader :

in vec2 UV;
main(){
    outColor = texture(sampler, UV);
}

What's more, you don't even have to provide texture coordinates : they are computed at run-time.

Another possibility, less invasive if you don't have shaders, is to re-compute your UVs so the same way as in the vertex shader.

Yet another possibility is glBitmap, but this is some very old piece of API...

0
votes

Answer #2 :

use glTexGen

http://www.dei.isep.ipp.pt/~matos/cg/docs/manual/glTexGen.3G.html

with arguments (GL_S, GL_T), GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR (I think; playaround with the value if it's not correct)