Please help me with the lighting...

there is something wrong with my lighting. please check this and tell me why lighting is not working as desired…?


#include <GL/glut.h>


void init(void)
{
  glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
  glShadeModel(GL_FLAT);
}

void display(void)
{
  glClear(GL_COLOR_BUFFER_BIT);

  glLoadIdentity();
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);
  glColor3f(0.453, 0.465, 0.123);
  glTranslatef(1.43, 1.8, 2.36);
  glScalef(3.2, 0.001, 2.2);
  glutSolidCube(1);

  glLoadIdentity();
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);

  glTranslatef(1.22098, 2.3, 0.68507);
  glScalef(3.5, 1.5, 0.25);
  glutSolidCube(1);


  glLoadIdentity();
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);
  glColor3f(0.4, 0.415, 0.123);
  glTranslatef(1.46988, 0.87911, -0.65016);
  glScalef(0.025, 1.65, 0.35);
  glutSolidCube(1);


  glLoadIdentity();
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);

  glTranslatef(-2.50068, 0.87911, -0.65016);
  glScalef(0.025, 1.65, 0.35);
  glutSolidCube(1);

  glLoadIdentity();
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);

  glTranslatef(0.85, 1.4, 0.6);
  glScalef(3.4, 0.025, 0.30);
  glutSolidCube(1);

  glLoadIdentity();
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);

  glTranslatef(0.85, 2.74, 0.6);
  glScalef(3.3, 0.025, 0.30);
  glutSolidCube(1);

  glLoadIdentity();
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);

  glTranslatef( 2.2, 0.8, 1.5);
  glScalef(0.1, 0.1, 2.5);
  glutSolidCube(1);

  glLoadIdentity();
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);

  glTranslatef(-1.5, 0.8, 1.5);
  glScalef(0.1, 0.1, 2.5);
  glutSolidCube(1);

  glLoadIdentity();
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);

  glTranslatef(1.43, 1.8, 3.4);
  glScalef(3.2, 0.1, 0.1);
  glutSolidCube(1);

  glLoadIdentity();
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);

  glTranslatef(1.43, 1.8, 1.2);
  glScalef(3.2, 0.1, 0.1);
  glutSolidCube(1);

  glLoadIdentity();
  glColor3f(0.35, 0.16, 0.14);
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);
  glTranslatef(-0.5, -0.1, -2.5);
  GLUquadricObj *quadratic;
  quadratic = gluNewQuadric();
  glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
  gluCylinder(quadratic, 0.2f, 0.2f, 1.7f, 32, 32);

  glLoadIdentity();
  glColor3f(0.35, 0.16, 0.14);
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);
  glTranslatef(-1.0, -0.1, -2.5);

  quadratic = gluNewQuadric();
  glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
  gluCylinder(quadratic, 0.2f, 0.2f, 1.7f, 32, 32);
  glLoadIdentity();
  glColor3f(0.35, 0.16, 0.14);
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);
  glTranslatef(-1.5, -0.1, -2.5);

  quadratic = gluNewQuadric();
  glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
  gluCylinder(quadratic, 0.2f, 0.2f, 1.7f, 32, 32);

  glLoadIdentity();
  glColor3f(0.35, 0.16, 0.14);
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);
  glTranslatef(-2.0, -0.1, -2.5);

  quadratic = gluNewQuadric();
  glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
  gluCylinder(quadratic, 0.2f, 0.2f, 1.7f, 32, 32);

  glLoadIdentity();
  glColor3f(0.35, 0.16, 0.14);
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);
  glTranslatef(-2.5, -0.1, -2.5);

  quadratic = gluNewQuadric();
  glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
  gluCylinder(quadratic, 0.2f, 0.2f, 1.7f, 32, 32);

  glLoadIdentity();
  glColor3f(0.35, 0.16, 0.14);
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);
  glTranslatef(-3.0, -0.1, -2.5);

  quadratic = gluNewQuadric();
  glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
  gluCylinder(quadratic, 0.2f, 0.2f, 1.7f, 32, 32);

  glLoadIdentity();
  glColor3f(0.35, 0.16, 0.14);
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);
  glTranslatef(-3.5, -0.1, -2.5);

  quadratic = gluNewQuadric();
  glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
  gluCylinder(quadratic, 0.2f, 0.2f, 1.7f, 32, 32);

  glLoadIdentity();
  glColor3f(0.35, 0.16, 0.14);
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);
  glTranslatef(-4.0, -0.1, -2.5);

  quadratic = gluNewQuadric();
  glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
  gluCylinder(quadratic, 0.2f, 0.2f, 1.7f, 32, 32);
  glLoadIdentity();
  glColor3f(0.35, 0.16, 0.14);
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);
  glTranslatef(-4.5, -0.1, -2.5);

  quadratic = gluNewQuadric();
  glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
  gluCylinder(quadratic, 0.2f, 0.2f, 1.7f, 32, 32);

  glLoadIdentity();
  glColor3f(0.35, 0.16, 0.14);
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);
  glTranslatef(2.0, -0.1, -2.5);

  quadratic = gluNewQuadric();
  glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
  gluCylinder(quadratic, 0.2f, 0.2f, 1.7f, 32, 32);

  glLoadIdentity();
  glRotatef(3.0,1.0,0.0,1.0);
  glColor3f(1.1, 1.1, 1.1);
  gluLookAt(8.0, 8.0, 7.0, 0.0, 0.0, 0.0, -3.0, -2.0, 3.0);
  glRasterPos3f(1.0, 0.0,0.0);
  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'C');
  glRasterPos3f( 0.5, 0.0,0.0);
  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'O');
  glRasterPos3f(0.0, 0.0,0.0);
  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'H');
  glRasterPos3f(-0.5, 0.0,0.0);
  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'I');
  glRasterPos3f(-1.0, 0.00,0.0);
  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'B');
  glRasterPos3f(-1.5, 0.00, 0.0);
  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'A');


  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  GLfloat ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
  GLfloat diffuseLight[] = { 0.8f, 0.8f, 0.8, 1.0f };
  GLfloat specularLight[] = { 0.5f, 0.5f, 0.5f, 1.0f };
  GLfloat position[] = { 0.27414f, 15.23099f, 15.79994f, 1.0f };
  glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
  glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
  glLightfv(GL_LIGHT0, GL_POSITION, position);

  glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
  glEnable(GL_COLOR_MATERIAL);

  glFlush();
}



void reshape(int w, int h)
{
  glViewport(0, 0, (GLsizei)w, (GLsizei)h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
  glMatrixMode(GL_MODELVIEW);
}



int main(int argc, char** argv)

{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowSize(500, 500);
  glutInitWindowPosition(100, 100);
  glutCreateWindow(argv[0]);
  init();
  glutDisplayFunc(display);
  glutReshapeFunc(reshape);
  glutMainLoop();
  return 0;
}

You didn’t specify what “desired” is, what the problem is, or what you’ve tried to do yourself to solve the problem.

This isn’t a debugging service. Give it a try yourself, and then ask some specific OpenGL-related questions.

Also, check out our Forum Posting Guidelines.