Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: High Level Frag Shader Help

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2005
    Location
    Glendale, CA
    Posts
    18

    High Level Frag Shader Help

    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:
    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:
    Code :
    	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):
    Code :
    	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

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Jan 2001
    Location
    NVIDIA, Austin, TX
    Posts
    555

    Re: High Level Frag Shader Help

    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.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2005
    Location
    Glendale, CA
    Posts
    18

    Re: High Level Frag Shader Help

    Thank you so much! That was it. I just changed the types to 2DRects and it works perfectly now.

    Walker

  4. #4
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,453

    Re: High Level Frag Shader Help

    The official and also working uniform and function names are samplerRect and textureRect from the ARB_texture_rectangle extension.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Jan 2001
    Location
    NVIDIA, Austin, TX
    Posts
    555

    Re: High Level Frag Shader Help

    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 ).

    The correct names are indeed sampler2DRect and texture2DRect.

  6. #6
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,453

    Re: High Level Frag Shader Help

    Argh! I missed the spec update. Thanks, now the reserved and official names finally agree.

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2006
    Posts
    6

    Re: High Level Frag Shader Help

    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:
    Code :
    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.

  8. #8
    Intern Contributor
    Join Date
    Mar 2004
    Posts
    52

    Re: High Level Frag Shader Help

    gluonconcerto - What hardware are you using?

  9. #9
    Intern Contributor
    Join Date
    Jun 2004
    Location
    Shanghai, China
    Posts
    79

    Re: High Level Frag Shader Help

    Maybe something wrong about your hardware and drivers

    I am using 6200A,works perfectly now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •