I have a solar system and I want to make the sun my light source.Can anyone tell me how, if it’s not big trouble…
I assume you are using fixed function pipeline (without vertex & fragment shaders).
You must use the regular method of setting up lighting using the OpenGL API:
- Set up desired light parameters of the sun by using glLightf / glLightfv functions.
This includes light colors (GL_AMBIENT, GL_DIFFUSE and GL_SPECULAR parameters), light position (GL_POSITION) and attenuation factors (GL_LINEAR_ATTENUATION, GL_CONSTANT_ATTENUATION and GL_QUADRATIC_ATTENUATION). Attenuation parameters control how far the light reaches.
There are also GL_SPOT_DIRECTION, GL_SPOT_EXPONENT and GL_SPOT_CUTOFF parameters, but you don’t need these since you are setting up a point light.
- Set up desired material properties before drawing planets. This is done by using glMaterialf / glMaterialfv functions.
This includes material colors (GL_EMISSIVE, GL_AMBIENT, GL_DIFFUSE and GL_SPECULAR) and the shininess factor (GL_SHININESS).
-
Enable GL_LIGHTING and GL_LIGHTi, where i is the light index of the sun. This is probably GL_LIGHT0 if you don’t have any other light sources in the scene.
-
Draw planets by using regular OpenGL drawing commands.
Check the OpenGL specification for details. There is also a very good book called “OpenGL Programming Guide” which explains everything about OpenGL. A must have for a student learning this API!
If you want to use shaders then you must do things differently, but you should probably learn fixed functionality first.
I hope this was some help to you.
I think I have done it… i think it’s a little be weak my sun light but i will fix it…
Thanks anyway