Hello, I am a beginner of OpenGL. I followed this page until Tutorial 6:

http://www.opengl-tutorial.org/beginner-tutorials/tutorial-6-keyboard-and-mouse/

I am trying to make it a voxel engine, my progress is here: https://github.com/gamedev8787/shaderhelp

In particular, I pass normals in the function createCube. To build, just do `mkdir build; cd build; cmake ..; make & # 39;

But when I run that, I have no shading or anything. Can someone take a look and advise? Many Thanks.

Ask shader:

```
#version 330 core
uniform vec3 LightPosition_worldspace;
uniform vec3 LightColor_worldspace;
out vec3 color;
in vec3 position_worldspace;
in vec3 normal_cameraspace;
in vec3 EyeDirection_cameraspace;
in vec3 LightDirection_cameraspace;
void main () {
/ *
float ambientStrength = 0.5f;
vec3 ambient = ambientStrength * LightColor_worldspace * objectColor;
Color = ambient light;
* /
vec3 LightColor = LightColor_worldspace;
vec3 Material Ambient Color = vec3 (0.5f, 0.8f, 0.31f);
vec3 Material DiffuseColor = vec3 (1.0f, 0.8f, 0.31f);
vec3 MaterialSpecularColor = vec3 (1,0f, 1,0f, 1,0f);
Swimming distance = length (LightPosition_worldspace - Position_worldspace);
vec3 n = normalize (normal_cameraspace);
vec3 l = normalize (LightDirection_cameraspace);
float cosTheta = clamp (point (n, l), 0,1);
vec3 E = normalize (EyeDirection_cameraspace);
vec3 R = reflect (-l, n);
Float cosAlpha = clamp (point (E, R), 0,1);
Color =
Material Ambient Color +
MaterialDiffuseColor * LightColor * cosTheta / (distance * distance) +
MaterialSpecularColor * LightColor * pow (cosAlpha, 5) / (distance * distance);
}
```

Vertex shader:

```
#version 330 core
// Input of vertex data that is different for all executions of this shatter.
Layout (location = 0) in vec3 vertexPosition_modelspace;
Layout (location = 1) in vec3 vertexNormal_modelspace;
// values that remain constant for the entire network.
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform vec3 LightPosition_worldspace;
out of vec3 position_worldspace;
out vec3 normal_cameraspace;
out vec3 EyeDirection_cameraspace;
out vec3 LightDirection_cameraspace;
void main () {
gl_position = P * V * M * vec4 (vertexPosition_modelspace, 1);
Position_worldspace = (M * vec4 (vertexPosition_modelspace, 1)). xyz;
vec3 vertexPosition_cameraspace = (V * M * vec4 (vertexPosition_modelspace, 1)). xyz;
EyeDirection_cameraspace = vec3 (0,0,0) - vertexPosition_cameraspace;
vec3 LightPosition_cameraspace = (V * vec4 (LightPosition_worldspace, 1)). xyz;
LightDirection_cameraspace = LightPosition_cameraspace + EyeDirection_cameraspace;
Normal_cameraspace = (V * M * vec4 (vertexNormal_modelspace, 0)). xyz; // Only correct if ModelMatrix does not scale the model! If not, use inverse transposition.
}
```

Create a cube

```
void Chunk :: createCube (GLfloat x, GLfloat y, GLfloat z) {
// Our vertices. Tree consecutive swimmers yield a 3D vertex; Three consecutive vertices result in a triangle.
// A cube has 6 faces, each with 2 triangles. This gives 6 * 2 = 12 triangles and 12 * 3 vertices
GLflat mx = float (x) + block :: BLOCK_RENDER_SIZE;
GLfloat my = float (y) + block :: BLOCK_RENDER_SIZE;
GLflat mz = float (z) + block :: BLOCK_RENDER_SIZE;
GLfloat arr[108] = {
x, y, z,
x, y, mz,
x, my, mz,
mx, my, z,
x, y, z,
x, my, z,
mx, y, mz,
x, y, z,
mx, y, z,
mx, my, z,
mx, y, z,
x, y, z,
x, y, z,
x, my, mz,
x, my, z,
mx, y, mz,
x, y, mz,
x, y, z,
x, my, mz,
x, y, mz,
mx, y, mz,
mx, my, mz,
mx, y, z,
mx, my, z,
mx, y, z,
mx, my, mz,
mx, y, mz,
mx, my, mz,
mx, my, z,
x, my, z,
mx, my, mz,
x, my, z,
x, my, mz,
mx, my, mz,
x, my, mz,
mx, y, mz
};
GLfloat n_arr[] = {
-100,
-100,
-100,
0, 0, -1,
0, 0, -1,
0, 0, -1,
0, -1, 0,
0, -1, 0,
0, -1, 0,
0, 0, -1,
0, 0, -1,
0, 0, -1,
-100,
-100,
-100,
0, -1, 0,
0, -1, 0,
0, -1, 0,
0, 0, 1,
0, 0, 1,
0, 0, 1,
100
100
100
100
100
100
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 0, 1,
0, 0, 1,
0, 0, 1
};
vertices.insert (vertices.end (), std :: begin (arr), std :: end (arr));
normals.insert (normals.end (), std :: begin (n_arr), std :: end (n_arr));
}
```

Transfer data to GPU

```
glEnableVertexAttribArray (0);
glBindBuffer (GL_ARRAY_BUFFER, m_vertexbuffer);
glVertexAttribPointer (
0, // attribute. No special reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE // normalized?
0, // step
(void *) 0 // array buffer offset
);
glDrawArrays (GL_TRIANGLES, 0, (vertices.size () / 3) * 3);
glDisableVertexAttribArray (attribute);
glEnableVertexAttribArray (1);
glBindBuffer (GL_ARRAY_BUFFER, m_normalbuffer);
glVertexAttribPointer (
1 // attribute. No special reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE // normalized?
0, // step
(void *) 0 // array buffer offset
);
glDisableVertexAttribArray (1);
`` `
```