PDA

View Full Version : frament shader only fetches first texture element



Dylan
02-13-2007, 03:12 AM
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?

zeoverlord
02-13-2007, 04:33 AM
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;

Dylan
02-13-2007, 04:53 AM
Originally posted by zeoverlord:
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; WORKS :)