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 3 of 3

Thread: Dumb texturing question

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2000
    Posts
    7

    Dumb texturing question

    I'm sure you guys have seen this enough times, but I'm having constant probs getting more than one texture on the go at one time in a pixel shader.

    Here's the gist of my code:
    <make texture map>
    glGenTextures(1, &texture1)
    glBindTexture(GL_TEX_2D, .... data)
    glTexParam(...)

    <make texture map>
    glGenTextures(1, &texture2)
    glBindTexture(GL_TEX_2D, .... data)
    glTexParam(...)

    glUseProgramObjectARB(program)

    glActiveTexture(GL_TEXTURE0)
    glBindTexture(GL_TEXTURE_2D, texture1);
    glUniform1iARB(glGetUniformLocationARB(program, "tex1"))

    glActiveTexture(GL_TEXTURE1)
    glBindTexture(GL_TEXTURE_2D, texture2);
    glUniform1iARB(glGetUniformLocationARB(program, "tex2"))

    I then draw my textured quad.

    The glGetUniformLocationARB calls return 0 and 1 respectively.

    The problem seems to be, no matter what I try the texture that the pixel shader uses is the one that has the first glBindTexture call. So it's not like it's having problems making the texture etc, as I can check by reversing the glBindT calls.

    If you need to know, here's my dead basic shader code:
    "uniform sampler2D tex1;"
    "uniform sampler2D tex2;"
    "void main(void)"
    "{"
    " vec2 texCoord = gl_TexCoord[0].xy;"
    " vec4 c1 = texture2D(frame, texCoord);"
    " vec4 c2 = texture2D(prevframe, texCoord);"
    " gl_FragColor = vec4(c2.x);" //changing to c1 will give the same texture as c2
    "}"
    }

    I know that the shader's being run as the image I get on the screen is greyscale (as I'm assigning the red channel of the textureto all the channels of the fragment)

    Please can someone suggest something dumb that I'm doing? This is killing me!

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

    Re: Dumb texturing question

    glUniform1iARB(glGetUniformLocationARB(program, "tex1"))
    ...
    glUniform1iARB(glGetUniformLocationARB(program, "tex2"))
    You don't show what you are passing as the last parameter to glUniform1iARB. Make sure you are specifying the texture unit here, not a texture ID.
    "uniform sampler2D tex1;"
    "uniform sampler2D tex2;"
    ...
    " vec4 c1 = texture2D(frame, texCoord);"
    " vec4 c2 = texture2D(prevframe, texCoord);"
    This shader shouldn't compile, the "frame" and "prevFrame" samplers haven't been declared, only the "tex1" and "tex2" samplers.

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2000
    Posts
    7

    Re: Dumb texturing question

    " vec4 c1 = texture2D(frame, texCoord);"
    " vec4 c2 = texture2D(prevframe, texCoord);"

    soz, that should have been tex1 and tex2, not frame/prevframe - I just forgot to change it when pasting in the example!

    And the calls to glUniform1
    --------------------
    Hold on!
    Sorry, it's my mistake cos I made a typo! The first call I made was glUniform1iARB, and the second was glUniform1fARB! So really I was trying to set the texture ID to a float rather than int!

    So I changed the f to an i and it worked first time!

    Thanks for the help anyway

Posting Permissions

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