I am new with OpenGL (~two months) ; I have a question concerning how lighting works, and more specifically, why I have a problem. I'll probably tell more than is needed, but I have no idea what is going wrong, so more is better than too little...
I have set up an openGL (no shaders, limited to ES) framework. Within that framework, I have been playing with a limited view of the solar system.
I have the sun (which contains a light in the center, which is not situated at the infinite), the earth (textured, orbiting and rotating on itself) and the moon (textured, orbiting around the earth.) I could add more, but that's not the point yet.
I have a standard viewing point, situated somewhere outside the solar system. I can view and rotate the planetary system and all looks OK, including lighting (i.e. I see that there is a dark side for earth, and that all places on earth (except the poles) get nights and days.
I can also positon my view point on the earth or on the moon (I did not really experiment much with the moon though), locally immobile ; from this view, I can change my viewing angles so that I can pretty much see everything there is to see from the ground. So I can see the sun (or moon) set up or down, or follow them in the sky. The earth texture is quite bad at that range (due to pixellation), but that could likely be solved with mipmapping later.
However, in that view, there is something that's not happening : I do not experiment the passing of night and days which I can see from outer space. There is no question that the model is the same (only the view position changes.) ; in case you wonder, I do reset the light position each frame, when I actually draw the sun.
Also, but this is more subjective, I feel the the moon is not correctly receiving light too when I am in that view point.
So my question is : what is going on, and why would lighting fail when my view point is on the planet rather that outer space...
Thanks for any answer!
Its is not quite clear what your problem is from the description, but 3d / openGL lighting is a massive discipline in itself, there are so many things that could be causing problems for you, there are tons of tutorials and information on the subject that is easily sourced online. You would be better posting a small informative portion of the code to illustrate your question,
Have you defined normals for your objects? are you using any GLUT out-of-the box primitives instead? have you defined and enabled your lights correctly? You have to understand that your planets will not be 'cast into shadow' by other objects unless you write shadow mapping or similar for the scene as well, their ' shadowed areas' will only come from the relative position of the light source per object portion in view , and not between objects.
If you are having trouble with the lighting then for clarity i would forget textures and strip your code right back to a simple fill version with lighting and rotation for two objects only.
I am definitely no expert on openGL, but it may be a good idea to post a couple of screenshots of the problem scenes, this may lend a very good insight to other more advanced openGL progammers here to help you.
For your information the openGL programming guide (which you can get for free - and is good quickreference ) contains a simple moon and planet example and is nice and short.
Thanks for the answer.
I believe I might fix the problem, because I've had time to make some progress.
There is likely a problem with the referential used when positionning the light.
The big view (the whole solar system) shows correctly. But the camera uses the basic referential, with a single translation and some rotations to move the view around.
The earth view obviously requires a modelview transform so that the camera can follow the scene and give the illusion of immobolity relatie to the earth.
However, I've lately been able to move my camera around (not just look around), and when I start in the earth referential then move away from the earth, I can see that the lighting is not correct, i.e. doesn't come from the sun. This is clear both on the earth and the moon, but that was not obvious while stuck on the ground.
So obviously, even though I believe I correctly reposition the light at each frame, this part of the code is likely wrong, i.e. I am probably not using the correct modelview matrix at that point, even though I do change it correctly later when I draw the sun.
I will not post images because the problem is only obvious dynamically. I can hardly post any code at all, first because that's not C++ but scala which is still confidential as a language, and because I'm building a framework ; there are shapes (which I build from scratch, not using any glu call ; actually, I'm not using glu or glut at all) that can be bound with local and global properties, movements that can be attached to shapes, cameras and so on) ; there is also a whole math library (quaternion most notably), but that was fully debugged.
Hence, OpenGL calls do not appear linearly in the code and one would have to read the whole framework to understand the logic.
For some time I was stuck with the stupid idea that beeing too close to the ground caused lighting problems...
Thanks for your help ; it put me on the right track when I started to take screenshots.
My properties were too smart; the position update was not sent to openGL because, locally, it was seen as constant (which it is in it's own referential!), and there usually is no need to send a command to openGL to say that the state doesn't actually change...
This scheme works well with most properties, but not with positions!