#include "initialization.h"

void initializeWindowSystem(GLFWwindow** windowPtr)
{
    glewExperimental = true;
    if( !glfwInit() )
    {
        fprintf( stderr, "Failed to initialize GLFW :(\n" );
        return -1;
    }
    glfwWindowHint(GLFW_SAMPLES, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    *windowPtr = glfwCreateWindow(WINW, WINH, "Planet Miner", NULL, NULL);
    if( *windowPtr == NULL )
    {
        fprintf( stderr, "Failed to create window. If you are using an Intel GPU, please note that they are not compatible with OpenGL 3.3\n" );
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(*windowPtr);

    glewExperimental = true;
    if( glewInit() != GLEW_OK )
    {
        fprintf( stderr, "Failed to initialize GLEW\n" );
        getchar();
        glfwTerminate();
        return -1;
    }

    glfwSetInputMode(*windowPtr, GLFW_STICKY_KEYS, GL_TRUE);

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    printf("Window: %d\n", (int)windowPtr);
}

void initializeVertexBuffer(GLuint* vertexBufferPtr, GLfloat* vertexBufferData)
{
    glGenBuffers(1, vertexBufferPtr);
    glBindBuffer(GL_ARRAY_BUFFER, *vertexBufferPtr);
    glBufferData(GL_ARRAY_BUFFER, sizeof(*vertexBufferData), vertexBufferData, GL_STATIC_DRAW);
}
