PDA

View Full Version : Multitexturing not working



iris_raj
05-22-2007, 03:25 AM
Dear all,

I am trying to add mulitexturing feature to one my applications using GLSL. I am held up. It is not working even when I disable the shader.




//my display code
void renderScene(void)
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-7.0f);
glActiveTextureARB(GL_TEXTURE0_ARB);
glActiveTextureARB(GL_TEXTURE1_ARB);
glBegin(GL_QUADS);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex2f(-3.0f,-3.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0, 0.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 0.0);
glVertex2f(3.0f,-3.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0, 1.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 1.0);
glVertex2f(3.0,3.0);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 1.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 1.0);
glVertex2f(-3.0,3.0);
glEnd();

glFlush();
glutSwapBuffers();
}
//my texture initialization code
void init()
{
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, tex1D);
glEnable(GL_TEXTURE_2D);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Sometimes setting these params
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // is REQUIRED for FBOs!!
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth,checkImageHeight,0,GL_RGBA, GL_UNSIGNED_BYTE,checkImage);

//Second Texture
glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, tex2D);
glEnable(GL_TEXTURE_2D);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_INCR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Sometimes setting these params
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // is REQUIRED for FBOs!!
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth,checkImageHeight,0,GL_RGBA, GL_UNSIGNED_BYTE,otherImage);
}
void setshader()
{
glUniform1i(getUniLoc(p, "tex1"), 0);
glUniform1i(getUniLoc(p, "tex2"), 1);
}
//my vertex shader code
varying vec2 texture_coordinate;

void main()
{


gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

}
//My fragment shader code
uniform sampler2D tex1,tex2;

void main()
{
vec4 texval1 = texture2D(tex1, vec2(gl_TexCoord[0]));
vec4 texval2 = texture2D(tex2, vec2(gl_TexCoord[1]));

gl_FragColor = 0.5*(texval1 + texval2);

}

Please help me.

Thanks in advance
RAJESH.R