Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
171 user(s) are online (158 user(s) are browsing Forums)

Members: 1
Guests: 170

hlt, more...

Support us!

Headlines

 
  Register To Post  

OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Quite a regular
Quite a regular


See User information
Hi All,

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]; //RGBAAmbient color
  
float Intensity;
  
float Diffuse]; //RGBA Diffuse color
  
float Specular]; //RGBA Diffuse color
  
float Position]; // X /Y /Z Position of the light

struct LightSTRUCT{
  
int IsActive;
  
int IsHidden;
  
float XPosYPosZPosNullPos;
  
float RGBRRGBGRGBBNullRGB;
  
float Range;
  
int Type;
 };
struct LightSTRUCT Lights[8];


Here is the light update function :
void UpdateLightsvoid ){
  
int LLoop 0;
  
int CLight 0;
  
glLightfvGL_LIGHT0GL_AMBIENTAmbientLight.Ambient );
  
glLightfvGL_LIGHT0GL_DIFFUSEAmbientLight.Diffuse );
  
glLightfvGL_LIGHT0GL_SPECULARAmbientLight.Specular );
  
glLightfvGL_LIGHT0GL_POSITIONAmbientLight.Position );
//  glLightf( GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0f );
//  glLightf( GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0f);
//  glLightf( GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.00f );
  
glEnableGL_LIGHT0 );
  for ( 
LLoop 1LLoop 8LLoop++ ){
    switch( 
LLoop ){
      case 
CLight GL_LIGHT1; break;
      case 
CLight GL_LIGHT2; break;
      case 
CLight GL_LIGHT3; break;
      case 
CLight GL_LIGHT4; break;
      case 
CLight GL_LIGHT5; break;
      case 
CLight GL_LIGHT6; break;
      case 
CLight GL_LIGHT7; break;
     }
    if ( 
LightsLLoop ].IsActive == ){
      
glDisableCLight );
     }else{
      switch ( 
LightsLLoop ].Type ){
        case 
0:                                                               // Position Light;
          
glLightfvCLightGL_DIFFUSE, &LightsLLoop ].RGBR );
          
glLightfvCLightGL_AMBIENT, &AmbientLight.Ambient] );
          
glLightfvCLightGL_POSITION, &LightsLLoop ].XPos );
          
glLightfCLightGL_CONSTANT_ATTENUATION1.0f );
          
glLightfCLightGL_LINEAR_ATTENUATION0.2f);
          
glLightfCLightGL_QUADRATIC_ATTENUATION0.08f );
          break;
        case 
1:
          
glLightfvCLightGL_DIFFUSE, &LightsLLoop ].RGBR );
          
glLightfvCLightGL_AMBIENT, &AmbientLight.Ambient] );
          
glLightfvCLightGL_POSITION, &LightsLLoop ].XPos );
          
glLightfCLightGL_CONSTANT_ATTENUATION1.0f );
          
glLightfCLightGL_LINEAR_ATTENUATION0.0f);
          
glLightfCLightGL_QUADRATIC_ATTENUATION0.00f );
       }
      
glEnableCLight );
     }
   }
  
glEnableGL_LIGHTING );
 }


Of course here is how a light positionning is done:
void DEPositionLightint LightIDfloat XPosfloat YPosfloat ZPos ){
  if ( 
LightID == ){
    
AmbientLight.Position] = XPos;
    
AmbientLight.Position] = YPos;
    
AmbientLight.Position] = ZPos;
    
AmbientLight.Position] = 1.0f;  // w > 0 = position light
   
}else{
    if ( 
LightID ){
      if ( 
LightID ){
        
LightsLightID ].XPos XPos;
        
LightsLightID ].YPos YPos;
        
LightsLightID ].ZPos ZPos;
        
LightsLightID ].NullPos 1.0f;  // w > 0 = position light
       
}
     }
   }
 }

void DESetDirectionalLightint LightIDfloat NXfloat NYfloat NZ ){
  if ( 
LightID ){
    
int LExist DEGetLightExistLightID );
    if ( 
LExist == ){
      
LightsLightID ].XPos NX;
      
LightsLightID ].YPos NY;
      
LightsLightID ].ZPos NZ;
      
LightsLightID ].NullPos 0.0f;
      
LightsLightID ].Type 1;  // w = 0 directional light
     
}
   }else{
    
AmbientLight.Position] = NX;
    
AmbientLight.Position] = NY;
    
AmbientLight.Position] = NZ;
    
AmbientLight.Position] = 0.0f// w = 0 directional light
   
}
 }

It can setup Ambient light GL_LIGHT0 and all 7 other lights GL_LIGHTx

Lights from 1 to 7 work correctly when I activate them. but light 0 always seem to be spawn at position 0, 0, 0

Does someone has any clue ?

Regards,
Fred

All we have to decide is what to do with the time that is given to us.
Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Home away from home
Home away from home


See User information
@freddix

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

Join Kea Campus' Amiga Corner and support Amiga content creation
https://keasigmadelta.com/ - see more of my work
Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Quite a regular
Quite a regular


See User information
@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.
Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Not too shy to talk
Not too shy to talk


See User information
@freddix

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).

Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Quite a regular
Quite a regular


See User information
@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.
Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Not too shy to talk
Not too shy to talk


See User information
@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:
Resized Image

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(?)

Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Home away from home
Home away from home


See User information
@freddix

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.

Hans

Join Kea Campus' Amiga Corner and support Amiga content creation
https://keasigmadelta.com/ - see more of my work
Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Quite a regular
Quite a regular


