Code and content re-work: advanced OpenGL and advanced lighting.

This commit is contained in:
Joey de Vries
2017-06-01 22:04:34 +02:00
parent 49d8d895ae
commit f844f7c541
32 changed files with 184 additions and 144 deletions

View File

@@ -120,7 +120,7 @@ int main()
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, amount * sizeof(glm::mat4), &modelMatrices[0], GL_STATIC_DRAW);
// Set transformation matrices as an instance vertex attribute (with divisor 1)
// set transformation matrices as an instance vertex attribute (with divisor 1)
// note: we're cheating a little by taking the, now publicly declared, VAO of the model's mesh(es) and adding new vertexAttribPointers
// normally you'd want to do this in a more organized fashion, but for learning purposes this will do.
// -----------------------------------------------------------------------------------------------------------------------------------
@@ -128,7 +128,7 @@ int main()
{
unsigned int VAO = rock.meshes[i].VAO;
glBindVertexArray(VAO);
// Set attribute pointers for matrix (4 times vec4)
// set attribute pointers for matrix (4 times vec4)
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)0);
glEnableVertexAttribArray(4);

View File

@@ -7,5 +7,5 @@ uniform mat4 projection;
void main()
{
gl_Position = projection * view * model * vec4(aPos, 1.0f);
gl_Position = projection * view * model * vec4(aPos, 1.0);
}

View File

@@ -72,8 +72,8 @@ int main()
// build and compile shaders
// -------------------------
Shader shader("11.1.anti_aliasing.vs", "11.1.anti_aliasing.fs");
Shader screenShader("11.2.aa_post.vs", "11.2.aa_post.fs");
Shader shader("11.anti_aliasing.vs", "11.anti_aliasing.fs");
Shader screenShader("11.aa_post.vs", "11.aa_post.fs");
// set up vertex data (and buffer(s)) and configure vertex attributes
// ------------------------------------------------------------------

View File

@@ -11,16 +11,16 @@ out vec3 fColor;
void build_house(vec4 position)
{
fColor = gs_in[0].color; // gs_in[0] since there's only one input vertex
gl_Position = position + vec4(-0.2f, -0.2f, 0.0f, 0.0f); // 1:bottom-left
gl_Position = position + vec4(-0.2, -0.2, 0.0, 0.0); // 1:bottom-left
EmitVertex();
gl_Position = position + vec4( 0.2f, -0.2f, 0.0f, 0.0f); // 2:bottom-right
gl_Position = position + vec4( 0.2, -0.2, 0.0, 0.0); // 2:bottom-right
EmitVertex();
gl_Position = position + vec4(-0.2f, 0.2f, 0.0f, 0.0f); // 3:top-left
gl_Position = position + vec4(-0.2, 0.2, 0.0, 0.0); // 3:top-left
EmitVertex();
gl_Position = position + vec4( 0.2f, 0.2f, 0.0f, 0.0f); // 4:top-right
gl_Position = position + vec4( 0.2, 0.2, 0.0, 0.0); // 4:top-right
EmitVertex();
gl_Position = position + vec4( 0.0f, 0.4f, 0.0f, 0.0f); // 5:top
fColor = vec3(1.0f, 1.0f, 1.0f);
gl_Position = position + vec4( 0.0, 0.4, 0.0, 0.0); // 5:top
fColor = vec3(1.0, 1.0, 1.0);
EmitVertex();
EndPrimitive();
}

View File

@@ -12,9 +12,9 @@ uniform float time;
vec4 explode(vec4 position, vec3 normal)
{
float magnitude = 2.0f;
vec3 direction = normal * ((sin(time) + 1.0f) / 2.0f) * magnitude;
return position + vec4(direction, 0.0f);
float magnitude = 2.0;
vec3 direction = normal * ((sin(time) + 1.0) / 2.0) * magnitude;
return position + vec4(direction, 0.0);
}
vec3 GetNormal()

View File

@@ -11,5 +11,5 @@ uniform mat4 model;
void main()
{
TexCoords = aTexCoords;
gl_Position = projection * view * model * vec4(aPos, 1.0f);
gl_Position = projection * view * model * vec4(aPos, 1.0);
}

View File

@@ -19,7 +19,7 @@ void GenerateLine(int index)
void main()
{
GenerateLine(0); // First vertex normal
GenerateLine(1); // Second vertex normal
GenerateLine(2); // Third vertex normal
GenerateLine(0); // first vertex normal
GenerateLine(1); // second vertex normal
GenerateLine(2); // third vertex normal
}