I'm having problems getting a 1D texture to work in GLSL, though it might be the app code at fault because this is the first time I have used 1D textures. Take a look:
[main.cpp]
bool loadTextures ()
{
...
glBindTexture (GL_TEXTURE_1D, spect);
glTexImage1D (GL_TEXTURE_1D, 0, 3, spectData->sizeX, 0, GL_RGB, GL_UNSIGNED_BYTE, spectData);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP);
...
};
void shaders ()
{
spectLoc = glGetUniformLocation (p, "spect");
glUniform1i (spectLoc, spect);
};
[shader.fs]
uniform sampler1D spect;
uniform int time;
void main ()
{
float f = (sin ((float) time / 100) / 2.0) + 0.5;
vec4 color = texture1D (spect, f);
gl_FragColor = vec4 (color.r, color.g, color.b, (color.r + color.g + color.b) / 3.0);
}
I hope I have shown enough information. The aim is to make a flashing rainbow effect, but the fragment shader is failing on the above code (result: white polygons).
The texture file itself is a 256x1 24-bit bitmap. Now it does work correctly if I load the texture as 2D, using the following code (but I want to avoid loading it as 2D here):
[main.cpp]
bool loadTextures ()
{
...
glBindTexture (GL_TEXTURE_2D, spect);
glTexImage2D (GL_TEXTURE_2D, 0, 3, spectData->sizeX, spectData->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, spectData->data);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
...
};
void shaders ()
{
spectLoc = glGetUniformLocation (p, "spect");
glUniform1i (spectLoc, spect);
};
[shader.fs]
uniform sampler2D spect;
uniform int time;
void main ()
{
float f = (sin ((float) time / 100) / 2.0) + 0.5;
vec4 color = texture2D (spect, vec2 (f, 0.0));
gl_FragColor = vec4 (color.r, color.g, color.b, (color.r + color.g + color.b) / 3.0);
}