Anyways, I'm trying to get a colored light shining on a different colored object.
My light colors are set with
GLfloat ambientLight[] = { 0.0, 0.3f, 0.0f, 1.0f };
GLfloat diffuseLight[] = { 0.0f, 0.7f, 0.0f, 1.0f };
and my object color is set via color tracking with
glColor3f(1.0, 0.0, 0.0);
However, in my scene, I only get a dark red cube, not a red cube with a green light on it. Can somebody please tell me what I'm doing wrong?
Here is my code
#include#include #include "3dMath.h" GLfloat xrot = 0.0f; GLfloat yrot = 0.0f; //Define my cube triangles, 6 sides to a cube, so 12 triangles in all (with 3 vertices each) float cube[12][3][3] = { {{-50, 50, -50}, {50, 50, -50}, {-50, -50, -50}}, //Triangle 1 {{50, 50, -50}, {50, -50, -50}, {-50, -50, -50}}, //Triangle 2 {{50, 50, -50}, {50, 50, 50}, {50, -50, -50}}, //Triangle 3 {{50, 50, 50}, {50, -50, 50}, {50, -50, -50}}, //Triangle 4 {{50, 50, 50}, {-50, -50, 50}, {50, -50, 50}}, //Triangle 5 {{50, 50, 50}, {-50, 50, 50}, {-50, -50, 50}}, //Triangle 6 {{-50, -50, 50}, {-50, 50, 50}, {-50, 50, -50}}, //Triangle 7 {{-50, -50, 50}, {-50, 50, -50}, {-50, -50, -50}}, //Triangle 8 {{50, 50, 50}, {50, 50, -50}, {-50, 50, -50}}, //Triangle 9 {{50, 50, 50}, {-50, 50, -50}, {-50, 50, 50}}, //Triangle 10 {{50, -50, 50}, {-50, -50, 50}, {-50, -50, -50}}, //Triangle 11 {{50, -50, -50}, {50, -50, 50}, {-50, -50, -50}}};//Triangle 12 float cubeNormals[12][3]; //Contains one normal for each triangle in the cube. void ChangeSize(GLsizei w, GLsizei h) { if(h == 0) h = 1; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60, (GLfloat)w/(GLfloat)h, 1, 400); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void RenderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); glTranslatef(0.0f, 0.0f, -10.0f); glRotatef(xrot, 1.0f, 0.0f, 0.0f); glRotatef(yrot, 0.0f, 1.0f, 0.0f); //Draw the cube /*glBegin(GL_TRIANGLES); int i = 0; for(i = 0; i<12; i++) { glNormal3f(cubeNormals[0], cubeNormals[i][1], cubeNormals[i][2]); glVertex3f(cube[i][0][0], cube[i][0][1], cube[i][0][2]); glVertex3f(cube[i][1][0], cube[i][1][1], cube[i][1][2]); glVertex3f(cube[i][2][0], cube[i][2][1], cube[i][2][2]); } glEnd();*/ glColor3f(1.0, 0.0, 0.0); glutSolidCube(5.0); glPopMatrix(); glutSwapBuffers(); } void Keyboard(int key, int x, int y) { if(key == GLUT_KEY_UP) xrot -= 5; if(key == GLUT_KEY_DOWN) xrot += 5; if(key == GLUT_KEY_RIGHT) yrot += 5; if(key == GLUT_KEY_LEFT) yrot -= 5; glutPostRedisplay(); } void SetupRC() { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //Setup a few flags glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); //Calculate all the normals in the cube for(int i = 0; i < 12; i++) { calcNormal(cube[i], cubeNormals[i]); ReduceToUnit(cubeNormals[i]); } //Setup polygons and lights glShadeModel(GL_SMOOTH); /// Light values and coordinates GLfloat ambientLight[] = { 0.0, 0.3f, 0.0f, 1.0f }; GLfloat diffuseLight[] = { 0.0f, 0.7f, 0.0f, 1.0f }; GLfloat lightPos[] = {0.f, 50.0f, 0.0f, 1.0f}; // Enable lighting glEnable(GL_LIGHTING); // Setup and enable light 0 glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight); glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight); glLightfv(GL_LIGHT0,GL_POSITION,lightPos); glEnable(GL_LIGHT0); // Enable color tracking glEnable(GL_COLOR_MATERIAL); // Set Material properties to follow glColor values glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); } void main(void) { glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("Primitives"); glutDisplayFunc(RenderScene); glutReshapeFunc(ChangeSize); glutSpecialFunc(Keyboard); SetupRC(); glutMainLoop(); }
Edited by - Blackstream on July 9, 2001 8:06:38 PM