See User information
@DAX
When I read the official OpenGL doc:
http://www.opengl.org/sdk/docs/man/xhtml/glLight.xml

It is not mentionned that Light0 cannot be set like other ones ...
So it should otherwise a warning concerning this may be mentioned in the doc...

I should maybe use LightModel ?
http://www.opengl.org/sdk/docs/man/xhtml/glLightModel.xml

Regards,
Fred

All we have to decide is what to do with the time that is given to us.
Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Not too shy to talk
Not too shy to talk


See User information
@freddix

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.

Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Quite a regular
Quite a regular


See User information
@DAX
I don't want a positional light !!

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.
Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Home away from home
Home away from home


See User information
@freddix

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

Join Kea Campus' Amiga Corner and support Amiga content creation
https://keasigmadelta.com/ - see more of my work
Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Quite a regular
Quite a regular


See User information
@Hans
Ok

I'll make more tests with this.

Regards,
Fred

All we have to decide is what to do with the time that is given to us.
Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Not too shy to talk
Not too shy to talk


See User information
@freddix
Ok.
Yet, terminology is quite out of whack wouldn't you agree (Directional has "no direction" but it does have "orientation" and so on... )

Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Quite a regular
Quite a regular


See User information
@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.
Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Home away from home
Home away from home


See User information
@freddix

Quote:

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.

Hans

Join Kea Campus' Amiga Corner and support Amiga content creation
https://keasigmadelta.com/ - see more of my work
Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Quite a regular
Quite a regular


See User information
@Hans
Light structure :
struct LightSTRUCT{
  
BOOL IsActive;
  
BOOL IsHidden;
  
float XPosYPosZPosNullPos;
  
float RGBRRGBGRGBBNullRGB;
  
float Range;
  
int Type;
 };
struct LightSTRUCT Lights[8];

Field NullPos replace the W pos.

Actual Update light function :
void UpdateLightsvoid ){
  
int LLoop 0;
  
int CLight 0;
  
glLightfvGL_LIGHT0GL_AMBIENTAmbientLight.Ambient );
  
glLightfvGL_LIGHT0GL_DIFFUSEAmbientLight.Diffuse );
  
glLightfvGL_LIGHT0GL_SPECULARAmbientLight.Specular );
  
glLightfvGL_LIGHT0GL_POSITIONAmbientLight.Position );
  
glEnableGL_LIGHT0 );
  for ( 
LLoop 1LLoop 8LLoop++ ){
    switch( 
LLoop ){
      case 
CLight GL_LIGHT1; break;
      case 
CLight GL_LIGHT2; break;
      case 
CLight GL_LIGHT3; break;
      case 
CLight GL_LIGHT4; break;
      case 
CLight GL_LIGHT5; break;
      case 
CLight GL_LIGHT6; break;
      case 
CLight GL_LIGHT7; break;
      default : 
CLight GL_LIGHT0; break;
     }
    if ( 
LightsLLoop ].IsActive == ){
      
glDisableCLight );
     }else{
      switch ( 
LightsLLoop ].Type ){
        case 
0:                                                               // Position Light;
          
glLightfvCLightGL_DIFFUSE, &LightsLLoop ].RGBR );
          
glLightfvCLightGL_AMBIENTAmbientLight.Ambient );
          
glLightfvCLightGL_POSITION, &LightsLLoop ].XPos );
          
glLightfCLightGL_LINEAR_ATTENUATION1.0f LightsLLoop ].Range );
          break;
        default:
          break;
       }
      
glEnableCLight );
     }
   }
  
glEnableGL_LIGHTING );
 }


and the position light/directional light :
void DEPositionLightint LightIDfloat XPosfloat YPosfloat ZPos ){
  if ( 
LightID == ){
    
AmbientLight.Position] = XPos;
    
AmbientLight.Position] = YPos;
    
AmbientLight.Position] = ZPos;
    
AmbientLight.Position] = 2.0;
   }else{
    if ( 
LightID ){
      if ( 
LightID ){
        
LightsLightID ].XPos XPos;
        
LightsLightID ].YPos YPos;
        
LightsLightID ].ZPos ZPos;
        
LightsLightID ].NullPos 2.0;
        
LightsLightID ].Type 0;
       }
     }
   }
 }
void DESetDirectionalLightint LightIDfloat NXfloat NYfloat NZ ){
  if ( 
LightID == ){
    
AmbientLight.Position] = NX;
    
AmbientLight.Position] = NY;
    
AmbientLight.Position] = NZ;
    
AmbientLight.Position] = 0.0f;
   }else{
    
int LExist DEGetLightExistLightID );
    if ( 
LExist == ){
      
LightsLightID ].XPos NX// * 999999;
      
LightsLightID ].YPos NY// * 999999;
      
LightsLightID ].ZPos NZ// * 999999;
      
LightsLightID ].NullPos 0.0f;
      
LightsLightID ].Type 1;
     }
   }
 }


I've modified for light 0 to test and see how it act :p

REgards,
Fred

All we have to decide is what to do with the time that is given to us.
Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Home away from home
Home away from home


See User information
@freddix

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

Join Kea Campus' Amiga Corner and support Amiga content creation
https://keasigmadelta.com/ - see more of my work
Go to top
Re: OpenGL - GL_LIGHT0 Vs GL_LIGHT( 1 - 7 ) ..
Quite a regular
Quite a regular


See User information
@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.
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 2 ( 0 members and 2 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project