Frament shader only fetches first texture element

Hi I have this weird problem:

I have a texure, it is 512x512. I draw a quad in a viewport of 512x512 like this:

    glBegin(GL_QUADS);
    {
      glTexCoord2f(0.0f, 0.0f); glVertex3f(-1, -1, -0.5f);
      glTexCoord2f(1.0f, 0.0f); glVertex3f( 1, -1, -0.5f);
      glTexCoord2f(1.0f, 1.0f); glVertex3f( 1,  1, -0.5f);
      glTexCoord2f(0.0f, 1.0f); glVertex3f(-1,  1, -0.5f);
    }
    glEnd();

my fragment shader:

uniform sampler2D texUnit;

void main()
{	
    vec2 texCoord = gl_TexCoord[0].st
    vec4 c  = texture2D(texUnit, texCoord);
    gl_FragColor = c;
} 

But the result is a quad with the color of only the first texture element at (0,0)!

Is there something wrong with my texture coordinates? Or did I miss something else?

Make sure you have this line in your vertex shader since gl_TexCoord[] does not contain any data if not set.

gl_TexCoord[0].st=gl_MultiTexCoord0.xy;

Originally posted by zeoverlord:
[b] Make sure you have this line in your vertex shader since gl_TexCoord does not contain any data if not set.

gl_TexCoord[0].st=gl_MultiTexCoord0.xy; [/b]
WORKS :slight_smile:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.