#include #include #include #include "consts.h" #include "fb.h" #include "shader.h" #include "die.h" #include "uniform.h" #include "fill_vert.h" #include "pass1_frag.h" #include "pass2_frag.h" void resize_handler(GLFWwindow* window, int width, int height) { glViewport(0, 0, width, height); } GLFWwindow* init_window() { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // creating a non-resizable floating window makes the window float with i3 glfwWindowHint(GLFW_FLOATING, GL_TRUE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // initialize window GLFWwindow* window = glfwCreateWindow(RES_H, RES_V, "vis", NULL, NULL); if (window == NULL) die("error: could not create window\n"); glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, resize_handler); // but i still want a resizable window glfwSetWindowAttrib(window, GLFW_RESIZABLE, GL_TRUE); return window; } void init_tri() { const float vertices[] = { 0, 1, 0, 1, -1, 0, -1, -1, 0, }; // initialize vertex {buffer,attribute} object buffers GLuint VBO, VAO; glGenBuffers(1, &VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glGenVertexArrays(1, &VAO); glBindVertexArray(VAO); // copy vertex data into VBO glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); // set VAO pointers glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); glEnableVertexAttribArray(0); // draw (only) this triangle glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(VAO); } int main(int argc, char** argv) { glfwInit(); GLFWwindow* window = init_window(); glewInit(); init_tri(); init_uniforms(); GLuint pass1 = link_shaders( vert_shader(fill_vert, fill_vert_size), frag_shader(pass1_frag, pass1_frag_size) ); GLuint pass2 = link_shaders( vert_shader(fill_vert, fill_vert_size), frag_shader(pass2_frag, pass2_frag_size) ); GLuint fbo = init_fb(); // main draw loop while (!glfwWindowShouldClose(window)) { glfwPollEvents(); glUseProgram(pass1); update_uniforms(); glBindFramebuffer(GL_FRAMEBUFFER, fbo); glDrawArrays(GL_TRIANGLES, 0, 3); glUseProgram(pass2); update_uniforms(); glBindFramebuffer(GL_FRAMEBUFFER, 0); glDrawArrays(GL_TRIANGLES, 0, 3); glfwSwapBuffers(window); } return EXIT_SUCCESS; }