Hi guys,
I have a scene in which there is a background mesh, and two other meshes. All these meshes are textured with different textures and each texture has a transparent background. I already got it so the meshes that are textured are transparent and the textures still show up correctly(with alpha and everything.) but when I render all the meshes and texture them, it seems to render each each texture, one superimposed on the last. I can’t seem to figure out why?
Here is the Rendering and Texturing code:
void RenderAll()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
Texture(BOARD);
b->Render();
Texture(CHAR_X);
c->Render(CHAR_X);
Texture(CHAR_O);
c->Render(CHAR_O);
g->Switch(hDC);
}
void Texture(int ID)
{
switch(ID)
{
case BOARD:
{
glBindTexture(GL_TEXTURE_2D, tex[0]);
break;
}
case CHAR_X:
{
glBindTexture(GL_TEXTURE_2D, tex[1]);
break;
}
case CHAR_O:
{
glBindTexture(GL_TEXTURE_2D, tex[2]);
break;
}
}
}
void LoadTextures()
{
GLint width, height, components;
YsRawPngDecoder *png = new YsRawPngDecoder();
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_RGBA);
//LOAD THE ACTUALL IMAGES
for(int i = 0; i < 3; ++i)
{
GLubyte *data;
glBindTexture(GL_TEXTURE_2D, tex[i]);
if(i == 0)
{
png->Decode("Art/Board_Basic.png");
data = png->rgba;
width = png->wid;
height = png->hei;
}
else if(i == 1)
{
png->Decode("Art/X_Basic.png");
data = png->rgba;
width = png->wid;
height = png->hei;
}
else
{
png->Decode("Art/O_Basic.png");
data = png->rgba;
width = png->wid;
height = png->hei;
}
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
}
}
The main application is Win32, but rendering, I/O, user interaction, etc. is all done abstractly from the OS in C++.
“b” , “c” , and “g” are all classes