Original Post
Hey Everyone, I am pretty new to openGL and GLSL, and not much of a game programmer. I need to use subract one textures from another using the pixel shader for an image processing app. I think I am making a very basic mistake. First, I am running Linux, OpenGl 2.0, on an Nvidia platform. As you would notice, most of the code is from nehe. The following are my shaders, very basic... -------------- //frag uniform sampler2D myTexture1; uniform sampler2D myTexture2; void main (void) { vec4 texval1 = texture2D(myTexture1, vec2(gl_TexCoord[0])); vec4 texval2 = texture2D(myTexture2, vec2(gl_TexCoord[1])); gl_FragColor = abs(texval1 - texval2); } ---------------------- //vertex void main(void) { gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[1] = gl_MultiTexCoord1; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } --------------------- Heres the drawing code... int drawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); GLint p; p= glGetUniformLocation(my_program, "myTexture1"); printf("Handle for uniform sampler myTexture1 is %d\n", p); GLint q; q= glGetUniformLocation(my_program, "myTexture2"); printf("Handle for uniform sampler myTexture2 is %d\n", q); /*End shader part*/ if (!loadGLTextures()) { return False; } glActiveTexture(GL_TEXTURE0 ); glBindTexture(GL_TEXTURE_2D, texture[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture[1]); glUseProgramObjectARB(my_program); glUniform1iARB(p, 0 ); glUniform1iARB(q, 1); glBegin(GL_QUADS); /* front face */ glNormal3f(0.0f, 0.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glEnd(); glUseProgramObjectARB(0); glXSwapBuffers(GLWin.dpy, GLWin.win); return True; } My shaders complile perfectly, so do both the textures. Now the trouble is that in the above funtion, when i try to pass the two textures to my shader code, only the first one reflects in the output, the second texture is somehow magically converted to a gray image. I ll put the problematic(i think) part again ----------- glActiveTexture(GL_TEXTURE0 ); glBindTexture(GL_TEXTURE_2D, texture[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture[1]); glUseProgramObjectARB(my_program); glUniform1iARB(p, 0 ); // p and q are uniform locations glUniform1iARB(q, 1); --------------- p and q take values of 0 and 1 which i think is okay. Could you tell me what I am doing wrong? Thanks in advance, Dj p.s. i do have glext.h included.