# Moving Light

Hello

I just started programming a little bit in OpenGL.
I defined a light:

``````
GLfloat light0Position[] = {xLight1, 20.0, 20.0, 20.0}; // Position
glLightfv(GL_LIGHT1, GL_POSITION, light0Position);
GLfloat ambient0[]={0.2, 0.2, 0.2, 1.0}; // Farbdefinitionen
GLfloat diffuse0[]={0.9, 0.9, 0.9, 1.0};
GLfloat specular0[]={1.0,1.0, 1.0, 1.0};
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient0);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse0);
glLightfv(GL_LIGHT1, GL_SPECULAR, specular0);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);

``````

The thing i tried to do is to move this light through my scene.

``````void myOpenGL::moveLight(void){

xLicht1-=50;

}

``````

IÂ´m sorry but my english is maybe not so good

Define â€śnothing happensâ€ť. You donâ€™t see anything (screen is black)? You see lighting, but the light source isnâ€™t moving? etc.

``````
GLfloat light0Position[] = {xLight1, 20.0, 20.0, 20.0}; // Position
glLightfv(GL_LIGHT1, GL_POSITION, light0Position);
``````

Ok, so xLight1 is your X light source coordinate. Y=20, Z=20, â€¦ Why do you have W=20 as well? That should be 1.0 for a positional light.

Also, the first light source is LIGHT0, not LIGHT1. I donâ€™t know if youâ€™re already using LIGHT0 for something or not, but if not, Iâ€™d use LIGHT0. Should work either way, but then again, built-in light sources are legacy functionality.

Also, you may already realize this, but the MODELVIEW matrix that is active when you set your light source POSITION is used to transform the position to eye space. So make sure your MODELVIEW is set appropriately before you call the above.

``````  GLfloat specular0[]={1.0,1.0, 1.0, 1.0};
``````

I personally would reset these to 0.0 until you figure out whatâ€™s going on with your lighting.

Define â€śnothing happensâ€ť. You donâ€™t see anything (screen is black)? You see lighting, but the light source isnâ€™t moving?

I see my scene. As it should be. But if I start the function moveLight, the light doesnÂ´t move. What I want to say: The problem is I donÂ´t see the light moving.

Also, the first light source is LIGHT0, not LIGHT1. I donâ€™t know if youâ€™re already using LIGHT0 for something or not, but if not, Iâ€™d use LIGHT0. Should work either way, but then again, built-in light sources are legacy functionality.

LIGHT0 is defined.

What I want to do is moving the LIGHT1 from the left to the right.

your move function needs some improvements

``````
void myOpenGL::moveLight(void){
xLicht1-=50;
GLfloat light0Position[] = {xLight1, 20.0, 20.0, 20.0};
glLightfv(GL_LIGHT1, GL_POSITION, light0Position);
}

``````

hey thanks thats pretty cool and i tried to do some other simple animations with some objects and everything works fine

today i tried to move some objects arround just one imaginary point in the middle between of two objects. my objects are moving, but not around my point

here is the piece of code:

``````
glColor3f(0.0f, 1.0f, 1.0f);
glPushMatrix();
glScalef(0.5f, 0.5f, 0.5f);
glutSolidTetrahedron();
glPopMatrix();
glRotatef(winkel3,1.0f,0.0f,0.0f);
glPopMatrix();
glPushMatrix();
glScalef(0.5f, 0.5f, 0.5f);
glutSolidOctahedron();
glPopMatrix();
``````

where is my mistake?

try this

``````
glColor3f(0.0f, 1.0f, 1.0f);
glPushMatrix();
glScalef(0.5f, 0.5f, 0.5f);
glutSolidTetrahedron();
glPopMatrix();

//glPopMatrix(); one too many pop matrix, time to drink that jolt-cola

glPushMatrix();
glRotatef(winkel3,1.0f,0.0f,0.0f); //moved in here, might work?