View Full Version : Light
12-31-2007, 10:19 AM
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...
12-31-2007, 06:26 PM
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:
1. 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.
2. 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).
3. 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.
4. 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.
01-01-2008, 07:23 AM
I think I have done it.... i think it's a little be weak my sun light but i will fix it...
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.