0

I'm trying to read from a fragment shader a texture1d:

uniform sampler1D world;

...

texelFetch(world, 0, 0);

I upload w, where w[0]=123.0f w[1]=123.0f...:

glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &pt->world);
glBindTexture(GL_TEXTURE_1D, pt->world);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA32F, 2, 0, GL_RGBA, GL_FLOAT, &w);

Binding:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_1D, pt->world);
glUniform1i(glbPTworld, 0);

However, the fragment shader read vec4(0,0,0,1) instead of vec4(123,123,123,123) when I use a width in glTexImage1D different from one. Also, if I use:

glGetTexImage(GL_TEXTURE_1D, 0, GL_RGBA, GL_FLOAT, x);

To get the texture back I see the expected values.

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
dv1729
  • 987
  • 1
  • 8
  • 25

1 Answers1

1

I see a couple of red flags with your code, though I'm not sure whether they're related to the problem or not. First, your telling OpenGL that your texture is only 2 pixels wide. Is that correct?

Second, you're passing GL_TEXTURE_2D to glTexParameteri(), but you're using the GL_TEXTURE_1D texture target. That seems wrong.

user1118321
  • 25,567
  • 4
  • 55
  • 86
  • Thanks! It was the GL_TEXTURE_2D in glTexParameteri, I didn't see it. However, it's a little bit odd that this error cause all this trouble, sometimes I don't understand some openGL decisions, like asking for the texture type/dimension in a glTexParameter when it already knows. – dv1729 Mar 07 '14 at 11:15