Why is the cylinder automatically texture mapped?
Hi,
I am mapping textures onto a cube. On the top layer of the cube is a cylinder.
I noticed that when a texture is mapped onto the cube, the cylinder is automatically texture mapped as well, even when I didnt enable any texturing coordinates for the cylinder.
I've added some code snippets below:
These are the standard code for texture mapping:
glGenTextures(1,&texture[0]);
glBindTexture(GL_TEXTURE_2D,texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,0,
GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data);
Then I draw and texture map the cube. It is done inside the DrawWalls() function.
glBindTexture(GL_TEXTURE_2D,texture[0]);
glBegin(GL_QUADS);
//Front face
glTexCoord2f(0.0f,0.0f); glVertex3f(-6.0f,-7.0f,5.0f); //Bottom left
glTexCoord2f(1.0f,0.0f); glVertex3f(6.0f,-7.0f,5.0f); //Bottom right
glTexCoord2f(1.0f,1.0f); glVertex3f(6.0f,7.0f,5.0f); //Top right glTexCoord2f(0.0f,1.0f); glVertex3f(-6.0f,7.0f,5.0f); //Top left
.......
glEnd();
Then in the InitGL function, I set up the code for the cylinder:
quadratic=gluNewQuadric(); // Create A Pointer To The Quadric Object. quadratic is a GLuquadricObj pointer created earlier
gluQuadricNormals(quadratic, GLU_SMOOTH); // Create Smooth Normals
gluQuadricTexture(quadratic, GL_TRUE); // Create Texture Coords
Then finally, in the main rendering function, I call the function to draw the cube first before drawing the cylinder.
glTranslatef(0.0f,0.0f,-10.0f); //shift -10 units back on the z axis
DrawWalls(); // draw the cube
glTranslatef(0.0f,7.0f,-4.0f); // shift the cylinder to the top of the cube
glRotatef(-90.0f,1.0f,0.0f,0.0f); // make the cylinder point upwards
gluCylinder(quadratic,3.0f,3.0f,7.0f,32,32); // draw the cylinder
This is all. I would want to texture map the cylinder also but I don't want it to be automatically texture mapped by whatever texture is applied to other objects. Is there any problem in the code?