PDA

View Full Version : Dumb texturing question



Simon Hall
12-01-2004, 08:42 AM
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!

jra101
12-01-2004, 09:28 AM
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.

Simon Hall
12-01-2004, 10:01 AM
" 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 :)