Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Gandalf

OpenGL Please help me with a OpenGL Light Problem!

This topic is 6605 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

Help! I try to implement a spotlight in a simple OpenGL application. The light is located at (0,0,0). The objects is 15 units away from the lightsource (0,0,-15). There is no light! Everything is almost black. Maybe the range is incorrect. //////////////////// CODE SECTION START ///////////(///////////////////////////////////// GLfloat LightDirection[] = { 0.00f, 0.00f, 1.00f, 0.0f }; //last value toggle dir/pos on off GLfloat LightPosition[] = { 0.00f, 0.00f, 0.00f, 1.0f }; //last value toggle dir/pos on off // Set position glLightfv(GL_LIGHT0, GL_POSITION, LightPosition); // Set direction glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, LightDirection); // Set spread angle glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, (g_PI/8)*g_RADTODEG); // Set intensity. Higher value = more focus ? glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, ((g_PI/8)/2)*g_RADTODEG); // Set attenuation. Here im not sure what I´m doing! glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0f); glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0f); glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0f); //////////////////// CODE SECTION END ///////////(///////////////////////////////////// If somebody have succeded to add a spotlight to a scene, please show me some code how to do it! Here is a list on things I already have tried: * Moving x,y,z position up and down. * Used GL_SPOT_DIRECTION to set position (with 4:th value set to 1). * Changed spread angle to almost everything. * Raised/decreased attenuation params without any effect. I''m thinking of commit suicide soon! This driving me crasy! It´s easy in both RM and IM. Gandalf the White

Share this post


Link to post
Share on other sites
Advertisement
Hi Gandalf,
please don''t commit suicide. I haven''t used spotlights yet. But the things I often did wrong was enabling the lightng AND enabling the light I used. glEnable(GL_LIGHT0); in your case.

Share this post


Link to post
Share on other sites
But that is probaly not the reason... or?

What´s wrong with enable both glLighting() and glEnable(GL_LIGHT0) ?

Gandalf the White

Share this post


Link to post
Share on other sites
quote:
Original post by The Mummy

Hi Gandalf,
please don''t commit suicide. I haven''t used spotlights yet. But the things I often did wrong was enabling the lightng AND enabling the light I used. glEnable(GL_LIGHT0); in your case.



Actually, you MUST enable both, because you can have lighting enabled, but some specific light disabled (GL_LIGHT0 or GL_LIGHT4 for example); And you can also want to disable all lights simply calling glDisable(GL_LIGHTING).

Gandalf The Grey, I think that the problem might be your LightPosition array: when you set a directional light, the last value must be 0, and for a positional light, it must be 1. A directional light is a light that''s very far away (like the sun), so its rays are perpendicular from each other. You specify only its direction in space, using the first 3 values of the array, and the last one must be 0 to tell OpenGL that it''s an directional light. A positional light is a light that is close to your scene, so its rays don''t hit the objects perpendiculary. You specify its position in space using the first 3 values of the array, and set the last to 1. Sorry for the bad explanation, but I always been a bad explanator.

Hope that helps,

Nicodemus.

----
"When everything goes well, something will go wrong." - Murphy

Share this post


Link to post
Share on other sites
quote:
Original post by The Mummy

Hi Gandalf,
please don''t commit suicide. I haven''t used spotlights yet. But the things I often did wrong was enabling the lighting AND enabling the light I used. glendale(GL_LIGHT0); in your case.



Actually, you MUST enable both, because you can have lighting enabled, but some specific light disabled (GL_LIGHT0 or GL_LIGHT4 for example); And you can also want to disable all lights simply calling glDisable(GL_LIGHTING).

Gandalf The Grey, I think that the problem might be your LightPosition array: when you set a directional light, the last value must be 0, and for a positional light, it must be 1. A directional light is a light that''s very far away (like the Sun), so its rays are (practically) perpendicular to each other. You specify only its direction in space, using the first 3 values of the array, and the last one must be 0 to tell OpenGL that it''s an directional light. A positional light is a light that is close to your scene (like a lamp), so its rays don''t hit the objects perpendicularly. You specify its position in space using the first 3 values of the array, and set the last to 1. Sorry for the bad explanation, but I always been a bad explanator.

Hope that helps,

Nicodemus.

----
"When everything goes well, something will go wrong." - Murphy

Share this post


Link to post
Share on other sites
Sorry Gandalf I made a mistake above! I wanted to say that you have to enable both. Sorry, I told you that, because I did that wrong when I tried OpenGL lights.

Edited by - TheMummy on June 17, 2000 3:52:04 AM

Share this post


Link to post
Share on other sites

  • 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!