Jump to content


opengl lights


11 replies to this topic

#1 starboarder2001

    Member

  • Members
  • PipPip
  • 35 posts

Posted 30 June 2003 - 07:35 PM

when i setup a opengl light and use gluLookAt(...) for my viewing transformations It seems that the light position is not effected by gluLookAt(...)?

sorry if this is a stupid question i am very new to opengl and c++.
1000
0100
0010
0001

#2 Noor

    Senior Member

  • Members
  • PipPipPipPip
  • 503 posts

Posted 30 June 2003 - 07:54 PM

did you do glEnable(GL_LIGHT0); ?
also, did you do: glEnable(GL_LIGHTING); ?
"What ever happened to happily ever after?"

#3 starboarder2001

    Member

  • Members
  • PipPip
  • 35 posts

Posted 30 June 2003 - 08:23 PM

the lighting is working...and i calculated the normals for all the polygons. The problem is that when i move the camera with gluLookAt() the light seems to move with the camera? if i set the light position at 0,10,0 when i move the camera to 0,0,-20 the light is now at 0,10,-20.

screenshots:

(Link Is Down):sigh:
1000
0100
0010
0001

#4 Noor

    Senior Member

  • Members
  • PipPipPipPip
  • 503 posts

Posted 30 June 2003 - 08:36 PM

i believe you need to set the position of the light using the glTranslatef() function instead of changing the light position. Try that and see if that works. Let me know about the results.
"What ever happened to happily ever after?"

#5 starboarder2001

    Member

  • Members
  • PipPip
  • 35 posts

Posted 30 June 2003 - 09:15 PM

this is what i am doing now:

//example1
float ambientlight[4]; //ambient light
float diffuselight[4]; //diffuse light
float specularlight[4]; //specular light
float lightposition[4]; //light position

//i would setup the 4 variables above here//

glLightfv(GL_LIGHT0,GL_AMBIENT,ambientlight);
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuselight);
glLightfv(GL_LIGHT0,GL_SPECULAR,specularlight);
glLightfv(GL_LIGHT0,GL_POSITION,lightposition);

glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION,0.9);
glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION,0.1);
glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION,0.1f);

glEnable(GL_LIGHT0);


this is what i tryed:

//example2
float ambientlight[4]; //ambient light
float diffuselight[4]; //diffuse light
float specularlight[4]; //specular light

//i would setup the 4 variables above here//

glPushMatrix();

glTranslatef(0,0,10);
glLightfv(GL_LIGHT0,GL_AMBIENT,ambientlight);
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuselight);
glLightfv(GL_LIGHT0,GL_SPECULAR,specularlight);
glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION,0.9);
glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION,0.1);
glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION,0.1f);
glEnable(GL_LIGHT0);

glPopMatrix();

Example 2 didnt work.. :sigh: can you give me a small example of how to setup a light using glTranslate(..);? are you shure that is how you can set the lights position?
1000
0100
0010
0001

#6 davepermen

    Senior Member

  • Members
  • PipPipPipPip
  • 1306 posts

Posted 30 June 2003 - 09:32 PM

use glLightfv(GL_LIGHT0,GL_POSITION,lightposition) as if you would draw a point.. means you possibly draw it at the moment it would just sit in front of your cam, without translation and rotation yet..


place the function where you draw the landscape..
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#7 Dia

    DevMaster Staff

  • Administrators
  • 1089 posts

Posted 30 June 2003 - 09:42 PM

Nice screenshots you have, btw :)

#8 starboarder2001

    Member

  • Members
  • PipPip
  • 35 posts

Posted 30 June 2003 - 09:50 PM

ok thanks i got it working :D
1000
0100
0010
0001

#9 Noor

    Senior Member

  • Members
  • PipPipPipPip
  • 503 posts

Posted 30 June 2003 - 10:21 PM

Good. Congratulation!


[EDIT]
yes, very nice screenshots!
[/EDIT]
"What ever happened to happily ever after?"

#10 davepermen

    Senior Member

  • Members
  • PipPipPipPip
  • 1306 posts

Posted 01 July 2003 - 04:14 AM

great!!

and to add to the screenshots: they are not only nice, but they where useful to detect the problem as well (if that really was the problem, of course:D)
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#11 dotanitis

    New Member

  • Members
  • Pip
  • 1 posts

Posted 24 June 2007 - 09:39 PM

Hello to all, (first post),

I have the same problem and could not find the answer. As was written again when i move the camera the light is also moves. my light code is:

glPushMatrix();
glLoadIdentity();

glDisable(GL_LIGHT0); // another light that i have
glEnable(GL_LIGHTING);

glEnable(GL_COLOR_MATERIAL);

GLfloat amb = 0.0f, dif = 2.0f;

GLfloat light_ambient[] = {amb, amb, amb};
GLfloat light_diffuse[] = {dif, dif, dif};
GLfloat light_specular[] = {0.0f, 0.0f, 0.0f};
GLfloat light_position[] = {m_nLightPosX, m_nLightPosY, m_nLightPosZ, 1.0f};

glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT1, GL_POSITION, light_position);

glEnable(GL_LIGHT1);

glPopMatrix();

Don't know what to do...

#12 Reedbeta

    DevMaster Staff

  • Administrators
  • 4777 posts
  • LocationBellevue, WA

Posted 24 June 2007 - 11:43 PM

You need to re-set the light position every frame, after you've set up your modelview matrix for the frame.

Also, this thread is from almost 4 years ago. It would be better if you had created a new thread for your question.
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users