#include #include #include #include "shader.h" #include "die.h" #include "hello_vert.h" #include "hello_frag.h" void prepare_tri(GLuint* VBO, GLuint* VAO) { const float vertices[] = { -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, 0.0f, 0.5f, 0.0f, }; // initialize vertex {buffer,attribute} object buffers glGenBuffers(1, VBO); glBindBuffer(GL_ARRAY_BUFFER, *VBO); glGenBuffers(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); } 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(800, 600, "vis", NULL, NULL); if (window == NULL) die("error: could not create window\n"); glfwMakeContextCurrent(window); // initialize GLEW glewInit(); // create single triangle GLuint VBO, VAO; prepare_tri(&VBO, &VAO); // prepare shaders GLuint shader = link_shaders( vert_shader(hello_vert, hello_vert_size), frag_shader(hello_frag, hello_frag_size) ); // main draw loop while (!glfwWindowShouldClose(window)) { glfwPollEvents(); glClearColor(1.f, 0.f, 1.f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glUseProgram(shader); glBindVertexArray(VAO); glDrawArrays(GL_TRIANGLES, 0, 3); glfwSwapBuffers(window); } return EXIT_SUCCESS; }