LWJGL Forum

Programming => OpenGL => Topic started by: zFollette on January 12, 2014, 17:33:26

Title: Lighting
Post by: zFollette on January 12, 2014, 17:33:26
I have added normals to my project, I am pretty sure they are added right, but my lighting is weird.

(http://i1375.photobucket.com/albums/ag446/zFollette/Image_zps05297779.png)

The raised block is 0, 0, 0 and my light position is -1, 0, -1

Here is some code:

Normals:
float[] normalData = new float[]{
                            /*Front Normal*/
                            0, 0, 1,
                           
                            /*Back Normal*/
                            0, 0, -1,
                           
                            /*Left Normal*/
                            -1, 0, 0,
                           
                            /*Right Normal*/
                            1, 0, 0,
                           
                            /*Bottom Normal*/
                            0, -1, 0,
                           
                            /*Top Normal*/
                            0, 1, 0
                        };


They are in that order to correspond to the order in which I generate my faces.

Lighting:

glEnable(GL_LIGHTING);
            glEnable(GL_LIGHT0);
            glLight(GL_LIGHT0, GL_AMBIENT, compileBuffer(new float[]{1.5f, 1.5f, 1.5f, 1f}));
            glLight(GL_LIGHT0, GL_DIFFUSE, compileBuffer(new float[]{1.5f, 1.5f, 1.5f, 1f}));
            glLight(GL_LIGHT0, GL_POSITION, compileBuffer(new float[]{light.x, light.y, light.z, 1}));


Normals Rendering:
glBindBuffer(GL_ARRAY_BUFFER, normal);
        glNormalPointer(GL_FLOAT, 0, 0);


Normals Buffering:

glBindBuffer(GL_ARRAY_BUFFER, normal);
        glBufferData(GL_ARRAY_BUFFER, normalBuffer, GL_STATIC_DRAW);
        glBindBuffer(GL_ARRAY_BUFFER, 0);


I hope that somewhere along this chain of code is my problem.
Title: Re: Lighting
Post by: Fool Running on January 17, 2014, 13:54:37
If you're using shaders, make sure you are multiplying the normals by the correct matrix.
Have you tried moving the light around? What happens then?

Also your lighting color arrays look suspicious (new float[]{1.5f, 1.5f, 1.5f, 1f}). Unless you are doing HDR rendering, the float values should be in the range of 0 to 1.