Jump to content
  • Advertisement
Sign in to follow this  
sajis

OpenGL How to identify different light type

This topic is 3419 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!