Solution

Files changed (1) hide show
  1. lab1-rasterization/lab1_main.cpp +37 -0
lab1-rasterization/lab1_main.cpp CHANGED
@@ -31,6 +31,7 @@ glm::vec3 g_triangleColor = { 1, 1, 1 };
31
31
  // consists of positions (from positionBuffer) and color (from colorBuffer)
32
32
  // in this example.
33
33
  GLuint vertexArrayObject;
34
+ GLuint vertexArrayObject2;
34
35
 
35
36
  ///////////////////////////////////////////////////////////////////////////////
36
37
  // Shader programs
@@ -117,6 +118,40 @@ void initialize()
117
118
  //////////////////////////////////////////////////////////////////////////////
118
119
 
119
120
 
121
+ const float positions2[] = { 0.0f, 0.6f, 1.0f, // t0v0
122
+ 0.5f, 0.9f, 1.0f, // t0v1
123
+ -0.5f, 0.8f, 1.0f, // t0v2
124
+ 0.0f, 0.55f, 1.0f, // t1v0
125
+ 0.5f, 0.8f, 1.0f, // t1v1
126
+ 0.5f, -0.45f, 1.0f }; // t1v2
127
+
128
+ // Define the colors for each of the three points of the triangle
129
+ const float colors2[] = { 0.0f, 1.0f, 0.0f, // t0v0
130
+ 0.0f, 0.0f, 0.2f, // t0v1
131
+ 0.0f, 0.0f, 0.2f, // t0v2
132
+ 1.0f, 0.0f, 0.0f, // t1v0
133
+ 1.0f, 1.0f, 0.0f, // t1v1
134
+ 0.0f, 1.0f, 1.0f }; // t1v2
135
+
136
+ GLuint positionBuffer2;
137
+ glGenBuffers(1, &positionBuffer2);
138
+ glBindBuffer(GL_ARRAY_BUFFER, positionBuffer2);
139
+ glBufferData(GL_ARRAY_BUFFER, labhelper::array_length(positions2) * sizeof(float), positions2,
140
+ GL_STATIC_DRAW);
141
+
142
+ GLuint colorBuffer2;
143
+ glGenBuffers(1, &colorBuffer2);
144
+ glBindBuffer(GL_ARRAY_BUFFER, colorBuffer2);
145
+ glBufferData(GL_ARRAY_BUFFER, labhelper::array_length(colors2) * sizeof(float), colors2, GL_STATIC_DRAW);
146
+
147
+ glGenVertexArrays(1, &vertexArrayObject2);
148
+ glBindVertexArray(vertexArrayObject2);
149
+ glBindBuffer(GL_ARRAY_BUFFER, positionBuffer2);
150
+ glVertexAttribPointer(0, 3, GL_FLOAT, false /*normalized*/, 0 /*stride*/, 0 /*offset*/);
151
+ glBindBuffer(GL_ARRAY_BUFFER, colorBuffer2);
152
+ glVertexAttribPointer(1, 3, GL_FLOAT, false /*normalized*/, 0 /*stride*/, 0 /*offset*/);
153
+ glEnableVertexAttribArray(0); // Enable the vertex position attribute
154
+ glEnableVertexAttribArray(1); // Enable the vertex color attribute
120
155
 
121
156
  ///////////////////////////////////////////////////////////////////////////
122
157
  // Create shaders
@@ -229,6 +264,8 @@ void display(void)
229
264
 
230
265
  // Task 4: Render the second VAO
231
266
  // Task 5: Set the `triangleColor` uniform to white
267
+ glBindVertexArray(vertexArrayObject2);
268
+ glDrawArrays(GL_TRIANGLES, 0, 6);
232
269
 
233
270
  glUseProgram(0); // "unsets" the current shader program. Not really necessary.
234
271
  }