#include "hk_window.hpp" // std #include namespace hk { Window::Window(int w, int h, const std::string& name) : m_width(w), m_height(h), m_windowName(name) { initWindow(); } Window::~Window() { glfwDestroyWindow(m_window); glfwTerminate(); } void Window::createWindowSurface(VkInstance instance, VkSurfaceKHR *surface) { if (glfwCreateWindowSurface(instance, m_window, nullptr, surface) != VK_SUCCESS) { throw std::runtime_error("failed to create window surface!"); } } void Window::initWindow() { glfwInit(); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); m_window = glfwCreateWindow(m_width, m_height, m_windowName.c_str(), nullptr, nullptr); glfwSetWindowUserPointer(m_window, this); glfwSetFramebufferSizeCallback(m_window, framebufferResizeCallback); } void Window::framebufferResizeCallback(GLFWwindow* window, int width, int height) { auto hkWindow = reinterpret_cast(glfwGetWindowUserPointer(window)); hkWindow->m_framebufferResized = true; hkWindow->m_width = width; hkWindow->m_height = height; } }