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
Please help me with a OpenGL Light Problem!
your target meshes probably have a low vertex count on them - openGL does a per-vertex lighting, meaning each vertex is coloured, not pixel. increase the density of the meshes and it shouls work.
// Set intensity. Higher value = more focus ?
no, just a brighter color for a longer distance
this might help (i''m not promising)
CJ
// Set intensity. Higher value = more focus ?
no, just a brighter color for a longer distance
this might help (i''m not promising)
CJ
But if I decrease the spotlight cone (glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, (g_PI/8)*g_RADTODEG)) then all objects outside the the cone should bee compleatly dark, because I only use one light. This effekt does not show up in my program and that´s why I´m not happy yet.
What other things can be wrong?
Edited by - Gandalf on June 16, 2000 3:40:47 AM
What other things can be wrong?
Edited by - Gandalf on June 16, 2000 3:40:47 AM
Hi,
this is some code from my last app where spotlight is ok :
GLfloat light1_position[]={-0.5f, 0.7f, +0.6f, 0.0};
GLfloat spot_direction[]={1.0,1.0,1.0};
....
.....
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);
.....
glLightfv(GL_LIGHT1, GL_POSITION,light1_position);
glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION,1.5);
glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION,0.5);
glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION,0.2f);
glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,180);
glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,spot_direction);
glLightf(GL_LIGHT1,GL_SPOT_EXPONENT,2.0);
hope that help
lunasol
this is some code from my last app where spotlight is ok :
GLfloat light1_position[]={-0.5f, 0.7f, +0.6f, 0.0};
GLfloat spot_direction[]={1.0,1.0,1.0};
....
.....
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);
.....
glLightfv(GL_LIGHT1, GL_POSITION,light1_position);
glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION,1.5);
glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION,0.5);
glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION,0.2f);
glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,180);
glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,spot_direction);
glLightf(GL_LIGHT1,GL_SPOT_EXPONENT,2.0);
hope that help
lunasol
That works becuase you are setting GL_SPOT_CUTOFF to 180 degree witch means you are not using spotlights at all. Sorry, but that is not what I want.
Gandalf the White
Gandalf the White
Shouldn''t the direction of the spotlight be pointing to the screen instead of pointing to you (positive Z-axis)?
You say :
GLfloat LightDirection[] = { 0.00f, 0.00f, 1.00f, 0.0f };
When the spot is at (0,0,0) and the object is at (0,0,-15), the
spot should point to the negative Z-axis.
Hope this helps.
Tatum
You say :
GLfloat LightDirection[] = { 0.00f, 0.00f, 1.00f, 0.0f };
When the spot is at (0,0,0) and the object is at (0,0,-15), the
spot should point to the negative Z-axis.
Hope this helps.
Tatum
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement