#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>

int main(void){
    GLFWwindow* window;

    // Library inits
    if (!glfwInit()) {
        std::cout << "GLFW could not be initialized!" << std::endl;
        return -1;
    }    

    //Window creation
    window = glfwCreateWindow(640, 480, "OpenGl practice", NULL, NULL);
    if (!window){
        std::cout << "Window could not be created!" << std::endl;
        glfwTerminate();
        return -1;
    }
   
    glfwMakeContextCurrent(window);

    if (glewInit() != GLEW_OK) {
        std::cout << "GLEW Error" << std::endl;
        return -1;
    }

    std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;

   //Main loop
    while (!glfwWindowShouldClose(window)){
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        glBegin(GL_TRIANGLES);
        glVertex2f(-0.5f, -0.5f);
        glVertex2f(0.0f, 0.5f);
        glVertex2f(0.5f, -0.5f);
        glEnd();

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}