I'm trying to pass an array of ints into the fragment shader by using a 1D texture. Although the code compiles and runs, when I look at the texture values in the shader, they are all zero!
This is the C++ code I have after following a number of tutorials:
GLuint texture;
glGenTextures(1, &texture);
glActiveTexture(GL_TEXTURE0 + 5); // use the 5th since first 4 may be taken
glBindTexture (GL_TEXTURE_1D, texture);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage1D(GL_TEXTURE_1D, 0, GL_RED_INTEGER, myVec.size(), 0,
GL_RED_INTEGER, GL_INT, &myVec[0]);
GLint textureLoc = glGetUniformLocation( program, "myTexture" );
glUniform1i(textureLoc, 5);
And this how I try and access the texture in the shader:
uniform sampler1D myTexture;
int dat = int(texture1D(myTexture, 0.0).r); // 0.0 is just an example
if (dat == 0) { // always true!
I'm sure this is some trivial error on my part, but I just can't figure it out. I'm unfortunately constrained to using GLSL 1.20, so this syntax may seem outdated to some.
So why are the texture values in the shader always zero?
EDIT:
If I replace the int's with floats, I still have a problem:
std::vector <float> temp;
// fill temp...
glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage1D(GL_TEXTURE_1D, 0, GL_R32F, temp.size(), 0, GL_R32F, GL_FLOAT, &temp[0]);
// ...
glUniform1f(textureLoc, 5);
This time, just reading from the sampler
seems to mess up the other textures..