@@ -178,6 +178,26 @@ void initFullScreenQuad()
|
|
178
178
|
{
|
179
179
|
// Task 4.1
|
180
180
|
// ...
|
181
|
+
static const glm::vec2 positions[] = { { -1.0f, -1.0f }, { 1.0f, -1.0f }, { 1.0f, 1.0f },
|
182
|
+
{ -1.0f, -1.0f }, { 1.0f, 1.0f }, { -1.0f, 1.0f } };
|
183
|
+
GLuint positionBuffer;
|
184
|
+
glGenBuffers(1, &positionBuffer);
|
185
|
+
// Set the newly created buffer as the current one
|
186
|
+
glBindBuffer(GL_ARRAY_BUFFER, positionBuffer);
|
187
|
+
// Send the vertex position data to the current buffer
|
188
|
+
glBufferData(GL_ARRAY_BUFFER, labhelper::array_length(positions) * sizeof(glm::vec2), positions,
|
189
|
+
GL_STATIC_DRAW);
|
190
|
+
|
191
|
+
glGenVertexArrays(1, &fullScreenQuadVAO);
|
192
|
+
// Bind the vertex array object
|
193
|
+
// The following calls will affect this vertex array object.
|
194
|
+
glBindVertexArray(fullScreenQuadVAO);
|
195
|
+
// Makes positionBuffer the current array buffer for subsequent calls.
|
196
|
+
glBindBuffer(GL_ARRAY_BUFFER, positionBuffer);
|
197
|
+
// Attaches positionBuffer to fullScreenQuadVAO, in the 0th attribute location
|
198
|
+
glVertexAttribPointer(0, 2, GL_FLOAT, false /*normalized*/, 0 /*stride*/, 0 /*offset*/);
|
199
|
+
// Enable the vertex position attribute
|
200
|
+
glEnableVertexAttribArray(0);
|
181
201
|
}
|
182
202
|
}
|
183
203
|
|
@@ -191,6 +211,13 @@ void drawFullScreenQuad()
|
|
191
211
|
///////////////////////////////////////////////////////////////////////////
|
192
212
|
// Task 4.2
|
193
213
|
// ...
|
214
|
+
GLboolean previous_depth_state;
|
215
|
+
glGetBooleanv(GL_DEPTH_TEST, &previous_depth_state);
|
216
|
+
glDisable(GL_DEPTH_TEST);
|
217
|
+
glBindVertexArray(fullScreenQuadVAO);
|
218
|
+
glDrawArrays(GL_TRIANGLES, 0, 6);
|
219
|
+
if(previous_depth_state)
|
220
|
+
glEnable(GL_DEPTH_TEST);
|
194
221
|
}
|
195
222
|
|
196
223
|
|
@@ -350,6 +377,11 @@ void display(void)
|
|
350
377
|
// Task 4.3 - Render a fullscreen quad, to generate the background from the
|
351
378
|
// environment map.
|
352
379
|
///////////////////////////////////////////////////////////////////////////
|
380
|
+
glUseProgram(backgroundProgram);
|
381
|
+
labhelper::setUniformSlow(backgroundProgram, "environment_multiplier", environment_multiplier);
|
382
|
+
labhelper::setUniformSlow(backgroundProgram, "inv_PV", inverse(projectionMatrix * viewMatrix));
|
383
|
+
labhelper::setUniformSlow(backgroundProgram, "camera_pos", camera.position);
|
384
|
+
drawFullScreenQuad();
|
353
385
|
|
354
386
|
///////////////////////////////////////////////////////////////////////////
|
355
387
|
// Render the .obj models
|