View Full Version : 1D Texture Coordinates

10-11-2007, 02:13 PM
I am having some problems accessing 1D texture coordinates in a fragment program. I am using a very simple program to test it...

Vertex Program calls...
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();

Fragment Programs calls...
vec3 finalColor = vec3(gl_TexCoord[0].s, 0.0, 0.0);
gl_FragColor = vec4(finalColor, 1.0);

If I use gl_TexCoord[0].s I get black, if I use gl_TexCoord[0].t I get red (ie 0 and 1). Am I doing something wrong?

p.s. my texture coordinates work fine in fixed pipeline.

10-11-2007, 04:24 PM
Two questions
1. what UV coordinates did you set
2. did you set any uv coordinates before that.

10-11-2007, 04:24 PM
I haven't used a 1D texture before, but I am pretty sure you need a sampler variable of some kind.

10-12-2007, 08:05 AM
Did you set the texture coordinates on your primitive correctly via glTexCoord1d(s); ?

10-12-2007, 09:13 AM
I don't see a sampler - you're just converting the texture coordinates to a color. You'll need to add a sampler uniform, and initialize it from your C code:

void main()
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();

uniform sampler1D my_sampler;

void main()
gl_FragColor = vec4(texture1D(my_sampler, gl_TexCoord[0].s).rgb, 1.0f);
}In your application, you'll have to pass the texture ID into the sampler uniform:

GLint sampler_location = glGetUniformLocation(program, "my_sampler");
glUniform1i(sampler_location, texture_id);