Original Post
Hi. ...I'm working on a 'forest walkthrough' and am having issues with the incorrect texture being 'binded' to objects that it is not supposed to be assigned to. Here are the display lists that are called:
void InitDisplayLists(void)
{
//draw bark
glNewList(1,GL_COMPILE);
glBindTexture(GL_TEXTURE_2D, textures[1]);
gluCylinder(q,1.f,1.f,1.f,5.f,5.f);
glEndList();
//draw leaves
glNewList(2,GL_COMPILE);
glBindTexture(GL_TEXTURE_2D, textures[2]);
gluDisk(q1,0.f,8.f,4.f, 4.f);
glEndList();
//draw the ground
glNewList(3, GL_COMPILE);
glBegin(GL_QUADS);
glColor3ub(50,50,50);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexCoord2f(100.0f, 100.0f);glVertex3f(-100,-0.6,-100);
glTexCoord2f(0.0f, 100.0f);glVertex3f(100,-0.6,-100);
glTexCoord2f(0.0f, 0.0f);glVertex3f(100,-0.6,100);
glTexCoord2f(100.0f, 0.0f);glVertex3f(-100,-0.6,100);
glEnd();
glEndList();
}
(q and q1 are quadrics. ...I have gluQuadricNormals([quadricobject], GLU_SMOOTH) and gluQuadricTexture([quadricobject], GL_TRUE) set for each of them) my texture loading functions look like this:
void InitTextureObjects()
{
//--------
//|Ground|
//*****************************
ground.data = LoadTGA("grass2.tga", &x, &y, &d);
ground.bitdepth = d;
ground.width = x;
ground.height = y;
//trunk and branches
bark.data = LoadTGA("bark1.tga", &x, &y, &d);
bark.bitdepth = d;
bark.width = x;
bark.height = y;
//leaves
leaf_oak.data = LoadTGA("bark1.tga", &x, &y, &d);
leaf_oak.bitdepth = d;
leaf_oak.width = x;
leaf_oak.height = y;
//skydome texture
sky.data = LoadTGA("sky.tga", &x, &y, &d);
sky.bitdepth = d;
sky.width = x;
sky.height = y;
printf("All texture objects loaded\n");
printf("ground.textureID = %d\n", ground.textureID);
printf("bark.textureID = %d\n", bark.textureID);
printf("leaf_oak.textureID = %d\n", leaf_oak.textureID);
}
GLuint Map1_2DTexture(GLuint target, Texture texture)
{
//1. Generate the Texture ID -:glGenTextures
//2. Bind texture to Texture array -:glBindTexture
//3. Set the TexImage2D pointer -:glTexImage2D
//4. Set Texture Parameters -: glTexParameteri
//5. Mipmap
//6. Release Texture memory if texture.lastUse = true, cuz it's done
//1.genID
//2.bind
glBindTexture(GL_TEXTURE_2D, target);
//3.set image
if(texture.bitdepth == 32)
{
glTexImage2D(GL_TEXTURE_2D, 0, 4, texture.width, texture.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture.data);
}
else
{
printf("Invalid Texture Format %d\n", target);
exit(1);
}
//4. texp
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//5. Mipmap
return target;
}
void InitTextures()
{
glGenTextures(1, &textures[0]);
glGenTextures(1, &textures[1]);
glGenTextures(1, &textures[2]);
glGenTextures(1, &textures[3]);
ground.textureID = Map1_2DTexture(textures[0], ground);
bark.textureID = Map1_2DTexture(textures[1], bark);
leaf_oak.textureID = Map1_2DTexture(textures[2], leaf_oak);
sky.textureID = Map1_2DTexture(textures[3], sky);
printf("ground = %d & %d\n", textures[0], ground.textureID);
printf("bark = %d & %d\n", textures[1], bark.textureID);
printf("leaf = %d & %d\n", textures[2], leaf_oak.textureID);
printf("sky = %d & %d\n", textures[3], sky.textureID);
}
(the printfs are used for debugging. I used both GLuint textures[] and the textureID of my texture struct to store the texture# just to make sure that I was assigning TextureIDs consistently) I have a recursive function defined for procedurally creating a tree for me that I can't divulge, but basically I draw the trunk until I reach the end of the branches, then I draw leaves. So, while I'm not at the end of the 'woody' part of the tree, glCallList(1) is called, and whenever I reach the end, glCallList(2) is called. ...Ok, there's the relevant information; now to my issue. Whenever I load only the grass texture for the ground and run my application, everything in my scene is textured with grass. ...But, whenever I load the other textures for the trees and try to bind the textures to their respective objects, the grass shows up as grass, everything else shows up as bark, and as soon as I move, the bark texture gets applied to everything. Does anybody have any idea what could be causing this? ...if anybody would like to see the rest of my code, ask and I'll post.