I’m having a problem with the most basic fragment shader using a texture. I’m just trying to get the fragment shader to pass through the texture (as a test), but it just renders black. I suspect that I am missing a step. I am not using a vertex shader.
There are 2 versions of the shader: one written in the high level language and one written in the low level language. I have tested each of them independently. The low level shader works perfectly and passes the texture through. The high level shader is returning black. I know the high level shader is being called because if I replace the texture2D call with a constant value vec4(1.0,0.5,1.0,1.0) it works fine. I also have been diligently checking for errors using glGetInfoLogARB, and there are no errors for either of the shaders.
I’m omitting all the setup code in the snippet below because it is quite lengthy, but I am quite certain that it is correct because it is properly calling the shader code. And the texture must be ok because it works with the low level shader fine.
Following is my main rendering code:
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureID);
GLint texArb = glGetUniformLocationARB(shaderProgram, "tex");
glUniform1iARB(texArb, 0);
glBegin(GL_QUADS);
{
glTexCoord2f( inRect->left, inRect->bottom );
glVertex2f( outRect->left, outRect->bottom );
glTexCoord2f( inRect->right, inRect->bottom );
glVertex2f( outRect->right, outRect->bottom );
glTexCoord2f( inRect->right, inRect->top );
glVertex2f( outRect->right, outRect->top );
glTexCoord2f( inRect->left, inRect->top );
glVertex2f( outRect->left, outRect->top );
}
glEnd();
Here is the high level shader:
static const GLcharARB *testShader =
"uniform sampler2D tex;
"
"void main(void) {
"
" gl_FragColor = texture2D(tex, gl_TexCoord[0].st);
"
"}
";
And here is the low level version (which works fine):
static const GLcharARB *testShaderLow =
"!!ARBfp1.0
"
"TEX result.color, fragment.texcoord[0], texture[0], RECT;
END";
Can anyone see what I’m missing? Why would the texture2D function be returning black?
Thanks for any help. It must be something basic that I’ve overlooked.
Steven Walker
steve@walkereffects.com