#include "graphics/glwindow.h"
#include <SDL_error.h>
#include <SDL_video.h>

bool GLWindow::Init() {
  window = SDL_CreateWindow(name, SDL_WINDOWPOS_UNDEFINED,
                            SDL_WINDOWPOS_UNDEFINED, w, h, SDL_WINDOW_OPENGL);
  if (!window) {
    LOG(ERROR, "Failed to create window! {}", SDL_GetError());
    return false;
  }
  glContext = SDL_GL_CreateContext(window);
  if (!glContext) {
    LOG(ERROR, "Failed to create opengl context! {}", SDL_GetError());
    return false;
  }
  return true;
}

void GLWindow::resizeWindow(size_t width, size_t height) {
  w = width;
  h = height;
}

GLWindow::~GLWindow() {
  SDL_GL_DeleteContext(glContext);
  SDL_DestroyWindow(window);
}
