Browse Source

Resize framebuffer texture on window resize

rexim 3 years ago
parent
commit
73e22752ae
4 changed files with 22 additions and 9 deletions
  1. 14 1
      main.c
  2. 2 2
      render.conf
  3. 1 1
      shaders/debug.frag
  4. 5 5
      shaders/main.frag

+ 14 - 1
main.c

@@ -444,11 +444,24 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
 }
 }
 
 
 GLuint framebuffer;
 GLuint framebuffer;
+GLuint framebuffer_texture;
 
 
 void window_size_callback(GLFWwindow* window, int width, int height)
 void window_size_callback(GLFWwindow* window, int width, int height)
 {
 {
     (void) window;
     (void) window;
     glViewport(0, 0, width, height);
     glViewport(0, 0, width, height);
+    glActiveTexture(GL_TEXTURE1);
+    glBindTexture(GL_TEXTURE_2D, framebuffer_texture);
+    glTexImage2D(
+        GL_TEXTURE_2D,
+        0,
+        GL_RGBA,
+        width,
+        height,
+        0,
+        GL_RGBA,
+        GL_UNSIGNED_BYTE,
+        NULL);
 }
 }
 
 
 void MessageCallback(GLenum source,
 void MessageCallback(GLenum source,
@@ -556,7 +569,7 @@ int main(void)
     glEnable(GL_BLEND);
     glEnable(GL_BLEND);
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
 
-    GLuint framebuffer_texture;
+
     glGenTextures(1, &framebuffer_texture);
     glGenTextures(1, &framebuffer_texture);
     glActiveTexture(GL_TEXTURE1);
     glActiveTexture(GL_TEXTURE1);
     glBindTexture(GL_TEXTURE_2D, framebuffer_texture);
     glBindTexture(GL_TEXTURE_2D, framebuffer_texture);

+ 2 - 2
render.conf

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

+ 1 - 1
shaders/debug.frag

@@ -11,5 +11,5 @@ in vec2 uv;
 out vec4 out_color;
 out vec4 out_color;
 
 
 void main(void) {
 void main(void) {
-    out_color = mix(texture(tex, (resolution / vec2(1600.0, 900.0)) * uv), color, t);
+    out_color = mix(texture(tex, uv), color, t);
 }
 }

+ 5 - 5
shaders/main.frag

@@ -12,9 +12,9 @@ in vec4 color;
 out vec4 out_color;
 out vec4 out_color;
 
 
 void main(void) {
 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);
 }
 }