Jump to content
  • Advertisement
Sign in to follow this  
Garanti

OpenGL lighting set position help

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

edit: think it's fine now. I'm new to OpenGL/GLUT and can't figure out (or find an answer) how to make my light sit still (while another object is getting "animated"). What keeps happening is the light position gets transformed together with the object... I'd appreciate any kind of help in making the light static (with a way of changing its position independently). Thank you in advance. From my draw()
  glLoadIdentity();
    
  glTranslatef(g_fXOrig,g_fYOrig,g_fZOrig); //camera movement

  glLightfv(GL_LIGHT0,GL_AMBIENT,ambient);
  glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse);
  glLightfv(GL_LIGHT0,GL_POSITION,position);

  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glEnable(GL_COLOR_MATERIAL);

  glColor3f(C_R,C_G,C_B);
  glLineWidth(1.0);

  glPushMatrix();
    glTranslatef(g_fXOrig+0.5,g_fYOrig,g_fZOrig);
    glRotatef(angle,0.0,0.0,1.0);
    glutSolidCube(0.6);
  glPopMatrix();

  glFlush();
  glutSwapBuffers(); 
  angle++;
[Edited by - Garanti on January 24, 2009 4:27:19 PM]

Share this post


Link to post
Share on other sites
Advertisement
Instead of glMatrixMode(GL_PROJECTION) you mean glMatrixMode(GL_MODELVIEW), right?

When you set a light its position is transformed using the current modelview matrix which still seems to be the identity matrix. Changing the projection just changes how your object will be projected onto the screen. It is still in the same relative position to the light in world space.

Edit: Where's that glMatrixMode call? Figured it yourself? ;)

Share this post


Link to post
Share on other sites
Yes, I'm testing what I've messed up, lol. I think it works... uh, as always I was too fast to ask for help... Thanks, at least I'm reassured now. :D

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!