diff --git a/exercise1/glsl/shader.frag b/exercise1/glsl/shader.frag index 5089dc0..f62db14 100644 --- a/exercise1/glsl/shader.frag +++ b/exercise1/glsl/shader.frag @@ -7,11 +7,9 @@ in vec4 fragment_color; out vec4 color; - - void main() { - color = fragment_color * 0.5 + vec4(0.5); + color = fragment_color; /**** Begin of tasks *** - 1.2.5 diff --git a/exercise1/glsl/shader.vert b/exercise1/glsl/shader.vert index 23a733b..d49c70c 100644 --- a/exercise1/glsl/shader.vert +++ b/exercise1/glsl/shader.vert @@ -4,16 +4,15 @@ #version 130 in vec4 in_position; +in vec4 in_color; out vec4 fragment_color; - - - void main() { gl_Position = in_position; - fragment_color = in_position; + + fragment_color = in_color; /* - 1.2.2 (b) * Declare a new "in" variable with the name "in_color". Instead of setting diff --git a/exercise1/src/Viewer.cpp b/exercise1/src/Viewer.cpp index 0cd0d1d..06e42b6 100644 --- a/exercise1/src/Viewer.cpp +++ b/exercise1/src/Viewer.cpp @@ -60,6 +60,23 @@ void Viewer::CreateVertexBuffers() -1, -1, 0, 1, 1, -1, 0, 1}; + GLfloat colors[] = { + 1, + 0, + 0, + 1, + + 0, + 1, + 0, + 1, + + 0, + 0, + 1, + 1, + }; + // Generate the vertex array glGenVertexArrays(1, &vertex_array_id); glBindVertexArray(vertex_array_id); @@ -88,6 +105,14 @@ void Viewer::CreateVertexBuffers() /*** End of task 1.2.2 (a) ***/ + glGenBuffers(1, &color_buffer_id); + glBindBuffer(GL_ARRAY_BUFFER, color_buffer_id); + glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW); + + GLuint cid = glGetAttribLocation(program_id, "in_color"); + glEnableVertexAttribArray(cid); + glVertexAttribPointer(cid, 4, GL_FLOAT, GL_FALSE, 0, 0); + // Unbind the vertex array to leave OpenGL in a clean state glBindVertexArray(0); }