Lamp, or sun, or moon, or spot light: How to draw?

OpenGL:Lamp, sun, spotlight?
Hi all,

Does anyone know of any tutorial that teaches how to draw, using OpenGL, spot lights (or lamps, or moon or sun)that shine on regions or objects to illuminate them?

Basically, I need to render a realistic light source with the rest of the scene.

Pls advice if you know any method or tutorial.

draw a sphere and give it a material with some emissive color, ie glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color). This will not make it emit light, but will make it look correct after you make it emit light. Now place a light at the center of your sphere, and it will look like it is lighting everything up. Thats the best way I can think of, just make sure your other objects are sufficiently tesselated and to remove the emissive color when you are done with the lamp/sun/whatever.

hey thanks!
I’ll try it out!
There’s one part I do not really understand about your reply, which is about tessallation. In layman’s terms, can you tell me what is that?

I’ll explain what I meant by it. Opengl lighting is per vextex, so if your planets are just squares they won’t look very good if you put a sun in the middle. People expect a nice gradient but with only 4 vertices you generally get something that doens’t look very nice. This is especially obvious when you point an opengl spotlight at a single quad. Instead of getting a flashlight pattern you get nothing because the vertices are outside of the cone. Tesselation means that you split single polygons into many, in this case you do it to drastically improve lighting.

oh, ok… So with tessalation, the number of normal vectors will increase, and hence you can make the effect of the light source on the object more realistic,right?

but if I were to do it, I will probably do it manually, meaning to say I will just draw out each and every small region of the object, doing something like this:


glVertexf(x1,y1,z1);//first triangle

glVertexf(x1,y1,z1);//second triangle

…//nth triangle


so all the triangles will make up the object, and I have to add in individual normals to each triangle.
Is that correct? Or is there a short cut??
Thanks once again!!

yes, but even a perfectly flat surfaace needs to be tessalated to look good with opengl lighting. There is a glu tesselation function but I have no idea how it works, you would have to look it up. Most people use modeling software to make anything complicated and import the model

ok, thanks for the prompt reply, will try to look up the glu tessalation!!