Jump to content
  • Advertisement
Sign in to follow this  
braineater1988

OpenGL Making the light to stay fixed as player moves

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

Hi I've been learning OpenGL in the past few days (I'm using AllegroGL). I've really been having trouble with having the light to NOT move with the player. Whatever I try, I am not able to correctly do it. I'm trying to do it for a directional light(w=0). I've put my code from the redraw function here. Can anyone see any evident problems?? =============================================== GLfloat position[]={0, -1, -1, 0}; glLoadIdentity(); glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 240.0); allegro_gl_apply_quat(&camera.orientation); glTranslatef(-camera.position.x, -camera.position.y, -camera.position.z); glBindTexture(GL_TEXTURE_2D, texture); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //Just applying the transformations to the light separately, for trial and error glPushMatrix(); glLoadIdentity(); allegro_gl_apply_quat(&tmp); //glTranslatef(-camera.position.x, -camera.position.y, -camera.position.z); glLightfv(GL_LIGHT1, GL_POSITION, position); glPopMatrix(); glBegin(GL_QUADS); ... ... glEnd(); /* Flip the backbuffer on screen */ allegro_gl_flip();

Share this post


Link to post
Share on other sites
Advertisement
I know what your talking about, it has to with where your setting the lights position.

Try this...

try putting
" glLightfv(GL_LIGHT1, GL_POSITION, position);"

either directly before or after you set your "camera"(i forgot witch):
allegro_gl_apply_quat(&camera.orientation);
glTranslatef(-camera.position.x, -camera.position.y, -camera.position.z);

like this:

allegro_gl_apply_quat(&camera.orientation);
glTranslatef(-camera.position.x, -camera.position.y, -camera.position.z);
glLightfv(GL_LIGHT1, GL_POSITION, position);

or

glLightfv(GL_LIGHT1, GL_POSITION, position);
allegro_gl_apply_quat(&camera.orientation);
glTranslatef(-camera.position.x, -camera.position.y, -camera.position.z);


tell me if that did it.

Share this post


Link to post
Share on other sites
Hi

Well, my code started working just before i saw your reply. The problem was that i was setting the frustum in the modelview matrix rather than the projection matrix.

Also, this:
allegro_gl_apply_quat(&camera.orientation);
glTranslatef(-camera.position.x, -camera.position.y, -camera.position.z);
glLightfv(GL_LIGHT1, GL_POSITION, position);
is the right way to do it.

Thanks for your reply.

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!