Help! Can't multitexture in GLSL

Trying to build your own version of Vega Strike and having problems? Unix users, paste your config.log here (stderr output alone is not helpful).
Post Reply
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Help! Can't multitexture in GLSL

Post by chuck_starchaser »

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.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Sorry about the OT-ness of the post; I was desperate and couldn't think of a better forum. My question was answered in usenet, BTW, as follows:
uniform variables, like texture-samplers, are initialised to 0. You have to
set their value manually:

Code: Select all

  int clouds_location = glGetUniformLocationARB(the_prog, "clouds");
  glUniform1iARB(clouds_location, 1);
This code assigns the cloud sampler to the second textureunit.
As the tex sampler is set to 0 automaticaly it will use the first texture
unit.
Multi-texturing is working now, but I have a new problem: Blackness creeps in as the sun illuminates the front of the planet, leaving only half size circle of my planet at noon. A brigth cissor cut circle with jaggy edges. Very weird. Then the the section grows again to look normal as the sun's about to pass the planet on the far side. I can't imagine what I did to cause this, but I tried removing multitexturing and it doesn't help...
Post Reply