Lighting

I have added normals to my project, I am pretty sure they are added right, but my lighting is weird.

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.
(This thread way modified, the following 6 questions have nothing to do with my current question).

Normal is basically a vec4 of length 1 if i’m not mistaking. It is pointing to some kind of direction. Normal tells how direction certain triangle is facing, so you can do lighting operations.
Most modeling programs should be able to generate normals for you.

This basically calculates the normal for all vertices using surrounding vertices positions. This current code requires you to be storing your data in a VBO and rendering using an IBO with glDrawElements(…).

private void calcNormals(Vertex[] vertices, int[] indices)
	{
		for(int i = 0; i < indices.length; i += 3)
		{
			int i0 = indices[i];
			int i1 = indices[i + 1];
			int i2 = indices[i + 2];
			
			Vector3f v1 = vertices[i1].getPos().sub(vertices[i0].getPos());
			Vector3f v2 = vertices[i2].getPos().sub(vertices[i0].getPos());
			
			Vector3f normal = v1.cross(v2).normalized();
			
			vertices[i0].setNormal(vertices[i0].getNormal().add(normal));
			vertices[i1].setNormal(vertices[i1].getNormal().add(normal));
			vertices[i2].setNormal(vertices[i2].getNormal().add(normal));
		}
		
		for(int i = 0; i < vertices.length; i++)
			vertices[i].setNormal(vertices[i].getNormal().normalized());
	}

Code taken from: https://github.com/BennyQBD/3DGameEngine/blob/master/src/com/base/engine/Mesh.java

Maybe it would be worthy to note that I do not know what indices are. I realize that it is the plural of index though. I am am using VBO’s to store, but I am not using IBM’s to render

I want to be able to make normals for cubes made in openGL.

Well you just have to hard code them as you would hard code the vertices.

if you have a cube with length 1 edges centered around 0,0,0 coordinate, lets take a bottom face. Bottom face normal would be facing down. So the normal for bottom face is (0, -1, 0). The normal for up face would be (0, 1, 0). The normal for right face would be (1, 0, 0). The normal for front face would be (0, 0, -1). The normal for back face would be (0,0,1). This is all assuming that positive X is to the right, positive Y is up, positive Z is inside the screen(forwards through the screen).

Also, if you would change where the cube is located, the normals wouldn’t change. They would always be same same no matter where the cube is located.

I have updated the thread with another question.

Built-in OpenGL lighting sucks hard. It’s ancient. If you want to do anything decent you’ll want to use shaders. You’ll have no use at all for the stuff you’re doing now.