#ifdef ARC_GLFW_WINDOW
#include "arc/graphics/renderer.h"
#include "renderer.h"

// #ifdef ARC_GLEW
#define GLEW_STATIC
#include <GL/glew.h>
// #endif // ARC_GLEW

#include <GLFW/glfw3.h>

#include "arc/graphics/window.h"
#include "arc/std/errno.h"
#include <stdlib.h>

void ARC_Renderer_CreateWithEngineData(ARC_Renderer **renderer, ARC_EngineData *data){
    if(!info){
        arc_errno = ARC_ERRNO_NULL;
        ARC_DEBUG_ERR("ARC_Renderer_Create(**renderer, NULL)");
        return;
    }

// #ifdef ARC_GLEW
    *renderer = (ARC_Renderer *)malloc(sizeof(ARC_Renderer));
    (*renderer)->window = (GLFWwindow *)data->window;

    glewExperimental = GL_TRUE;
    if(glewInit() != GLEW_OK){
        ARC_DEBUG_ERR("ARC_Renderer_Create(**renderer, info), GLEW failed to init");
        glfwTerminate();
        arc_errno = ARC_ERRNO_INIT;
    }
// #endif // ARC_GLEW

    glClearColor(0.23f, 0.38f, 0.47f, 1.0f);
}

void ARC_Renderer_Destroy(ARC_Renderer *renderer){
    free(renderer);
}

void ARC_Renderer_Clear(ARC_Renderer *renderer){
    glClear(GL_COLOR_BUFFER_BIT);
}

void ARC_Renderer_Render(ARC_Renderer *renderer){
// #ifdef ARC_GLEW
    glfwSwapBuffers(renderer->window);
// #endif // ARC_GLEW
}

#endif //ARC_SDL
