2022-01-11 22:33:29 +01:00
|
|
|
#include "gui/window.hpp"
|
2022-01-08 23:40:31 +01:00
|
|
|
#include <stdexcept>
|
2022-01-17 22:00:26 +01:00
|
|
|
#include <spdlog/spdlog.h>
|
2022-01-08 23:40:31 +01:00
|
|
|
|
|
|
|
static void glfwErrorCallback(int error, const char *message) {
|
2022-01-09 00:43:33 +01:00
|
|
|
SPDLOG_CRITICAL("Error code{}: {}", error, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void framebufferCallback([[maybe_unused]] GLFWwindow *glfWwindow, int width, int height) {
|
|
|
|
glViewport(0, 0, width, height);
|
2022-04-08 23:13:38 +02:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2022-01-08 23:40:31 +01:00
|
|
|
}
|
2022-01-08 21:57:17 +01:00
|
|
|
|
|
|
|
gui::Window::Window() {
|
2022-01-10 21:16:05 +01:00
|
|
|
SPDLOG_DEBUG("Creating Window");
|
2022-01-08 23:40:31 +01:00
|
|
|
glfwSetErrorCallback(glfwErrorCallback);
|
2022-01-08 21:57:17 +01:00
|
|
|
if (glfwInit() == GLFW_FALSE) {
|
2022-01-09 00:43:33 +01:00
|
|
|
SPDLOG_CRITICAL("GLFW init failed.");
|
2022-01-08 21:57:17 +01:00
|
|
|
throw std::runtime_error("GLFW init failed.");
|
|
|
|
}
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
2022-01-24 20:51:25 +01:00
|
|
|
wwindow = std::unique_ptr<GLFWwindow, decltype(&delete_glfw_window)>(glfwCreateWindow(720, 1280, "Billy Sheet tracker", nullptr, nullptr),
|
2022-01-08 21:57:17 +01:00
|
|
|
delete_glfw_window);
|
2022-01-09 00:43:33 +01:00
|
|
|
if (!wwindow) {
|
|
|
|
glfwTerminate();
|
|
|
|
SPDLOG_CRITICAL("No GLFW window created, nullptr.");
|
|
|
|
throw std::runtime_error("GLFW failed. See log.");
|
|
|
|
}
|
|
|
|
glfwMakeContextCurrent(wwindow.get());
|
2022-01-17 22:00:26 +01:00
|
|
|
glewExperimental = true;
|
|
|
|
if (glewInit() != GLEW_OK) {
|
|
|
|
wwindow.reset(nullptr);
|
|
|
|
glfwTerminate();
|
|
|
|
SPDLOG_CRITICAL("GLEW loader failed.");
|
|
|
|
throw std::runtime_error("GLEW failed. See log.");
|
|
|
|
}
|
2022-01-09 00:43:33 +01:00
|
|
|
glfwSetFramebufferSizeCallback(wwindow.get(), framebufferCallback);
|
2022-01-24 20:51:25 +01:00
|
|
|
|
|
|
|
glfwSwapInterval(1); // VSync on
|
2022-01-09 00:43:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool gui::Window::should_close() const noexcept {
|
|
|
|
return glfwWindowShouldClose(wwindow.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui::Window::swap_buffers() const noexcept {
|
|
|
|
glfwSwapBuffers(wwindow.get());
|
2022-01-08 21:57:17 +01:00
|
|
|
}
|