A simple light

BlitzMax Forums/OpenGL Module/A simple light

Ryan Burnside(Posted 2007) [#1]
I've looked at the Nehe tutorials and still don't understand how you implement a light. I have my model loaded and ready for light. Is there a simple block of code I could use to define a light for each step?


Odds On(Posted 2007) [#2]
First step is to enable lighting:

glEnable( GL_LIGHTING );

Next, enable the first OpenGL light:

glEnable( GL_LIGHT0 );

You only need to do that once, so put it in your initialisation method. That's it really. You'll probably want to position it and set other properties like colour etc, which you should be able to find out how to do on the Nehe website, but essentially you can just do:

light_pos:Float[] = [ 1.0, 1.0, 1.0, 1.0 ]
glLightfv( GL_LIGHT0, GL_POSITION, light_pos )

where the first three 1.0 values are the x, y and z locations for the light, and the fourth value defines if it is a point light or a directional light (1.0 means point light, 0.0 means directional). That should be done every frame before rendering any other objects.

Hope this helps,
Chris