Sign in to follow this  
sajis

OpenGL How to identify different light type

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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];

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Quote:
Original post by biraneto
May I ask you why don't you create an object for the light to keep track of its own properties?
OpenGL already has a light object. Caching the value in your own object is a premature optimisation.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by sybixsus
In this case, making a light object would be making things a whole lot easier.
But 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.
However, the former runs the risk of returning an invalid value, while the latter doesn't.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this