1D Texture Coordinates

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.

I haven’t used a 1D texture before, but I am pretty sure you need a sampler variable of some kind.

Two questions

  1. what UV coordinates did you set
  2. did you set any uv coordinates before that.

Did you set the texture coordinates on your primitive correctly via glTexCoord1d(s); ?

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:

VERTEX:
void main()
{
   gl_TexCoord[0] = gl_MultiTexCoord0;
   gl_Position = ftransform();
}

FRAGMENT:
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:

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

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