How to identify different light type
Hello forum,
I have a single light light source and that light can be changed to different type based on
user interaction - Point, Spot Or Directional Light Source.
Is there any OpenGL function that query into the current active light and find out its type.
Thanks
Sajjad
Use glGetLight
If position.w is 0, you have a directional light.
If spot_cutoff is 180 you have a point light.
Otherwise you have a spotlight.
If position.w is 0, you have a directional light.
If spot_cutoff is 180 you have a point light.
Otherwise you have a spotlight.
Thanks
***********************************'
GLfloat lightParam = 0;
if(glIsEnabled(GL_LIGHTING))
{
if(glIsEnabled(GL_LIGHT0))
glGetLightfv(GL_LIGHT0,GL_POSITION,lightParam);
}
***********************************
The above code is giving me a segmentation fault.
Any Idea?
Regards
Sajjad
***********************************'
GLfloat lightParam = 0;
if(glIsEnabled(GL_LIGHTING))
{
if(glIsEnabled(GL_LIGHT0))
glGetLightfv(GL_LIGHT0,GL_POSITION,lightParam);
}
***********************************
The above code is giving me a segmentation fault.
Any Idea?
Regards
Sajjad
Quote:Original post by sajis
Thanks
***********************************'
GLfloat lightParam = 0;
if(glIsEnabled(GL_LIGHTING))
{
if(glIsEnabled(GL_LIGHT0))
glGetLightfv(GL_LIGHT0,GL_POSITION,lightParam);
}
***********************************
The above code is giving me a segmentation fault.
Any Idea?
Regards
Sajjad
try GLfloat lightParama[4];
Are you really going to query for the light every time you need it? And you have a single light? May I ask you why don't you create an object for the light to keep track of its own properties?
Quote:Original post by biranetoOpenGL already has a light object. Caching the value in your own object is a premature optimisation.
May I ask you why don't you create an object for the light to keep track of its own properties?
Quote:Original post by HodgmanOpenGL already has a light object. Caching the value in your own object is a premature optimisation.
An optimization is something you do to make things work faster. In this case, making a light object would be making things a whole lot easier. The fact that it might also improve performance is not the reason it is being proposed.
Exactly. Go back to the second post and read it.
>If position.w is 0, you have a directional light.
>If spot_cutoff is 180 you have a point light.
>Otherwise you have a spotlight.
This is insane. He could just keep a byte value, a char or whatever to avoid going into an insane piece of code.
>If position.w is 0, you have a directional light.
>If spot_cutoff is 180 you have a point light.
>Otherwise you have a spotlight.
This is insane. He could just keep a byte value, a char or whatever to avoid going into an insane piece of code.
Quote:Original post by sybixsusBut a light object who's "GetLightType" method uses a cached enum/byte would be exactly as easy to use as a light object that uses an if/elseif/else approach.
In this case, making a light object would be making things a whole lot easier.
However, the former runs the risk of returning an invalid value, while the latter doesn't.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement