I'm creating a open GL program with 6 Torus. When I applied the texture it's displaying with one color. Even though it's not in a single color.
I'm getting images from array. Other textures (skybox, planet, HUD) are applying properly except Torus textures. I tried to apply light source as well but no luck. Can somebody help me to achieve this?
Below is my code.
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glTranslatef(xpos, ypos, zpos);
glRotatef(fPlanetRot, 0.0f, -1.0f, 0.0f);
glColor3f(0.0, 0.0, 0.0);
// Select the texture object
glBindTexture(GL_TEXTURE_2D, textures[3]);
glutSolidTorus(0.1, 1.0, 30, 30);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
//This is where I load the texture
void SetupRC()
{
//textures
GLuint texture;
// allocate a texture name
glGenTextures( 1, &texture );
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
//there are quite a few ways of loading images
// Load textures in a for loop
glGenTextures(TEXTURE_COUNT, textures);
//this puts the texture into OpenGL texture memory
// glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - not defined so probably need to update GLEW - not needed here so ignore
for(int iLoop = 0; iLoop < TEXTURE_COUNT; iLoop++)
{
// Bind to next texture object
glBindTexture(GL_TEXTURE_2D, textures[iLoop]);
// Load texture data, set filter and wrap modes
//note that gltLoadTGA is in the glm.cpp file and not a built-in openGL function
pBytes0 = gltLoadTGA(textureFiles[iLoop],&iWidth, &iHeight,
&iComponents, &eFormat);
glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytes0);
//set up texture parameters
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);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//try these too
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
free(pBytes0);
}
//enable textures
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST); // Hidden surface removal
glFrontFace(GL_CCW);// Counter clock-wise polygons face out
glEnable(GL_CULL_FACE); // Do not calculate inside
// glCullFace(GL_FRONT_AND_BACK);
// Enable lighting
glEnable(GL_LIGHTING);
glEnable(GL_POINT_SMOOTH);
// Setup and enable light 0
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,whiteLightLessBright);
glLightfv(GL_LIGHT0,GL_DIFFUSE,redLight);
glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
glEnable(GL_LIGHT0);
// Enable colour tracking
glEnable(GL_COLOR_MATERIAL);
// Set Material properties to follow glColor values
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
// Black blue background
glClearColor(0.0f, 0.0f, 0.03f, 1.0f );
}