I know web pages should be past this, but this site doesn't look right on IE.
I will fix it some day ( not for IE 6 though) but for now this is easier and a lot more fun.

Download firefox or chrome or hide this message forever...

Add a Couple More Lights




The are four major types of lights in OpenGL: ambient, directional, source, and spotlight. We took a look at directional lighting last tutorial. In this one we will look at the others. In the demo there is now a yellow source light at the intersection of the three axis, and a red spotlight to the left of the camera.


  • Ambient
    • This is often referred to as Cosmic Background Radiation. This one is a little different because there is only one and you can only change one thing, the color.
    • glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, [r,g,b, 1.0])
  • The next three kinds of lights are vary similar in how they are create. They all share the same four basic attributes discussed in the previous tutorial
  • Directional
    • A directional light is a light the just has a direction and not a source.
    • You can make a directional light by setting the fourth number in the position array to 0. It is highlighted below in yellow.
    • gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, [r,g,b, 1.0], 0);
      gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, [r,g,b, 1.0], 0);
      gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, [r,g,b, 1.0], 0);
      gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, [x, y, z, 0.0], 0);
  • Source
    • A source light is a light emanates from a single point.
    • You can make a source light by setting the fourth number in the position array to 1. It is highlighted below in yellow.
    • gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, [r,g,b, 1.0], 0);
      gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, [r,g,b, 1.0], 0);
      gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, [r,g,b, 1.0], 0);
      gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, [x, y, z, 1.0], 0);
  • Spotlight
    • A spotlight is just like a spotlight in real life. It is a source light that emits light in a controlled direction with a controlled beam.
    • It is created exactly like a source light only you set the the cutoff angle. This is the angle from the center of the beam of light to edge.
    • gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, [r,g,b, 1.0], 0);
      gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, [r,g,b, 1.0], 0);
      gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, [r,g,b, 1.0], 0);
      gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, [x, y, z, 1.0],1.0);
      gl.glLightf(GL.GL_LIGHT2, GL.GL_SPOT_CUTOFF, angel in degrees);