PDA

View Full Version : High Level Frag Shader Help



Steven Walker
12-09-2005, 11:12 AM
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;\n"
"void main(void) {\n"
" gl_FragColor = texture2D(tex, gl_TexCoord[0].st);\n"
"}\n";And here is the low level version (which works fine):

static const GLcharARB *testShaderLow =
"!!ARBfp1.0\n"
"TEX result.color, fragment.texcoord[0], texture[0], RECT;\nEND";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

jra101
12-09-2005, 11:32 AM
Your GLSL shader uses 2D textures, your ARB_fragment_program shader uses RECT textures.

Most likely your texture coordinates are in the [0..width]x[0..height] range (required for RECTANGLE textures) so the ARB_fragment_program works correctly.

Update your GLSL shader to use sampler2DRect and texture2DRect and it should work fine.

Steven Walker
12-09-2005, 11:46 AM
Thank you so much! That was it. I just changed the types to 2DRects and it works perfectly now.

Walker

Relic
12-11-2005, 11:09 PM
The official and also working uniform and function names are samplerRect and textureRect from the ARB_texture_rectangle extension.

jra101
12-12-2005, 08:01 AM
Originally posted by Relic:
The official and also working uniform and function names are samplerRect and textureRect from the ARB_texture_rectangle extension.That was actually a bug in the spec (see the revision history of the latest spec: http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_rectangle.txt (http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_rectangle.txt).) ).

The correct names are indeed sampler2DRect and texture2DRect.

Relic
12-12-2005, 08:31 AM
Argh! I missed the spec update. Thanks, now the reserved and official names finally agree.

gluonconcerto
01-07-2006, 04:26 PM
Hi, I'm having the exact same problem as he is with GLSL fragment shaders, but when I tried to change sampler2D to sampler2dRect and texture2D to texture2DRect, I got the following shader compiler errors:

ERROR: 0:1: 'sampler2DRect' : Reserved word.
ERROR: 0:1: 'sampler2DRect' : syntax error parse error What should that tell me?
3D Lab's ShaderGen works fine on my card, as does the standard brick example from the Orange Book, so my guess is there might be something else I'm not doing. I tried to copy his code above as exactly as possible.

kingjosh
01-09-2006, 10:49 AM
gluonconcerto - What hardware are you using?

Jedimaster
01-10-2006, 09:42 PM
Maybe something wrong about your hardware and drivers

I am using 6200A,works perfectly now