Help! Can't multitexture in GLSL
Posted: Sun May 29, 2005 5:32 am
I'm trying to use multitexturing with GLSL shaders and it's not working:
Whichever texture I bind to texture unit 0 gets used used for both 0 and 1. I'm compiling with MinGW under Dev C++, and my videocard is gforce6.
my includes:
#include <GL/glew.h>
#include <GL/glut.h>
all the windowing stuff, then..
glewInit();
if(GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
plog.log_note("glew initialized! Ready for GLSL\n");
else
{
plog.log_note("glew blew No GLSL support\n");
exit(1);
}
which passes aok, then I have..
::glActiveTextureARB(texture_unit);
::glBindTexture(GL_TEXTURE_2D, name);
::gluBuild2DMipmaps(.......); ::glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
::glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); ::glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
::glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
::glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY,16);
.. for each of my two textures.
Then I set up my lights and matrices, then,
glEnable(GL_CULL_FACE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
..and in the loop:
glPushMatrix ();
glUseProgramObjectARB(the_prog_);
glRotatef (theta, 0.0f, 1.0f, 0.0f);
glutSolidSphere(1.0, 256, 128);
glPopMatrix ();
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_CULL_FACE);
glPopMatrix ();
SwapBuffers (hDC);
theta += 0.05f;
Sleep (7);
My vertex shader looks like,
void main()
{
...........................
gl_TexCoord[0].x = longitude/(2.0*3.141592);
gl_TexCoord[0].y = clamp( 0.5*(1.0-v4.z), 0.0, 1.0);
gl_TexCoord[1].x = gl_TexCoord[0].x;
gl_TexCoord[1].y = clamp( 0.5-0.25*(v4.z+v4.z*v4.z*v4.z), 0.0, 1.0);
...........................
}
And my fragment shader:
...........................
uniform sampler2D tex;
uniform sampler2D clouds;
void main()
{
...........................
vec4 pix_tex0 = texture2D(tex,gl_TexCoord[0].st);
vec4 pix_tex1 = texture2D(clouds,gl_TexCoord[1].st);
...........................
gl_FragColor = pix_tex0 * light_acc * (1-atmo_alpha);
...........................
gl_FragColor += 0.2*intensity*(pix_tex1);
};
So, like I said, there is blending going on but of only one texture, blended twice, --namely, whichever texture I bind to texture unit 0. The other doesn't show. The order in which I bind the textures does not seem to make a difference.
And if I only use texture unit 1, no texture shows up.
Any help would be appreciated.
Whichever texture I bind to texture unit 0 gets used used for both 0 and 1. I'm compiling with MinGW under Dev C++, and my videocard is gforce6.
my includes:
#include <GL/glew.h>
#include <GL/glut.h>
all the windowing stuff, then..
glewInit();
if(GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
plog.log_note("glew initialized! Ready for GLSL\n");
else
{
plog.log_note("glew blew No GLSL support\n");
exit(1);
}
which passes aok, then I have..
::glActiveTextureARB(texture_unit);
::glBindTexture(GL_TEXTURE_2D, name);
::gluBuild2DMipmaps(.......); ::glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
::glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); ::glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
::glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
::glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY,16);
.. for each of my two textures.
Then I set up my lights and matrices, then,
glEnable(GL_CULL_FACE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
..and in the loop:
glPushMatrix ();
glUseProgramObjectARB(the_prog_);
glRotatef (theta, 0.0f, 1.0f, 0.0f);
glutSolidSphere(1.0, 256, 128);
glPopMatrix ();
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_CULL_FACE);
glPopMatrix ();
SwapBuffers (hDC);
theta += 0.05f;
Sleep (7);
My vertex shader looks like,
void main()
{
...........................
gl_TexCoord[0].x = longitude/(2.0*3.141592);
gl_TexCoord[0].y = clamp( 0.5*(1.0-v4.z), 0.0, 1.0);
gl_TexCoord[1].x = gl_TexCoord[0].x;
gl_TexCoord[1].y = clamp( 0.5-0.25*(v4.z+v4.z*v4.z*v4.z), 0.0, 1.0);
...........................
}
And my fragment shader:
...........................
uniform sampler2D tex;
uniform sampler2D clouds;
void main()
{
...........................
vec4 pix_tex0 = texture2D(tex,gl_TexCoord[0].st);
vec4 pix_tex1 = texture2D(clouds,gl_TexCoord[1].st);
...........................
gl_FragColor = pix_tex0 * light_acc * (1-atmo_alpha);
...........................
gl_FragColor += 0.2*intensity*(pix_tex1);
};
So, like I said, there is blending going on but of only one texture, blended twice, --namely, whichever texture I bind to texture unit 0. The other doesn't show. The order in which I bind the textures does not seem to make a difference.
And if I only use texture unit 1, no texture shows up.
Any help would be appreciated.