diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-02-17 13:28:50 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-02-17 13:28:50 -0500 |
commit | 6b99c7aee539e35b8e67520f36adeca9007641cb (patch) | |
tree | 7e265900e63512889109048047ee6a1b103c4339 /src/renderer.cpp | |
parent | 783b308990e7c4ef0837a102a138778f73e4d2b7 (diff) | |
download | therapy-6b99c7aee539e35b8e67520f36adeca9007641cb.tar.gz therapy-6b99c7aee539e35b8e67520f36adeca9007641cb.tar.bz2 therapy-6b99c7aee539e35b8e67520f36adeca9007641cb.zip |
Refactored map loader and added a second map
Also tweaked the font for apostrophe, p, and q
Diffstat (limited to 'src/renderer.cpp')
-rw-r--r-- | src/renderer.cpp | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/src/renderer.cpp b/src/renderer.cpp index 3011e8f..2ee0642 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp | |||
@@ -3,7 +3,7 @@ | |||
3 | #include <fstream> | 3 | #include <fstream> |
4 | #include <vector> | 4 | #include <vector> |
5 | #include <cstdio> | 5 | #include <cstdio> |
6 | #include "map.h" | 6 | #include "mapview.h" |
7 | 7 | ||
8 | static bool rendererInitialized = false; | 8 | static bool rendererInitialized = false; |
9 | 9 | ||
@@ -27,6 +27,12 @@ static GLuint scanlinesTex; | |||
27 | static GLuint preBloomTex; | 27 | static GLuint preBloomTex; |
28 | static GLuint bloomPassTex; | 28 | static GLuint bloomPassTex; |
29 | 29 | ||
30 | // The VAO | ||
31 | static GLuint VertexArrayID; | ||
32 | |||
33 | // A plane that fills the renderbuffer | ||
34 | static GLuint quad_vertexbuffer; | ||
35 | |||
30 | GLuint LoadShaders(const char* vertex_file_path, const char* fragment_file_path) | 36 | GLuint LoadShaders(const char* vertex_file_path, const char* fragment_file_path) |
31 | { | 37 | { |
32 | // Create the shaders | 38 | // Create the shaders |
@@ -221,7 +227,6 @@ GLFWwindow* initRenderer() | |||
221 | } | 227 | } |
222 | 228 | ||
223 | // Set up vertex array object | 229 | // Set up vertex array object |
224 | GLuint VertexArrayID; | ||
225 | glGenVertexArrays(1, &VertexArrayID); | 230 | glGenVertexArrays(1, &VertexArrayID); |
226 | glBindVertexArray(VertexArrayID); | 231 | glBindVertexArray(VertexArrayID); |
227 | 232 | ||
@@ -269,6 +274,20 @@ GLFWwindow* initRenderer() | |||
269 | 274 | ||
270 | curBuf = 0; | 275 | curBuf = 0; |
271 | 276 | ||
277 | // Load the vertices of a flat surface | ||
278 | GLfloat g_quad_vertex_buffer_data[] = { | ||
279 | -1.0f, -1.0f, 0.0f, | ||
280 | 1.0f, -1.0f, 0.0f, | ||
281 | -1.0f, 1.0f, 0.0f, | ||
282 | -1.0f, 1.0f, 0.0f, | ||
283 | 1.0f, -1.0f, 0.0f, | ||
284 | 1.0f, 1.0f, 0.0f, | ||
285 | }; | ||
286 | |||
287 | glGenBuffers(1, &quad_vertexbuffer); | ||
288 | glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); | ||
289 | glBufferData(GL_ARRAY_BUFFER, sizeof(g_quad_vertex_buffer_data), g_quad_vertex_buffer_data, GL_STATIC_DRAW); | ||
290 | |||
272 | artifactsTex = loadBMP_custom("../res/artifacts.bmp"); | 291 | artifactsTex = loadBMP_custom("../res/artifacts.bmp"); |
273 | scanlinesTex = loadBMP_custom("../res/scanlines.bmp"); | 292 | scanlinesTex = loadBMP_custom("../res/scanlines.bmp"); |
274 | 293 | ||
@@ -293,6 +312,9 @@ void destroyRenderer() | |||
293 | exit(-1); | 312 | exit(-1); |
294 | } | 313 | } |
295 | 314 | ||
315 | // Delete the plane buffer | ||
316 | glDeleteBuffers(1, &quad_vertexbuffer); | ||
317 | |||
296 | // Delete the shaders | 318 | // Delete the shaders |
297 | glDeleteProgram(ntscShader); | 319 | glDeleteProgram(ntscShader); |
298 | glDeleteProgram(finalShader); | 320 | glDeleteProgram(finalShader); |
@@ -312,6 +334,9 @@ void destroyRenderer() | |||
312 | // Delete the framebuffer | 334 | // Delete the framebuffer |
313 | glDeleteFramebuffers(1, &FramebufferName); | 335 | glDeleteFramebuffers(1, &FramebufferName); |
314 | 336 | ||
337 | // Delete the VAO | ||
338 | glDeleteVertexArrays(1, &VertexArrayID); | ||
339 | |||
315 | // Kill the window | 340 | // Kill the window |
316 | glfwTerminate(); | 341 | glfwTerminate(); |
317 | 342 | ||
@@ -569,23 +594,9 @@ void renderScreen(Texture* tex) | |||
569 | glUniform1i(glGetUniformLocation(ntscShader, "NTSCArtifactSampler"), 2); | 594 | glUniform1i(glGetUniformLocation(ntscShader, "NTSCArtifactSampler"), 2); |
570 | glUniform1f(glGetUniformLocation(ntscShader, "NTSCLerp"), curBuf * 1.0); | 595 | glUniform1f(glGetUniformLocation(ntscShader, "NTSCLerp"), curBuf * 1.0); |
571 | 596 | ||
572 | // Load the vertices of a flat surface | ||
573 | GLfloat g_quad_vertex_buffer_data[] = { | ||
574 | -1.0f, -1.0f, 0.0f, | ||
575 | 1.0f, -1.0f, 0.0f, | ||
576 | -1.0f, 1.0f, 0.0f, | ||
577 | -1.0f, 1.0f, 0.0f, | ||
578 | 1.0f, -1.0f, 0.0f, | ||
579 | 1.0f, 1.0f, 0.0f, | ||
580 | }; | ||
581 | |||
582 | GLuint quad_vertexbuffer; | ||
583 | glGenBuffers(1, &quad_vertexbuffer); | ||
584 | glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); | ||
585 | glBufferData(GL_ARRAY_BUFFER, sizeof(g_quad_vertex_buffer_data), g_quad_vertex_buffer_data, GL_STATIC_DRAW); | ||
586 | |||
587 | // Render our composition | 597 | // Render our composition |
588 | glEnableVertexAttribArray(0); | 598 | glEnableVertexAttribArray(0); |
599 | glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); | ||
589 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); | 600 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); |
590 | glDrawArrays(GL_TRIANGLES, 0, 6); | 601 | glDrawArrays(GL_TRIANGLES, 0, 6); |
591 | glDisableVertexAttribArray(0); | 602 | glDisableVertexAttribArray(0); |
@@ -694,7 +705,6 @@ void renderScreen(Texture* tex) | |||
694 | glfwSwapBuffers(window); | 705 | glfwSwapBuffers(window); |
695 | 706 | ||
696 | glDeleteBuffers(1, &g_norms); | 707 | glDeleteBuffers(1, &g_norms); |
697 | glDeleteBuffers(1, &quad_vertexbuffer); | ||
698 | 708 | ||
699 | curBuf = (curBuf + 1) % 2; | 709 | curBuf = (curBuf + 1) % 2; |
700 | } | 710 | } |