I try to setup light properties and want to be able for each lights to set it as "position" or "direction" light when user enter the correct function. I encounter a problem. Light 0 cannot be setup as "direction" light and , it does not take the position I want.
Here is the light definition :
struct AmbientLightStruct{
float Ambient[ 4 ]; //RGBAAmbient color
float Intensity;
float Diffuse[ 4 ]; //RGBA Diffuse color
float Specular[ 4 ]; //RGBA Diffuse color
float Position[ 4 ]; // X /Y /Z Position of the light
struct LightSTRUCT{
int IsActive;
int IsHidden;
float XPos, YPos, ZPos, NullPos;
float RGBR, RGBG, RGBB, NullRGB;
float Range;
int Type;
};
struct LightSTRUCT Lights[8];
Light 0 is generally used as the global light source. I'm not sure if the OpenGL specification says that it's hard-wired for that purpose or not. I thought that I read somewhere that it was, but I can't find it. Regardless, it sounds like it's been hardwired to be the global light source.
@Hans Yes, it's what I've read. GL_LIGHT0 is used for global, like simulating sun (directional light) but I can't modify its direction. it's not normal.
All we have to decide is what to do with the time that is given to us.
I don't know if it is related but in conventional 3D authoring programs (ie Lightwave, 3DS Max) the "global" light source (which is generally the default light source at start up) irradiates light in all directions and its not a directional light at all. Spot lights and others have an origin (X.y.Z. pos) and a direction, while that global light can only be moved in different positions (it is basically an omnidirectional light, you can also alter color and intensity but not direction).
@DAX Not exactly, in softwares like 3DSMax ... you can generally set the direction of the light even if the light is global. Because this global light is planed to simulate something similar to sun ...
All we have to decide is what to do with the time that is given to us.
@freddix I explained myself pretty badly ^__^. I'm an everyday 3DS Max user by the way so here is what I reckon in more detail: the default light in 3DS max (not an omnilight) is like a very distant light always aimed at the objects in the scene no matter how you rotate them. It is as if positioned in the viewer eyes, no matter how you rotate, animate or position your objects they will always be illuminated directly (good for modeling).
As soon as you place your own lights, the default one gets deactivated.
Some of the lights at your disposal are "target" lights and they do have a direction parameter.
Others like "omni" have no direction whatsoever (they irradiate in all directions and you cannot change this behavior)
OMNI_Light shown below:
I wonder if the default global light you are talking about can be effectively "directed" or maybe the best course of action would be to just deactivate it and add true directional lights(?)
By definition the global light source is what we call an "infinite" light source, that means that the light is so far away that its rays are parallel, and hit all objects from the same angle. This means that you can change that angle by moving the light source's position, but you cannot specify a direction on top of that. Think of the way that lighting changes when the sun moves from east to west.
Indeed they should specify in the documentation something as important as GL_LIGHT0 being a "particular" kind of light that is hardwired to a single usage (maybe the documentation should be revised or something).
On terminology:
I digged out Beginning OpenGL game programming (book) and the description of lights is rather ambiguous (or at least the choice of "terminology" could be debatable to a certain extent) as a Directional light is what Hans has described above as an "infinite" light source, while a "positional light" is what you were looking for (O_o).
Positional lights it says, take in consideration a direction vector between the light source and the object surface while for "directional lights" the direction is the same for every surface (always hit by light rays with the same parallel direction no matter how you manipulate them).
Anyway, since Light_0 is hardwired to the default behavior (which is what the book calls Directional Lights), it cannot be used otherwise it would seem.
The directional light is exactly what the term tell you don' t have a position but you have an orientation that will be the same for each objects all ray light will be parallell and came from an infinite position And you can, using X, Y, Z define the vector of orientation of the light 0
Position light does not have this notion of orientation because it enlight all objects in all directions.
GL_LIGHT 0 is directional light ... and then it should handle the vector of direction. Many openGL samples uses that ...
All we have to decide is what to do with the time that is given to us.
I've had a look at your code, and I can't see why it wouldn't work. Do note that you've forgotten to set light 1-7's type to 0 in your DEPositionLight() function. You also don't need to add the ambient light value to all lights, this just results in amplifying your ambient lighting by the number of enabled lights.
I've also had a look at the MiniGL source-code, and I don't see any special treatment for light 0 at all.
@Hans it's handled by the DEPositionLightEx() itself
if user use DEPositionLightEx(), it will set it as position light (set w = 0 ) if the user use DESetDirectionalLightEx(), it will set the light as directional ( set w> 1 ) so no need to add this as a parameter.
@DAX: Lol ...
All we have to decide is what to do with the time that is given to us.
freddix wrote: @Hans it's handled by the DEPositionLightEx() itself
if user use DEPositionLightEx(), it will set it as position light (set w = 0 ) if the user use DESetDirectionalLightEx(), it will set the light as directional ( set w> 1 ) so no need to add this as a parameter.
????? I'm talking about the Type field in LightSTRUCT, not adding parameters. Your UpdateLighting() function uses it to decide how to set up certain lighting parameters. You are enabling that flag in DESetDirectionalLightEx(), and not disabling it again in DEPositionLightEx(). That could result in your lighting update function doing the wrong thing depending on what order functions are called in. Personally I think that the Type field is redundant, but if it's there, then you should make sure that it's updated properly.
One other thing, you may wish to double-check this in the OpenGL specifications, but I'm pretty sure that you can assume that GL_LIGHTn = GL_LIGHT0 + n
Using this you can eliminate the switch statement in UpdateLights().
@Hans It's something I seem to have seen in some tutorials ... but didn't tried ... I prefered use something I'm sure it should work until lights command work perfectly .. After I'll optimise with things like this one ;)
Thank you Hans.
Regards, Fred
All we have to decide is what to do with the time that is given to us.