views:

91

answers:

3

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)
A: 

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);
Bahbar
Unfortunately, using GL_LINEAR or any mipmapping means that the mask is going to be blurred. I really need each texel of the mask to match to a single pixel on the screen. Like this:http://img101.imageshack.us/img101/6499/30831346.pngThe left image shows the mask across the whole screen, and the outline of the quad I'm trying to draw. The right image shows how the screen should look after drawing a white quad (which has been blended with the mask).
bparker
A: 

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...

Calvin1602
See update #1 in the post, not using shaders. Does my example match how you think it should work?
bparker
Ok, sorry, but this doesn't change anything. It you agree to pre-process each vertex each frame on the CPU, this is equivalent to executing the vertex shader I gave you. So the gl_Position = ... will be executed bu the fixed functionality pipeline anyway, you just have to update the UV coordinates buffer.
Calvin1602
@bparker : see other answer
Calvin1602
A: 

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)

Calvin1602