PDA

View Full Version : Multiple Texture Help



Raito07
01-30-2013, 01:52 PM
Hi ,
i have problem with Opengl texture, i couldnot understand why it not working

GLuint textid[2];
CBmp *mBmp1,*mBmp2; //CBmp class is loading .bmp file

initGl()
{
... // others initalizing

glGenTextures(2,textid);

mBmp1 = new CBmp("linux.bmp");
if(!(mBmp1->init()) ){ std::cout << "failed" ;}

glBindTexture(GL_TEXTURE_2D, textid[0]);

glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
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_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mBmp1->getWidth(), mBmp1->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, mBmp1->getBuffer(0));
mBmp1->freeBuffer();

mBmp2 = new CBmp("Sample.bmp");
if(!(mBmp2->init()) ){ std::cout << "failed" ;}

glBindTexture(GL_TEXTURE_2D, textid[1]);
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
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_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mBmp2->getWidth(), mBmp2->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, mBmp2->getBuffer(0));

mBmp2->freeBuffer();
}

DisplayFunc()
{
glBegin(GL_QUADS);

glBindTexture(GL_TEXTURE_2D,textid[1]); //(1)
glNormal3f( 0.0f, 0.0f,-1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(MaxX,MaxY,MinZ); //F
glTexCoord2f(1.0f, 1.0f); glVertex3f(MinX,MaxY,MinZ); //E
glTexCoord2f(1.0f, 0.0f); glVertex3f(MinX,MinY,MinZ); //H
glTexCoord2f(0.0f, 0.0f); glVertex3f(MaxX,MinY,MinZ); //G

glBindTexture(GL_TEXTURE_2D,textid[0]); //(2)
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(MinX,MinY,MaxZ);
glTexCoord2f(1.0f, 0.0f); glVertex3f(MaxX,MinY,MaxZ);
glTexCoord2f(1.0f, 1.0f); glVertex3f(MaxX,MaxY,MaxZ);
glTexCoord2f(0.0f, 1.0f); glVertex3f(MinX,MaxY,MaxZ);
glEnd();

glPopMatrix();

}

(1) and (2) line code is not working. i changed or remove them ,nothing happened ,last .bmp file("sample.bmp") is always loading
where am i making mistake?

thanks for now

tonyo_au
01-30-2013, 10:46 PM
I don't believe you can change texture bindings inside a begin/end block.