Hello there,

I’m trying to implement lighting to my 3D rendering program. What I did is that I calculated face normals (I’m ok with flat shading because my program use only cubes for now), I stored this normals to VAO and I loaded it into glsl, did some calculations and when I compiled it the object on which light casted was colored with ambient color only. Here is some code:

```
static GLfloat g_normal_buffer_data[10000]; /*this is normal buffer I wont show how i filled it because I think it's irrelevant. I'm sure normals are calculated good. These data are calculated in different struct as my rendering stuff.*/
GLuint normalBuffer;
glGenBuffers(1, &normalBuffer);
glBindBuffer(GL_ARRAY_BUFFER, normalBuffer);
glBufferData(GL_ARRAY_BUFFER, 1, dataObject->initializeVertices(1) /*this returns normals*/, GL_STATIC_DRAW);
glEnableVertexAttribArray(2);
glBindBuffer(GL_ARRAY_BUFFER, normalBuffer);
glVertexAttribPointer
(
2,
3,
GL_FLOAT,
GL_FALSE,
0,
(void*)0
);/*this is in my game loop*/
//vShader
#version 330 core
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec3 color;
layout(location = 2) in vec3 normal;
out vec3 FragPos;
out vec3 Normal;
out vec3 fcolor;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
/*what I think is problem here is that face normals are only 10 * vec3(I'm rendering only 5 walls on a rectangle) and vertices are 30 * vec3 so every time it pushes new vertex to compute it pushes new face normal to compute so face normals are finished when 11th vertex starts to compute*/
gl_Position = projection * view * model * vec4(vertexPosition_modelspace, 1);
FragPos = vec3(model * vec4(vertexPosition_modelspace, 1.0));
Normal = mat3(transpose(inverse(model))) * normal;
fcolor = color; //object color
}
//fShader
#version 330 core
flat in vec3 fcolor;
flat in vec3 FragPos;
flat in vec3 Normal;
out vec4 color;
uniform vec3 lightColor;
uniform vec3 lightPos;
void main()
{
float ambientStrength = 0.1f;
vec3 ambient = ambientStrength * lightColor;
vec3 lightDir = normalize(lightPos - FragPos);
float diff = max(dot(Normal, lightDir), 0.0);
vec3 diffuse = diff * lightColor;
vec3 result = (ambient + diffuse) * fcolor;
color = vec4(result, 1.0f);
}
```

I really need help with this. I’m also attaching some screenshots so you can see.![Snímka|690x338]

PS: Could upload only 1 screenshot so I uploaded my face normals.

EDIT:

I wanted to check my normalBuffer directly so I did something like this:

```
glm::vec3 *dataPointer = new glm::vec3();
glGetNamedBufferSubData(normalBuffer, 0, sizeof(normalBuffer), dataPointer);
std::cout << "bufferX: " << dataPointer->x << std::endl;
std::cout << "bufferY: " << dataPointer->y << std::endl;
std::cout << "bufferZ: " << dataPointer->z << std::endl;
```

The output was 0 for every case so I think the problem might be in filling buffer with data