Add color array

This commit is contained in:
hodasemi 2018-10-17 10:55:20 +02:00
parent 4a2c752bc0
commit b7c5b93a31
3 changed files with 29 additions and 7 deletions

View file

@ -7,11 +7,9 @@ in vec4 fragment_color;
out vec4 color; out vec4 color;
void main() void main()
{ {
color = fragment_color * 0.5 + vec4(0.5); color = fragment_color;
/**** Begin of tasks *** /**** Begin of tasks ***
- 1.2.5 - 1.2.5

View file

@ -4,16 +4,15 @@
#version 130 #version 130
in vec4 in_position; in vec4 in_position;
in vec4 in_color;
out vec4 fragment_color; out vec4 fragment_color;
void main() void main()
{ {
gl_Position = in_position; gl_Position = in_position;
fragment_color = in_position;
fragment_color = in_color;
/* - 1.2.2 (b) /* - 1.2.2 (b)
* Declare a new "in" variable with the name "in_color". Instead of setting * Declare a new "in" variable with the name "in_color". Instead of setting

View file

@ -60,6 +60,23 @@ void Viewer::CreateVertexBuffers()
-1, -1, 0, 1, -1, -1, 0, 1,
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 // Generate the vertex array
glGenVertexArrays(1, &vertex_array_id); glGenVertexArrays(1, &vertex_array_id);
glBindVertexArray(vertex_array_id); glBindVertexArray(vertex_array_id);
@ -88,6 +105,14 @@ void Viewer::CreateVertexBuffers()
/*** End of task 1.2.2 (a) ***/ /*** 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 // Unbind the vertex array to leave OpenGL in a clean state
glBindVertexArray(0); glBindVertexArray(0);
} }