OpenGL lighting issues

Started by
6 comments, last by Auron 19 years, 9 months ago
In my OpenGL code, I created a light, but I'm unable to see it. Do I have to have an object for the light to reflect off of? Or can I just see the light anyway? Thanks in advance! Here's my code, at least, the part that creates the light.

        GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
	GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };

	glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
	glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);

Advertisement
did you:

glEnable(GL_LIGHT0);

?

you should also take a look at the chapter on lighting in the openGL red book:
http://fly.cc.fer.hr/~unreal/theredbook/

-me
Yes, I did enable the lights, and all that jazz. I already checked the 'Red Book'. Does anyone have a working snippet of code that creates a visible light?
You need an object, of course. Without anything to reflect from, of course you won't be able to see it!

OpenGL's lighting model is very simplified and really not much like light in real life. A "light" is an abstract sort of thing, not an object in itself, but a part of a calculation used to determine the colors applied to other objects.
Okay, I understand now. But the book Beginning OpenGL Game Programming made it seem as if you could have visible light by itself. You say that OpenGL lighting system is not true to the real world. How else would I get lighting in my game?
What's he is trying to say is this is Light in Open Gl are In Abstract Form, so what they basuily do is apply a certain amout of lighting on object on your scene and based on that amout it reflect on your objects
Quote:Original post by CodeTitan
Okay, I understand now. But the book Beginning OpenGL Game Programming made it seem as if you could have visible light by itself. You say that OpenGL lighting system is not true to the real world. How else would I get lighting in my game?

If you want realistic lighting, you'd have to write your own vertex and fragment programs to do it. But that's an advanced topic, and the standard lighting system is a serviceable approximation with excellent performance. Don't worry about it too much. [grin]

Of course, if you're content with your lighting being completely static, the typical solution is to perform very accurate lighting calculations on your geometry beforehand, and then export the results as "light map" textures that can be blended with your color textures. That way, you can have game levels that look perfectly realistic with nice shadows and everything, but the light sources in the level itself can't move. That's the solution used by pretty much every 3D game in the past several years, and we're only just now getting games with seriously dynamic lighting and shadows done with vertex programs.
Unless I'm really wrong here (and I've been known to be), CodeTitan is looking for a lamp, not just a light source. OpenGL's lighting scheme does abstract lights because it makes way more sense. Lamps would require geometry and usually some extra optical effects, which is inefficient and more often than not undesired.

What you need to do is create your "lamp" as geometry of some sort and give it an emissive material (look up materials, it'll explain how to do it) then place your light at the same place and pointing in the desired direction. It won't be a stunning effect but it will give you what you want.

-Auron

This topic is closed to new replies.

Advertisement