2022-01-08 21:57:17 +01:00
|
|
|
#include "window.hpp"
|
2022-01-08 23:40:31 +01:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
|
|
|
|
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-01-08 23:40:31 +01:00
|
|
|
}
|
2022-01-08 21:57:17 +01:00
|
|
|
|
|
|
|
gui::Window::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);
|
|
|
|
wwindow = std::unique_ptr<GLFWwindow, decltype(&delete_glfw_window)>(glfwCreateWindow(600, 800, "Billy Sheet tracker", nullptr, nullptr),
|
|
|
|
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());
|
|
|
|
glfwSwapInterval(1); // VSync on
|
|
|
|
|
|
|
|
glfwSetFramebufferSizeCallback(wwindow.get(), framebufferCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|