#include "dxwindow.h" #define GLFW_EXPOSE_NATIVE_WIN32 #include #include #include namespace dx { static char glfw_error[1024] = {}; static void glfw_error_callback(int error, const char* description) { sprintf_s(glfw_error, sizeof(glfw_error), "GLFW error %d: %s", error, description); } Window::~Window() { if (m_window != nullptr) { glfwDestroyWindow(m_window); } } bool Window::Initialise(int width, int height, const char* title) { // GLFW by default creates an OpenGL context with the window. // Use GLFW_NO_API to tell it not to do so. glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); if ((m_window = glfwCreateWindow( width, height, title, /*monitor=*/NULL, /*share=*/NULL)) == nullptr) { return false; } return true; } HWND Window::GetWindowHandle() { if (!m_window) { return NULL; } return glfwGetWin32Window(m_window); } void Window::Update() { assert(m_window); glfwPollEvents(); } bool Window::ShouldClose() const { assert(m_window); return glfwWindowShouldClose(m_window) == GLFW_TRUE; } bool WindowInitialise() { glfwSetErrorCallback(glfw_error_callback); return glfwInit() == GLFW_TRUE; } void WindowTerminate() { glfwTerminate(); } const char* GetWindowError() { return glfw_error; } } // namespace dx