vktutorial/hk_window.cpp

47 lines
1.3 KiB
C++
Raw Normal View History

2024-02-21 13:28:50 +08:00
#include "hk_window.hpp"
// std
#include <stdexcept>
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);
2024-02-21 15:42:32 +08:00
glfwSetWindowUserPointer(m_window, this);
glfwSetFramebufferSizeCallback(m_window, framebufferResizeCallback);
}
void Window::framebufferResizeCallback(GLFWwindow* window, int width, int height)
{
auto hkWindow = reinterpret_cast<Window*>(glfwGetWindowUserPointer(window));
hkWindow->m_framebufferResized = true;
hkWindow->m_width = width;
hkWindow->m_height = height;
2024-02-21 13:28:50 +08:00
}
}