0
votes

I have a simple cube at (0,0,0) and a point of light at (10,0,0). For some reason both the right and left sides of my cube are illuminated. So opposite sides of the cube are lighting up. Im using blender to generate the normals so i know there correct, i also checked them manually and inverted them. but the result is the same.

Naturaly only the right side of the cube should be lighting up right?

GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_LIGHT0);  
GL11.glLightModeli(GL11.GL_LIGHT_MODEL_LOCAL_VIEWER, GL11.GL_TRUE); 
        //
GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, floatBuffer(new float[] {0.2f, 0.2f, 0.2f, 1.0f}));  
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, floatBuffer(new float[] {0.8f, 0.8f, 0.8f, 1.0f}));   
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, floatBuffer(new float[] {1.0f, 1.0f, 1.0f, 1.0f}));  
        //
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, floatBuffer(new float[] {10, 0, 0, 1}));         
    //
GL11.glEnable(GL11.GL_COLOR_MATERIAL);          
GL11.glColorMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE);

// i worked on it abit more, now i have a sphere, and every direction i look at it, it displays the exact same about of light. Shouldn't the back of the sphere opposite of the light source be dark like in real life?

// i took pictures but the site says i need 10 reputation points to post them :(.

1

1 Answers

0
votes

I found the problem. Theres a good explanation: here Problems with OpenGL lighting in Java/lwjgl
//
The Probelm was that i need to constantly set the light location in my render loop like this,,

public void render()
{
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, position));
}