• Advertisement

Archived

This topic is now archived and is closed to further replies.

Lighting vs. newbie; lighting wins! (easy one; I'm sure)

This topic is 5736 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, I''m working with OpenGL and Win32 here. I''m drawing polygons no sweat. I want to add lighting. Problem is, as soon as I do, all polygons switch to grayscale gouraud shading. I don''t think I''m doing anything terribly special; the lighting is ripped right out of Tut #7. The only difference is lack of textures (I''m using glColor3f for everything atm) but that can''t be it, can it? Here''s my light initialization:
  
   GLfloat LightAmbient[]=   { 0.5f, 0.5f, 0.5f, 1.0f };
   GLfloat LightDiffuse[]=   { 1.0f, 1.0f, 1.0f, 1.0f };
   GLfloat LightPosition[]=  { 0.0f, 0.0f, 2.0f, 1.0f };

   glLightfv(GL_LIGHT0, GL_AMBIENT,  LightAmbient);
   glLightfv(GL_LIGHT0, GL_DIFFUSE,  LightDiffuse);
   glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
   glEnable(GL_LIGHT0);
   glEnable(GL_LIGHTING);
  
Here''s what I''m drawing (simple spinning colored pyramid):
  
int DrawGLScene(GLvoid)
{
   static GLfloat xrot = 0;
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);   // Clear Screen And Depth Buffer

   glLoadIdentity();

   float top[][3] = {
         { 0.0,  1.0,  0.0},
         { 1.5, -1.0, -1.5},
         {-1.5, -1.0, -1.5},
         {-1.5, -1.0,  1.5},
         { 1.5, -1.0,  1.5}
                    };

   float normal[][3] = {
         { 0.0,  0.0, -1.5},
         {-1.5,  0.0,  0.0},
         { 0.0,  0.0,  1.5},
         { 1.5,  0.0,  0.0}
                       };

   // begin actual drawing

   glTranslatef(0.0, 0.0, -6.0);     // Move Left 1.5 Units And Into The Screen 6.0

   glRotatef(xrot, 1.0, 0.5, 0.3);   // Rotate


   glBegin(GL_TRIANGLES);            // Drawing Using Triangles

      glNormal3fv(normal[0]);
      glColor3f(1.0, 0.0, 1.0);
      glVertex3fv(top[0]);
      glColor3f(0.0, 1.0, 1.0);
      glVertex3fv(top[1]);
      glColor3f(1.0, 1.0, 0.0);
      glVertex3fv(top[2]);

      glNormal3fv(normal[1]);
      glColor3f(1.0, 0.0, 1.0);
      glVertex3fv(top[0]);
      glColor3f(1.0, 1.0, 0.0);
      glVertex3fv(top[2]);
      glColor3f(0.0, 1.0, 1.0);
      glVertex3fv(top[3]);

      glNormal3fv(normal[2]);
      glColor3f(1.0, 0.0, 1.0);
      glVertex3fv(top[0]);
      glColor3f(0.0, 1.0, 1.0);
      glVertex3fv(top[3]);
      glColor3f(1.0, 1.0, 0.0);
      glVertex3fv(top[4]);

      glNormal3fv(normal[3]);
      glColor3f(1.0, 0.0, 1.0);
      glVertex3fv(top[0]);
      glColor3f(1.0, 1.0, 0.0);
      glVertex3fv(top[4]);
      glColor3f(0.0, 1.0, 1.0);
      glVertex3fv(top[1]);
   glEnd();                          // Finished Drawing The Triangle

   // end actual drawing


   xrot += 5;

   return TRUE;										// Everything Went OK

}
  
Truly, I am stumped ...... Chris Barry (crbarry at mts.net) My Personal Programming Depot

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement