#include #include #include #include #include #include "shader.h" #include "die.h" #include "config.h" #include "fill_vert.h" #include "visuals_frag.h" void prepare_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(); 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 glewInit(); // create single triangle prepare_tri(); // prepare shaders 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); // 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); glUseProgram(shader); glDrawArrays(GL_TRIANGLES, 0, 3); glfwSwapBuffers(window); } return EXIT_SUCCESS; }