PDA

View Full Version : I will be mad :-( Big Bug About glActiveTexture in GLSL application



Jedimaster
11-18-2005, 07:34 AM
FIRST I MUST LOAD TEXTURES FROM BMP MAP

void init2DTextures(GLuint* texName,char *texPath,GLint texUnit)
{
AUX_RGBImageRec *TextureImage[1];
memset(TextureImage,0,sizeof(void *)*1);


TextureImage[0]=LoadBMP(texPath);
glGenTextures(1, texName);
glBindTexture(GL_TEXTURE_2D, texName);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glActiveTexture(GL_TEXTURE0_ARB+texUnit);

if (TextureImage[0])
{
if (TextureImage[0]->data)
{
free(TextureImage[0]->data);
}

free(TextureImage[0]);
}
glEnable(GL_TEXTURE_2D);

}

init2DTexture function is based on NEHE and a pdf from 3dlabs.

Now I load 2 texture in main function as following:

init2DTextures(&tex[0],"0.bmp",0);
init2DTextures(&tex[1],"1.bmp",1);

I DO NOT think there is something wrong,i checked it for a long time, easy to use :-)

but in my draw function as following:
void drawCube(void)
{
glTranslated(-1.0,-0.2,0.0);
glBegin(GL_QUADS);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 1.0);glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 1.0);
glVertex3f(0.0f,0.0f,0.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 0.0);glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex3f(1.0f,0.0f,0.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0, 0.0);glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 0.0);
glVertex3f(1.0f,1.0f,0.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0, 1.0);glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 1.0);
glVertex3f(0.0f,1.0f,0.0f);
glEnd();
}

I want to draw a square covered by 2 texture with mixed color effect.

BIG BIG WORM OUT !

If I use glActiveTexture(GL_TEXTURE0_ARB+texUnit),I can only see the second bmp not with first bmp.

If I use glActiveTexture(GL_TEXTURE1_ARB+texUnit), I CAN SEE CORRECT PICTURE.

If I use glActiveTexture(GL_TEXTURE4_ARB+texUnit[even bigger number]), I can see only 1st BMP.

What's the problem is ?
Thanks Thanks Thanks ! :)

Trahern
11-18-2005, 07:46 AM
well this definitely doesnt have anything to do with GLSL.. have you read anything about multitexturing before posting here??

you are calling
glActiveTexture(GL_TEXTURE0_ARB+texUnit);
after you bind your texture .. thats the problem

so what happens in your case is:
1. bind 1. texture into the active tex. unit ( which is GL_TEXTURE0 by default )
2. activate GL_TEXTURE0
3. bind 2. texture to the active unit ( which is still GL_TEXTURE0 )
4. activate GL_TEXTURE1

so its quite obvious where the problem is and it explains all the things listed at the end of your post

simply you have to activate the correct texture unit before binding anything to it.

Mars_999
11-18-2005, 04:00 PM
Originally posted by Trahern:
well this definitely doesnt have anything to do with GLSL.. have you read anything about multitexturing before posting here??

you are calling
glActiveTexture(GL_TEXTURE0_ARB+texUnit);
after you bind your texture .. thats the problem

so what happens in your case is:
1. bind 1. texture into the active tex. unit ( which is GL_TEXTURE0 by default )
2. activate GL_TEXTURE0
3. bind 2. texture to the active unit ( which is still GL_TEXTURE0 )
4. activate GL_TEXTURE1

so its quite obvious where the problem is and it explains all the things listed at the end of your post

simply you have to activate the correct texture unit before binding anything to it.Ouch! ;)