Turning on the Light.
Lights have very similar properties as materials, only they apply to the effects they have on object, since you can't see a light. Also OpenGl only promises that you can create 8 lights at a time. In this demo there is one directional blue light going down the z-axis.
- Before the lights show up you have to enable them
- Enable lighting
- glEnable(GL.GL_LIGHTING)
- Enable Auto Normals: normals are vectors that point out from the face of an object. They have to be computed for polygons like the cube we made in tutorial 3 but they are automatically made the the the teapot.
- glEnable(GL.GL_AUTO_NORMAL)
- Enable the light(s) you are going to use
-
glEnable(GL.GL_LIGHT0)
or
glEnable(GL.GL_LIGHT1)
GL.GL_LIGHT( and the number of the light goes here) - Set the properties to each light.
- Ambient color
- gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, [r,g,b, 1.0], 0);
- Diffuse Color: this is color the light will cast onto objects.
- gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, [r,g,b, 1.0], 0);
- Specular Highlighting: the color the light give glares
- gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, [r,g,b, 1.0], 0);
- Position
- gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, [x, y, z, 0.0], 0);
- If you use zero as the last member of the position array, the light will be a directional light and a 1 will make it a source light. More on this in the next tutorial.
