#ifdef _WIN32 #include #include #endif #define GLFW_INCLUDE_NONE #include "GLFW/glfw3.h" #ifdef _WIN32 #define GLFW_EXPOSE_NATIVE_WIN32 #include "GLFW/glfw3native.h" #endif #include "fmt/std.h" #include "cbt/window.hpp" namespace cbt { auto window::init_glfw() -> bool { if (!glfwInit()) { fmt::print("Failed to initialize GLFW\n"); return false; } return true; } auto window::terminate_glfw() -> void { glfwTerminate(); } window::window(std::string title, int width, int height) { if (!init_glfw()) { return; } m_glfw_initialized = true; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); m_window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr); if (!m_window) { fmt::print("Failed to create window\n"); terminate_glfw(); m_glfw_initialized = false; return; } #ifdef _WIN32 auto hwnd = glfwGetWin32Window(m_window); BOOL use_dark_mode = TRUE; DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &use_dark_mode, sizeof(use_dark_mode)); #endif } window::~window() { if (m_window) { glfwDestroyWindow(m_window); } if (m_glfw_initialized) { terminate_glfw(); } } auto window::should_close() const -> bool { return m_window && glfwWindowShouldClose(m_window); } auto window::valid() const -> bool { return m_window != nullptr; } auto window::swap_buffers() -> void { glfwSwapBuffers(m_window); } auto window::poll_events() -> void { glfwPollEvents(); } auto window::raw() const -> GLFWwindow* { return m_window; } auto window::stop() -> void { if (m_window) { glfwSetWindowShouldClose(m_window, GLFW_TRUE); } } }