diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 66 |
1 files changed, 33 insertions, 33 deletions
@@ -1,17 +1,42 @@ #include <stdlib.h> #include <GL/glew.h> #include <GLFW/glfw3.h> -#include <sys/time.h> -#include <time.h> #include "shader.h" #include "die.h" -#include "config.h" +#include "uniform.h" #include "fill_vert.h" #include "visuals_frag.h" -void prepare_tri() { +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 + int width = 800, height = 600; // default size + GLFWwindow* window = glfwCreateWindow(width, height, "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, @@ -39,46 +64,21 @@ void prepare_tri() { int main(int argc, char** argv) { glfwInit(); - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - - // force floating window w/ i3 - glfwWindowHint(GLFW_FLOATING, GL_TRUE); - glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); - - // initialize window - GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "vis", NULL, NULL); - if (window == NULL) - die("error: could not create window\n"); - glfwMakeContextCurrent(window); - - // initialize GLEW + GLFWwindow* window = init_window(); glewInit(); - // create single triangle - prepare_tri(); - - // prepare shaders + init_tri(); GLuint shader = link_shaders( vert_shader(fill_vert, fill_vert_size), frag_shader(visuals_frag, visuals_frag_size) ); - - // prepare uniform variables - GLint u_time = glGetUniformLocation(shader, "time"); - int time_start = time(NULL); + init_uniform(shader, window); // main draw loop while (!glfwWindowShouldClose(window)) { glfwPollEvents(); - // set `time` uniform - struct timeval t; - gettimeofday(&t, NULL); - t.tv_sec -= time_start; - float time = t.tv_sec + (t.tv_usec / 1e6); - glUniform1f(u_time, time); + update_uniform(); glUseProgram(shader); glDrawArrays(GL_TRIANGLES, 0, 3); |