diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 34 |
1 files changed, 31 insertions, 3 deletions
@@ -8,6 +8,7 @@ #include "fill_vert.h" #include "visuals_frag.h" +#include "output_frag.h" void resize_handler(GLFWwindow* window, int width, int height) { glViewport(0, 0, width, height); @@ -68,18 +69,45 @@ int main(int argc, char** argv) { glewInit(); init_tri(); - GLuint shader = link_shaders( + + GLuint visuals = link_shaders( vert_shader(fill_vert, fill_vert_size), frag_shader(visuals_frag, visuals_frag_size) ); - init_uniform(shader, window); + uniforms_t * visuals_uniforms = init_uniforms(visuals, window); + + GLuint output = link_shaders( + vert_shader(fill_vert, fill_vert_size), + frag_shader(output_frag, output_frag_size) + ); + uniforms_t * output_uniforms = init_uniforms(output, window); + + GLuint fbo; + glGenFramebuffers(1, &fbo); + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + + GLuint last_frame; + glGenTextures(1, &last_frame); + glBindTexture(GL_TEXTURE_2D, last_frame); + // todo: what to do when the size changes? + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 800, 600, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, last_frame, 0); + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) + die("can't initialize framebuffer??\n"); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + + glUseProgram(visuals); // main draw loop while (!glfwWindowShouldClose(window)) { glfwPollEvents(); - update_uniform(); + update_uniforms(visuals_uniforms); + // glBindFramebuffer(GL_FRAMEBUFFER, fbo); glDrawArrays(GL_TRIANGLES, 0, 3); + // glBindFramebuffer(GL_FRAMEBUFFER, 0); glfwSwapBuffers(window); } |