Hi! I first create a lookup-table for a transfer function and then try to upload it as a 1D texture as follows:
for (unsigned i = 0; i < 1024; i++)
tfm0[i] = qfeGetProbability(tf0, (float)i/1023.f);
glActiveTexture(GL_TEXTURE17);
if (glIsTexture(tfmTex0)
glDeleteTextures(1, &tfmTex0);
glGenTextures(1, &tfmTex0);
glBindTexture(GL_TEXTURE_1D, tfmTex0);
glTexImage1D(GL_TEXTURE_1D, 0, GL_R16F, 1024, 0, GL_RED, GL_FLOAT, tfm0);
Right before the rendering call I make sure all the textures I need are bound to the right texture units:
glActiveTexture(GL_TEXTURE17);
glBindTexture(GL_TEXTURE_1D, tfmTex0);
Then, I set my uniform variable for the 1D texture:
glUniform1f(glGetUniformLocation(shaderProgram, "tf0"), 17);
And this is how the 1D texture is defined in the fragment shader, where sampleNorm is a value between 0 and 1:
uniform sampler1D tf0;
vec4 tfValue = texture1D(tf0, sampleNorm);
Somehow, all of the tfValues end up being (0, 0, 0, 1), which I suspect is a default fallback value.
To be sure that I uploaded the values to the graphics card correctly, I also have this check right before the draw call:
float values[1024];
glActiveTexture(GL_TEXTURE17);
glGetTexImage(GL_TEXTURE_1D, 0, GL_RED, GL_FLOAT, values);
It retrieves the values in the texture I uploaded back to "normal" memory, and they show up to be exactly the values I expect them to be.
Does anyone have an idea of where things might be going wrong? What would cause the sampler in the fragment shader to return (0, 0, 0, 1), when it should be returning my values in the R-channel?
Thank you in advance,
Arjan