Domanda

enter image description here

in the picture you can see a white dote were the light source is positioned. The right object lights correctly but the left one does not.

GLfloat LightPosition[] = {0.0f,0.0f,1.0f,0.0};
void render()
{
    ::clearScreen(); // clear screen
    ::camera->update(); //changes matrix for camera

    glPushMatrix();
    glRotatef(x,0,1,0);
    glTranslatef(0,0,1);
    glBegin(GL_POINTS); // draw white dot
    glVertex3f(LightPosition[0],LightPosition[1],LightPosition[2]);
    glEnd();

    glLightfv (GL_LIGHT0,GL_POSITION,LightPosition); // position light
    ::glPopMatrix();

    ::m2->draw(); // draw king chess piece

    ::glPushMatrix();
    glTranslatef(4,0,0);
    m1->draw(); // draw sphere
    ::glPopMatrix();

    glFlush();
    glutSwapBuffers();
}

i understand that im just lighting up both objects as if the were in the center of the world and then im translating the object to the left causing this effect. How do i get around this and have my objects light correctly?

È stato utile?

Soluzione

Your light source doesn't have a position, it only has a direction and is therefore unaffected by translations. Plus, the vertex processor won't compute the direction from the source to the vertex for a directional light.

Set the w coordinate to 1 t have a point light:

GLfloat LightPosition[] = {0.0f,0.0f,1.0f,1.0};
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top