summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2015-02-23 10:49:56 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2015-02-23 10:49:56 -0500
commit0751446e1d069263d25abcff49a32a380231709a (patch)
treeaf47582053b30d018c3f1d02e0462aa1eab1b6bb /src
parentcecdba5cd996cea3ebd2534aea7a3e3a41205b9c (diff)
downloadtherapy-0751446e1d069263d25abcff49a32a380231709a.tar.gz
therapy-0751446e1d069263d25abcff49a32a380231709a.tar.bz2
therapy-0751446e1d069263d25abcff49a32a380231709a.zip
Rewrote bloom so it's not super slow, also removed the frame from the screen mesh
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp18
-rw-r--r--src/renderer.cpp151
2 files changed, 107 insertions, 62 deletions
diff --git a/src/main.cpp b/src/main.cpp index 62c8b16..bc7832d 100644 --- a/src/main.cpp +++ b/src/main.cpp
@@ -42,22 +42,24 @@ int main()
42 curGameState = new MapView(m, 100, 100); 42 curGameState = new MapView(m, 100, 100);
43 43
44 Texture* buffer = createTexture(GAME_WIDTH, GAME_HEIGHT); 44 Texture* buffer = createTexture(GAME_WIDTH, GAME_HEIGHT);
45 //Texture* buffer = loadTextureFromBMP("../res/title.png");
45 46
46 double lastTime = glfwGetTime(); 47 double lastTime = glfwGetTime();
47 double accum = 0.0; 48 int nbFrames = 0;
48 49
49 while (!(quit || glfwWindowShouldClose(window))) 50 while (!(quit || glfwWindowShouldClose(window)))
50 { 51 {
51 // Tick! 52 double currentTime = glfwGetTime();
52 accum += (glfwGetTime() - lastTime); 53 nbFrames++;
53 if (accum < 0) accum = 0; 54 if (currentTime - lastTime >= 1.0)
54 while (accum > SECONDS_PER_FRAME)
55 { 55 {
56 curGameState->tick(); 56 // printf and reset timer
57 accum -= SECONDS_PER_FRAME; 57 printf("%f ms/frame\n", 1000.0/double(nbFrames));
58 nbFrames = 0;
59 lastTime += 1.0;
58 } 60 }
59 61
60 lastTime = glfwGetTime(); 62 curGameState->tick();
61 63
62 // Do rendering 64 // Do rendering
63 curGameState->render(buffer); 65 curGameState->render(buffer);
diff --git a/src/renderer.cpp b/src/renderer.cpp index 6c8a88a..72de8a9 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp
@@ -17,8 +17,9 @@ static bool rendererInitialized = false;
17 17
18static GLFWwindow* window; 18static GLFWwindow* window;
19 19
20static GLuint FramebufferName; // The framebuffer 20static GLuint generic_framebuffer; // The framebuffer
21static GLuint depthrenderbuffer; 21static GLuint bloom_framebuffer;
22static GLuint bloom_depthbuffer;
22static int buffer_width = 1024; 23static int buffer_width = 1024;
23static int buffer_height = 768; 24static int buffer_height = 768;
24 25
@@ -37,7 +38,8 @@ static int curBuf;
37static GLuint artifactsTex; 38static GLuint artifactsTex;
38static GLuint scanlinesTex; 39static GLuint scanlinesTex;
39static GLuint preBloomTex; 40static GLuint preBloomTex;
40static GLuint bloomPassTex; 41static GLuint bloomPassTex1;
42static GLuint bloomPassTex2;
41 43
42// The VAO 44// The VAO
43static GLuint VertexArrayID; 45static GLuint VertexArrayID;
@@ -199,21 +201,22 @@ void setFramebufferSize(GLFWwindow* w, int width, int height)
199 buffer_width = width; 201 buffer_width = width;
200 buffer_height = height; 202 buffer_height = height;
201 203
202 glDeleteFramebuffers(1, &FramebufferName); 204 glDeleteFramebuffers(1, &bloom_framebuffer);
203 glDeleteRenderbuffers(1, &depthrenderbuffer); 205 glDeleteRenderbuffers(1, &bloom_depthbuffer);
204 206
205 glGenFramebuffers(1, &FramebufferName); 207 glGenFramebuffers(1, &bloom_framebuffer);
206 glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); 208 glBindFramebuffer(GL_FRAMEBUFFER, bloom_framebuffer);
207 GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; 209 GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT1};
208 glDrawBuffers(1, DrawBuffers); 210 glDrawBuffers(1, DrawBuffers);
209 211
210 glGenRenderbuffers(1, &depthrenderbuffer); 212 glGenRenderbuffers(1, &bloom_depthbuffer);
211 glBindRenderbuffer(GL_RENDERBUFFER, depthrenderbuffer); 213 glBindRenderbuffer(GL_RENDERBUFFER, bloom_depthbuffer);
212 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height); 214 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
213 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthrenderbuffer); 215 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, bloom_depthbuffer);
214 216
215 glDeleteTextures(1, &preBloomTex); 217 glDeleteTextures(1, &preBloomTex);
216 glDeleteTextures(1, &bloomPassTex); 218 glDeleteTextures(1, &bloomPassTex1);
219 glDeleteTextures(1, &bloomPassTex2);
217 220
218 glGenTextures(1, &preBloomTex); 221 glGenTextures(1, &preBloomTex);
219 glBindTexture(GL_TEXTURE_2D, preBloomTex); 222 glBindTexture(GL_TEXTURE_2D, preBloomTex);
@@ -223,9 +226,17 @@ void setFramebufferSize(GLFWwindow* w, int width, int height)
223 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 226 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
224 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 227 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
225 228
226 glGenTextures(1, &bloomPassTex); 229 glGenTextures(1, &bloomPassTex1);
227 glBindTexture(GL_TEXTURE_2D, bloomPassTex); 230 glBindTexture(GL_TEXTURE_2D, bloomPassTex1);
228 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width/16, height/16, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); 231 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width/4, height/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
232 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
233 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
234 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
235 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
236
237 glGenTextures(1, &bloomPassTex2);
238 glBindTexture(GL_TEXTURE_2D, bloomPassTex2);
239 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width/4, height/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
229 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 240 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
230 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 241 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
231 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 242 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -285,15 +296,20 @@ GLFWwindow* initRenderer()
285 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 296 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
286 297
287 // Set up the framebuffer 298 // Set up the framebuffer
288 glGenFramebuffers(1, &FramebufferName); 299 glGenFramebuffers(1, &generic_framebuffer);
289 glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); 300 glBindFramebuffer(GL_FRAMEBUFFER, generic_framebuffer);
290 GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; 301 GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
291 glDrawBuffers(1, DrawBuffers); 302 glDrawBuffers(1, DrawBuffers);
292 303
293 glGenRenderbuffers(1, &depthrenderbuffer); 304 glGenFramebuffers(1, &bloom_framebuffer);
294 glBindRenderbuffer(GL_RENDERBUFFER, depthrenderbuffer); 305 glBindFramebuffer(GL_FRAMEBUFFER, bloom_framebuffer);
306 GLenum DrawBuffers2[1] = {GL_COLOR_ATTACHMENT1};
307 glDrawBuffers(1, DrawBuffers2);
308
309 glGenRenderbuffers(1, &bloom_depthbuffer);
310 glBindRenderbuffer(GL_RENDERBUFFER, bloom_depthbuffer);
295 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, 1024, 768); 311 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, 1024, 768);
296 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthrenderbuffer); 312 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, bloom_depthbuffer);
297 313
298 // Set up the NTSC rendering buffers 314 // Set up the NTSC rendering buffers
299 glGenTextures(1, &renderedTex1); 315 glGenTextures(1, &renderedTex1);
@@ -323,9 +339,17 @@ GLFWwindow* initRenderer()
323 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 339 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
324 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 340 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
325 341
326 glGenTextures(1, &bloomPassTex); 342 glGenTextures(1, &bloomPassTex1);
327 glBindTexture(GL_TEXTURE_2D, bloomPassTex); 343 glBindTexture(GL_TEXTURE_2D, bloomPassTex1);
328 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 48, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); 344 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024/4, 768/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
346 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
347 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
348 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
349
350 glGenTextures(1, &bloomPassTex2);
351 glBindTexture(GL_TEXTURE_2D, bloomPassTex2);
352 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024/4, 768/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
329 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 353 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
330 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 354 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
331 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 355 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -381,7 +405,7 @@ GLFWwindow* initRenderer()
381 glGenTextures(1, &scanlinesTex); 405 glGenTextures(1, &scanlinesTex);
382 glBindTexture(GL_TEXTURE_2D, scanlinesTex); 406 glBindTexture(GL_TEXTURE_2D, scanlinesTex);
383 int stdw, stdh; 407 int stdw, stdh;
384 unsigned char* scanlinesTex_data = stbi_load("../res/scanlines.bmp", &stdw, &stdh, 0, 3); 408 unsigned char* scanlinesTex_data = stbi_load("../res/scanlines_222.bmp", &stdw, &stdh, 0, 3);
385 flipImageData(scanlinesTex_data, stdw, stdh, 3); 409 flipImageData(scanlinesTex_data, stdw, stdh, 3);
386 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, atdw, atdh, 0, GL_RGB, GL_UNSIGNED_BYTE, scanlinesTex_data); 410 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, atdw, atdh, 0, GL_RGB, GL_UNSIGNED_BYTE, scanlinesTex_data);
387 stbi_image_free(scanlinesTex_data); 411 stbi_image_free(scanlinesTex_data);
@@ -430,11 +454,13 @@ void destroyRenderer()
430 glDeleteTextures(1, &artifactsTex); 454 glDeleteTextures(1, &artifactsTex);
431 glDeleteTextures(1, &scanlinesTex); 455 glDeleteTextures(1, &scanlinesTex);
432 glDeleteTextures(1, &preBloomTex); 456 glDeleteTextures(1, &preBloomTex);
433 glDeleteTextures(1, &bloomPassTex); 457 glDeleteTextures(1, &bloomPassTex1);
458 glDeleteTextures(1, &bloomPassTex2);
434 459
435 // Delete the framebuffer 460 // Delete the framebuffer
436 glDeleteRenderbuffers(1, &depthrenderbuffer); 461 glDeleteRenderbuffers(1, &bloom_depthbuffer);
437 glDeleteFramebuffers(1, &FramebufferName); 462 glDeleteFramebuffers(1, &bloom_framebuffer);
463 glDeleteFramebuffers(1, &generic_framebuffer);
438 464
439 // Delete the VAO 465 // Delete the VAO
440 glDeleteVertexArrays(1, &VertexArrayID); 466 glDeleteVertexArrays(1, &VertexArrayID);
@@ -543,7 +569,7 @@ void fillTexture(Texture* tex, Rectangle* dstrect, int r, int g, int b)
543 } 569 }
544 570
545 // Target the framebuffer 571 // Target the framebuffer
546 glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); 572 glBindFramebuffer(GL_FRAMEBUFFER, generic_framebuffer);
547 glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex->texID, 0); 573 glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex->texID, 0);
548 574
549 // Set up the vertex attributes 575 // Set up the vertex attributes
@@ -592,7 +618,7 @@ void blitTexture(Texture* srctex, Texture* dsttex, Rectangle* srcrect, Rectangle
592 } 618 }
593 619
594 // Target the framebuffer 620 // Target the framebuffer
595 glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); 621 glBindFramebuffer(GL_FRAMEBUFFER, generic_framebuffer);
596 glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, dsttex->texID, 0); 622 glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, dsttex->texID, 0);
597 623
598 // Set up the vertex attributes 624 // Set up the vertex attributes
@@ -717,6 +743,35 @@ void renderWithoutEffects(Texture* tex)
717 glfwSwapBuffers(window); 743 glfwSwapBuffers(window);
718} 744}
719 745
746void bloomPass1(GLuint srcTex, GLuint dstTex, bool horizontal, vec2 srcRes, vec2 dstRes)
747{
748 glBindFramebuffer(GL_FRAMEBUFFER, generic_framebuffer);
749 glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, dstTex, 0);
750 glViewport(0,0,dstRes.x,dstRes.y);
751 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
752 glUseProgram(bloom1Shader);
753
754 glActiveTexture(GL_TEXTURE0);
755 glBindTexture(GL_TEXTURE_2D, srcTex);
756 glUniform1i(glGetUniformLocation(bloom1Shader, "inTex"), 0);
757
758 vec2 offset = vec2(0.0);
759 if (horizontal)
760 {
761 offset.x = 1.2/srcRes.x;
762 } else {
763 offset.y = 1.2/srcRes.y;
764 }
765
766 glUniform2f(glGetUniformLocation(bloom1Shader, "offset"), offset.x, offset.y);
767
768 glEnableVertexAttribArray(0);
769 glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer);
770 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
771 glDrawArrays(GL_TRIANGLES, 0, 6);
772 glDisableVertexAttribArray(0);
773}
774
720void renderScreen(Texture* tex) 775void renderScreen(Texture* tex)
721{ 776{
722 if (!rendererInitialized) 777 if (!rendererInitialized)
@@ -727,7 +782,7 @@ void renderScreen(Texture* tex)
727 782
728 // First we're going to composite our frame with the previous frame 783 // First we're going to composite our frame with the previous frame
729 // We start by setting up the framebuffer 784 // We start by setting up the framebuffer
730 glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); 785 glBindFramebuffer(GL_FRAMEBUFFER, generic_framebuffer);
731 glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexBufs[curBuf], 0); 786 glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexBufs[curBuf], 0);
732 787
733 // Set up the shader 788 // Set up the shader
@@ -775,7 +830,8 @@ void renderScreen(Texture* tex)
775 glDisableVertexAttribArray(0); 830 glDisableVertexAttribArray(0);
776 831
777 // We're going to render the screen now 832 // We're going to render the screen now
778 glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, preBloomTex, 0); 833 glBindFramebuffer(GL_FRAMEBUFFER, bloom_framebuffer);
834 glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, preBloomTex, 0);
779 //glBindFramebuffer(GL_FRAMEBUFFER, 0); 835 //glBindFramebuffer(GL_FRAMEBUFFER, 0);
780 glViewport(0,0,buffer_width,buffer_height); 836 glViewport(0,0,buffer_width,buffer_height);
781 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 837 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -799,7 +855,7 @@ void renderScreen(Texture* tex)
799 glUniform1i(glGetUniformLocation(finalShader, "scanlinestex"), 1); 855 glUniform1i(glGetUniformLocation(finalShader, "scanlinestex"), 1);
800 856
801 // Initialize the MVP matrices 857 // Initialize the MVP matrices
802 mat4 p_matrix = perspective(45.0f, (float) buffer_width / (float) buffer_height, 0.1f, 100.0f); 858 mat4 p_matrix = perspective(42.5f, (float) buffer_width / (float) buffer_height, 0.1f, 100.0f);
803 mat4 v_matrix = lookAt(vec3(2,0,0), vec3(0,0,0), vec3(0,1,0)); 859 mat4 v_matrix = lookAt(vec3(2,0,0), vec3(0,0,0), vec3(0,1,0));
804 mat4 m_matrix = mat4(1.0); 860 mat4 m_matrix = mat4(1.0);
805 mat4 mvp_matrix = p_matrix * v_matrix * m_matrix; 861 mat4 mvp_matrix = p_matrix * v_matrix * m_matrix;
@@ -808,6 +864,7 @@ void renderScreen(Texture* tex)
808 glUniformMatrix4fv(glGetUniformLocation(finalShader, "MVP"), 1, GL_FALSE, &mvp_matrix[0][0]); 864 glUniformMatrix4fv(glGetUniformLocation(finalShader, "MVP"), 1, GL_FALSE, &mvp_matrix[0][0]);
809 glUniformMatrix4fv(glGetUniformLocation(finalShader, "worldMat"), 1, GL_FALSE, &m_matrix[0][0]); 865 glUniformMatrix4fv(glGetUniformLocation(finalShader, "worldMat"), 1, GL_FALSE, &m_matrix[0][0]);
810 glUniform2f(glGetUniformLocation(finalShader, "resolution"), buffer_width, buffer_height); 866 glUniform2f(glGetUniformLocation(finalShader, "resolution"), buffer_width, buffer_height);
867 glUniform1f(glGetUniformLocation(finalShader, "iGlobalTime"), glfwGetTime());
811 868
812 glEnableVertexAttribArray(0); 869 glEnableVertexAttribArray(0);
813 glBindBuffer(GL_ARRAY_BUFFER, mesh_vertexbuffer); 870 glBindBuffer(GL_ARRAY_BUFFER, mesh_vertexbuffer);
@@ -826,24 +883,10 @@ void renderScreen(Texture* tex)
826 glDisableVertexAttribArray(1); 883 glDisableVertexAttribArray(1);
827 glDisableVertexAttribArray(0); 884 glDisableVertexAttribArray(0);
828 885
829 // Do the first pass of bloom (downsampling and tapping) 886 // First pass of bloom!
830 glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, bloomPassTex, 0); 887 vec2 buffer_size = vec2(buffer_width, buffer_height);
831 glViewport(0, 0, buffer_width/16, buffer_height/16); 888 bloomPass1(preBloomTex, bloomPassTex1, true, buffer_size, buffer_size / 4.0f);
832 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 889 bloomPass1(bloomPassTex1, bloomPassTex2, false, buffer_size / 4.0f, buffer_size / 4.0f);
833 glUseProgram(bloom1Shader);
834
835 glActiveTexture(GL_TEXTURE0);
836 glBindTexture(GL_TEXTURE_2D, preBloomTex);
837 glUniform1i(glGetUniformLocation(bloom1Shader, "screenTex"), 0);
838
839 glUniform1f(glGetUniformLocation(bloom1Shader, "iGlobalTime"), glfwGetTime());
840 glUniform2f(glGetUniformLocation(bloom1Shader, "resolution"), buffer_width, buffer_height);
841
842 glEnableVertexAttribArray(0);
843 glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer);
844 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
845 glDrawArrays(GL_TRIANGLES, 0, 6);
846 glDisableVertexAttribArray(0);
847 890
848 // Do the second pass of bloom and render to screen 891 // Do the second pass of bloom and render to screen
849 glBindFramebuffer(GL_FRAMEBUFFER, 0); 892 glBindFramebuffer(GL_FRAMEBUFFER, 0);
@@ -853,14 +896,14 @@ void renderScreen(Texture* tex)
853 896
854 glActiveTexture(GL_TEXTURE0); 897 glActiveTexture(GL_TEXTURE0);
855 glBindTexture(GL_TEXTURE_2D, preBloomTex); 898 glBindTexture(GL_TEXTURE_2D, preBloomTex);
856 glUniform1i(glGetUniformLocation(bloom2Shader, "screenTex"), 0); 899 glUniform1i(glGetUniformLocation(bloom2Shader, "clearTex"), 0);
857 900
858 glActiveTexture(GL_TEXTURE1); 901 glActiveTexture(GL_TEXTURE1);
859 glBindTexture(GL_TEXTURE_2D, bloomPassTex); 902 glBindTexture(GL_TEXTURE_2D, bloomPassTex2);
860 glUniform1i(glGetUniformLocation(bloom2Shader, "downsampledTex"), 1); 903 glUniform1i(glGetUniformLocation(bloom2Shader, "blurTex"), 1);
861 904
862 glUniform1f(glGetUniformLocation(bloom2Shader, "iGlobalTime"), glfwGetTime()); 905 glUniform1f(glGetUniformLocation(bloom2Shader, "iGlobalTime"), glfwGetTime());
863 glUniform2f(glGetUniformLocation(bloom2Shader, "resolution"), buffer_width, buffer_height); 906// glUniform2f(glGetUniformLocation(bloom2Shader, "resolution"), buffer_width, buffer_height);
864 907
865 glEnableVertexAttribArray(0); 908 glEnableVertexAttribArray(0);
866 glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); 909 glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer);