Impl 1.2.4

This commit is contained in:
hodasemi 2018-10-17 13:00:47 +02:00
parent 213e4207dc
commit db5d8220fc
4 changed files with 45 additions and 17 deletions

1
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1 @@
{}

View file

@ -6,11 +6,14 @@
in vec4 in_position;
in vec4 in_color;
uniform mat4 view;
uniform mat4 proj;
out vec4 fragment_color;
void main()
{
gl_Position = in_position;
gl_Position = proj * view * in_position;
fragment_color = in_color;

View file

@ -35,6 +35,9 @@ private:
color_buffer_id, // ID of the color buffer
uv_map_buffer_id; // ID of the uv_map
GLint view_uniform_id;
GLint proj_uniform_id;
// Read, Compile and link the shader codes to a shader program
void CreateShaders();
// Create and define the vertex array and add a number of vertex buffers

View file

@ -23,6 +23,9 @@ Viewer::Viewer()
CreateShaders();
CreateVertexBuffers();
view_uniform_id = glGetUniformLocation(program_id, "view");
proj_uniform_id = glGetUniformLocation(program_id, "proj");
modelViewMatrix.setIdentity();
projectionMatrix.setIdentity();
@ -56,25 +59,40 @@ void Viewer::CreateVertexBuffers()
// Define 3 vertices for one face
GLfloat positions[] = {
0, 1, 0, 1,
-1, -1, 0, 1,
1, -1, 0, 1};
-1, 1, -1, 1,
1, -1, -1, 1,
1, 1, 1, 1,
-1, 1, -1, 1,
-1, -1, 1, 1,
1, -1, -1, 1,
-1, 1, -1, 1,
-1, -1, 1, 1,
1, 1, 1, 1,
1, -1, -1, 1,
1, 1, 1, 1,
-1, -1, 1, 1,
};
GLfloat colors[] = {
1,
0,
0,
1,
1, 0, 0, 1,
0, 1, 0, 1,
0, 0, 1, 1,
0,
1,
0,
1,
1, 0, 0, 1,
0, 1, 0, 1,
0, 0, 1, 1,
0,
0,
1,
1,
1, 0, 0, 1,
0, 1, 0, 1,
0, 0, 1, 1,
1, 0, 0, 1,
0, 1, 0, 1,
0, 0, 1, 1,
};
// Generate the vertex array
@ -234,10 +252,13 @@ void Viewer::drawContents()
then set them with the command glUniformMatrix4fv.
*/
glUniformMatrix4fv(view_uniform_id, 1, false, modelViewMatrix.data());
glUniformMatrix4fv(proj_uniform_id, 1, false, projectionMatrix.data());
// Bind the vertex array
glBindVertexArray(vertex_array_id);
// Draw the bound vertex array. Start at element 0 and draw 3 vertices
glDrawArrays(GL_TRIANGLES, 0, 3);
glDrawArrays(GL_TRIANGLES, 0, 12);
/*** End of task 1.2.4 (b) ***/