Selaa lähdekoodia

Implement flashbanging on hot reloading

rexim 3 vuotta sitten
vanhempi
commit
4f0b531f18
4 muutettua tiedostoa jossa 15 lisäystä ja 8 poistoa
  1. 6 0
      main.c
  2. 2 2
      render.conf
  3. 2 1
      shaders/debug.frag
  4. 5 5
      shaders/main.frag

+ 6 - 0
main.c

@@ -386,6 +386,7 @@ bool r_reload(Renderer *r)
 #define COLOR_BLACK_V4F ((V4f){0.0f, 0.0f, 0.0f, 1.0f})
 #define COLOR_RED_V4F ((V4f){1.0f, 0.0f, 0.0f, 1.0f})
 #define COLOR_GREEN_V4F ((V4f){0.0f, 1.0f, 0.0f, 1.0f})
+#define COLOR_BLUE_V4F ((V4f){0.0f, 0.0f, 1.0f, 1.0f})
 
 float t = 0.0f;
 float dt = 0.0f;
@@ -423,6 +424,9 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
                 fprintf(stderr, "ERROR: could not save %s: %s\n", SCREENSHOT_PNG_PATH, strerror(errno));
             }
             free(pixels);
+            color = COLOR_BLUE_V4F;
+            dt = -2.0f;
+            t = 1.0f;
         } else if (key == GLFW_KEY_SPACE) {
             pause = !pause;
         } else if (key == GLFW_KEY_Q) {
@@ -595,6 +599,7 @@ int main(void)
     GLuint framebuffer_tex_uniform = glGetUniformLocation(framebuffer_program, "tex");
     GLuint framebuffer_color_uniform = glGetUniformLocation(framebuffer_program, "color");
     GLuint framebuffer_t_uniform = glGetUniformLocation(framebuffer_program, "t");
+    GLuint framebuffer_resolution_uniform = glGetUniformLocation(framebuffer_program, "resolution");
 
     glUniform1i(framebuffer_tex_uniform, 1);
     glUniform4f(framebuffer_color_uniform, 1.0, 0.0, 0.0, 1.0);
@@ -649,6 +654,7 @@ int main(void)
         }
         glUniform1f(framebuffer_t_uniform, t);
         glUniform4f(framebuffer_color_uniform, color.x, color.y, color.z, color.w);
+        glUniform2f(framebuffer_resolution_uniform, width, height);
         glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 
         glfwSwapBuffers(window);

+ 2 - 2
render.conf

@@ -1,4 +1,4 @@
 vert = shaders/main.vert
 frag = shaders/main.frag
-texture = assets/tsodinW-345.png
-#texture = assets/tsodinFlushed-112.png
+#texture = assets/tsodinW-345.png
+texture = assets/tsodinSleep-112.png

+ 2 - 1
shaders/debug.frag

@@ -5,10 +5,11 @@ precision mediump float;
 uniform sampler2D tex;
 uniform vec4 color;
 uniform float t;
+uniform vec2 resolution;
 
 in vec2 uv;
 out vec4 out_color;
 
 void main(void) {
-    out_color = mix(texture(tex, vec2(uv.x, uv.y)), color, t);
+    out_color = mix(texture(tex, (resolution / vec2(1600.0, 900.0)) * uv), color, t);
 }

+ 5 - 5
shaders/main.frag

@@ -12,9 +12,9 @@ in vec4 color;
 out vec4 out_color;
 
 void main(void) {
-    out_color = texture(tex, vec2(uv.x, 1.0 - uv.y)) * vec4(
-        (sin(uv.x + time) + 1.0) / 2.0,
-        (cos(uv.y + time) + 1.0) / 2.0,
-        (cos(uv.x + uv.y + time) + 1.0) / 2.0,
-        1.0);
+    out_color = texture(tex, vec2(uv.x, 1.0 - uv.y));//  * vec4(
+        // (sin(uv.x + time) + 1.0) / 2.0,
+        // (cos(uv.y + time) + 1.0) / 2.0,
+        // (cos(uv.x + uv.y + time) + 1.0) / 2.0,
+        // 1.0);
 }