#include "include/glad/glad.h"
#include "include/glfw/glfw3.h"

#include <iostream>
#include "visualization.hpp"


GLFWwindow* initWindow() {
    // return nullptr because of GLFWwindow datatype
    // set to openGL 3 atleast
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    // initialize glfw, check for success
    if (!glfwInit()) {
        std::cerr << "GLFW initialization failed" << std::endl;
        return nullptr;
    } else {
        std::cerr << "GLFW initialization SUCCESS" << std::endl;
    }

    // create the window
    GLFWwindow* window = glfwCreateWindow(1280, 720, "Body Tracking Visualizer", NULL, NULL); 
    if (!window){
        std::cerr << "GLFW window creation failed" << std::endl;
        glfwTerminate();
        return nullptr;
    } else {
        std::cerr << "GLFW window creation SUCCESS" << std::endl;
    }

    // set the window context current
    glfwMakeContextCurrent(window);

    // initialize GLAD
    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)){
        std::cerr << "GLAD initialization failed" << std::endl;
        return nullptr;
    } else {
        std::cerr << "GLAD initialization SUCCESS" << std::endl;
    }



    // glViewport could be added here to make the display area smaller than the actual windowsize
    // with callbacks to automatically adjust if the user changes size

    

    // vsync
    glfwSwapInterval(1);

    return window;
}
