title: Problems with OpenGL lighting
body: <p>I'm having trouble being able to see objects I've created when I have enabled lighting in OpenGL. I have an object that is imported from 3D Max that the lighting works correctly on but the rest of my scene does not. I know that I need to specify normals but this hasn't seemed to have helped. Although if I create a simple polygon in my display() function that works correctly but other polygons that have been created in methods of a class and called in the display() function are not showing up</p>
  
  <p>Here is my lighting code</p>
  
  <pre><code>glewInit();
  
  glClearColor(0.0,0.0,0.0,0.0);
  glClear(GL_COLOR_BUFFER_BIT) 
  
  glShadeModel(GL_SMOOTH);
  
  //light position and colour
  GLfloat light_position[] = { 0.0, 0.0, 20.0,0.0 };
  GLfloat white_light[] = {0.8,0.8,0.8,0.0};
  GLfloat diff_light[] = {1.0,1.0,1.0,0.0};
  GLfloat spec_light[] = {1.0,1.0,1.0,0.0};
  glLightfv(GL_LIGHT0, GL_AMBIENT, white_light);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, diff_light);
  glLightfv(GL_LIGHT0, GL_SPECULAR, spec_light);
  glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  
  //ambient light
  GLfloat ambient[] = {0.3,0.3,0.3};
  glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
  
  //diffuse material component
  GLfloat diff[] = {0.6,0.6,0.6};
  glMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
  
  //specular material component
  GLfloat WhiteSpec[] = {1,1,1};
  glMaterialfv(GL_FRONT, GL_SPECULAR, WhiteSpec);
  
  GLfloat shininess = 50;
  glMaterialf(GL_FRONT, GL_SHININESS, shininess);
  
  //ENABLE LIGHTING AND DEPTH TEST
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  
  glEnable(GL_DEPTH_TEST);
  </code></pre>
  
  <p>This is my class method that is creating my sea</p>
  
  <pre><code>glColor3f(0,0,1);
  glPushMatrix();
  
  //enable texturing
  glEnable(GL_TEXTURE_2D);    
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glBindTexture(GL_TEXTURE_2D, seaTex);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  
  for(int i = 0, k = 0; i &lt; (getWidth()/10); i++){
      for(int j = 0; j &lt; (getLength()/10); j++){
          if(i &gt;= Sea::waveLoc1 &amp;&amp; i &lt;= Sea::waveLoc1+Sea::sinArrayLength){
  
              int nextK = k+1;
              if(nextK == Sea::sinArrayLength){
                  nextK = 0;
              }
  
              if(i == Sea::waveLoc1+Sea::sinArrayLength){
                  //front of wave
                  glBegin(GL_POLYGON);    
  
                  glNormal3f(0.0f, 1.0f, 0.0f);   
                      glTexCoord2f(0.0, 1.0);glVertex3f(Sea::seaGrid[i][j].x, Sea::sinVals[nextK], Sea::seaGrid[i][j].z);
                      glTexCoord2f(0.0, 0.0);glVertex3f(Sea::seaGrid[i][j+1].x, Sea::sinVals[nextK], Sea::seaGrid[i][j+1].z);
                      glTexCoord2f(1.0, 0.0);glVertex3f(Sea::seaGrid[i+1][j+1].x, Sea::seaGrid[i+1][j+1].y , Sea::seaGrid[i+1][j+1].z);
                      glTexCoord2f(1.0, 1.0);glVertex3f(Sea::seaGrid[i+1][j].x, Sea::seaGrid[i+1][j].y, Sea::seaGrid[i+1][j].z);
                  glEnd();
              }else{
                  //rest of wave
                  glBegin(GL_POLYGON);    
  
                  glNormal3f(0.0f, 1.0f, 0.0f);   
                      glTexCoord2f(0.0, 1.0);glVertex3f(Sea::seaGrid[i][j].x, Sea::sinVals[k], Sea::seaGrid[i][j].z);
                      glTexCoord2f(0.0, 0.0);glVertex3f(Sea::seaGrid[i][j+1].x, Sea::sinVals[k], Sea::seaGrid[i][j+1].z);
                      glTexCoord2f(1.0, 0.0);glVertex3f(Sea::seaGrid[i+1][j+1].x, Sea::sinVals[nextK], Sea::seaGrid[i+1][j+1].z);
                      glTexCoord2f(1.0, 1.0);glVertex3f(Sea::seaGrid[i+1][j].x, Sea::sinVals[nextK], Sea::seaGrid[i+1][j].z);
                  glEnd();
              }
  
          }else{
              //draw flat sea
              glBegin(GL_POLYGON);    
  
                  glNormal3f(0.0f, 1.0f, 0.0f);
  
                  glTexCoord2f(0.0, 1.0);glVertex3f(Sea::seaGrid[i+1][j].x, Sea::seaGrid[i+1][j].y, Sea::seaGrid[i+1][j].z);
                  glTexCoord2f(0.0, 0.0);glVertex3f(Sea::seaGrid[i+1][j+1].x, Sea::seaGrid[i+1][j+1].y, Sea::seaGrid[i+1][j+1].z);
                  glTexCoord2f(1.0, 0.0);glVertex3f(Sea::seaGrid[i][j+1].x, Sea::seaGrid[i][j+1].y, Sea::seaGrid[i][j+1].z);
                  glTexCoord2f(1.0, 1.0);glVertex3f(Sea::seaGrid[i][j].x, Sea::seaGrid[i][j].y, Sea::seaGrid[i][j].z);
              glEnd();
          }
      }
  
      //increment k if i is in the area of the wave
      if(k &lt; Sea::sinArrayLength-1 &amp;&amp; (i &gt;= Sea::waveLoc1 &amp;&amp; i &lt;= Sea::waveLoc1+Sea::sinArrayLength)){
          k++;
      }else if(k == Sea::sinArrayLength){
          k = 0;
      }
  }
  
  if(Sea::waveLoc1 &lt; 100 &amp;&amp; Sea::waveInc == Sea::waveSpeedLimiter){
      Sea::waveLoc1 +=1;
  }else if(Sea::waveLoc1 &gt;= 100){
      Sea::waveLoc1 = 0;
  }
  
  //limits speed of wave
  if(Sea::waveInc &lt; Sea::waveSpeedLimiter){
      Sea::waveInc++;
  }else{
      Sea::waveInc = 0;
  }
  
  
  //disable texturing
  glDisable(GL_BLEND);
  glDisable(GL_TEXTURE_2D);
  glPopMatrix();
  </code></pre>
  
  <p>This is then called in my display() function as below</p>
  
  <pre><code>glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(45.0f,(GLfloat)screenWidth/(GLfloat)screenHeight,0.1f,1000.0f);
  
  glMatrixMode(GL_MODELVIEW);
  
  glLoadIdentity();
  
  camera.updateCameraPosition(mouse_x,mouse_y,screenWidth,screenHeight);
  
  
  sea.buildSeaPlane();
  scene.buildEdges();
  
  
  glPushMatrix(); 
  glColor3f(0,1,0);
  glTranslatef(0, 20, 200);
  model.speedDisplayFaceNormals();
  
  glPopMatrix();
  
  glPushMatrix();
  
  plane.updatePlanePosition();
  
  glBegin(GL_POLYGON);    
  
      glNormal3f(0.0f, 1.0f, 0.0f);
  
      glVertex3f(0, 25, 10);
      glVertex3f(2, 25, 10);
      glVertex3f(2, 25, 20);
      glVertex3f(0, 25, 20);
  glEnd();
  
  
  glPopMatrix();
  
  glFlush();  
  </code></pre>
  
  <p>Any idea why I can't see any of this?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I can see my sea if I disable texturing. How can I fix it so I can use textures and lighting?</p>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <p>Have changed texturing to GL_MODULATE but I also had to remove the blending to make it work. Do I need blending enabled?</p>