moving lights

Started by
2 comments, last by gcmonk 18 years, 9 months ago
I am currently learning OpenGL and I am starting on lighting. I made a scene with a heightfield terrain and can move around it with directional keys. I also placed a light using these commands in my initilization section and then render the map. When I move around though, it seems like the lighting changes, as if it's moving with me. I read somewhere that the lights are moved when you do translation and such. Is there a way I can make sure the lights are moved or am I doing this wrong?

  // this is in my init section of code
  GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  GLfloat mat_shininess[] = { 50.0 };
  GLfloat light_position[] = { 0.0, 1.0, 1.0, 1.0 };

  glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
  glLightfv(GL_LIGHT0, GL_POSITION, light_position);

  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);

// this is in my main loop
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);  
  glLoadIdentity();
  glRotatef(mAngleZ, 0.0f, 1.0f, 0.0f);
  glTranslatef(mX, mY, mZ);
  // renders the heightfield terrain
  mMap->Render();

:: site :: project ::
Advertisement
There was a thread about this about a week ago. You need to do your light transformations after your camera translations/rotations.
I've done a search using the terms, "opengl light moving" and "opengl lighting move" and can't seem to find it. Do you happen to have this thread handly so I can learn from it?
:: site :: project ::
Found the relevant thread after going through each page of thread in the OpenGl forum. ^_^ Here it is for anyone else who may encounter the problem.

http://www.gamedev.net/community/forums/topic.asp?topic_id=329426
:: site :: project ::

This topic is closed to new replies.

Advertisement