minecraftvulkan/engine/xe_window.cpp

37 lines
1.1 KiB
C++
Raw Normal View History

2022-09-19 01:20:51 +00:00
#include "xe_window.hpp"
namespace xe {
2022-09-25 01:16:13 +00:00
Window::Window(int w, int h, std::string name) : width{w}, height{h}, windowName{name} {
2022-09-19 01:20:51 +00:00
initWindow();
}
2022-09-25 01:16:13 +00:00
Window::~Window() {
2022-09-19 01:20:51 +00:00
glfwDestroyWindow(window);
glfwTerminate();
}
2022-09-25 01:16:13 +00:00
void Window::initWindow() {
2022-09-19 01:20:51 +00:00
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
window = glfwCreateWindow(width, height, windowName.c_str(), nullptr, nullptr);
glfwSetWindowUserPointer(window, this);
glfwSetFramebufferSizeCallback(window, framebufferResizeCallback);
}
2022-09-25 01:16:13 +00:00
void Window::createWindowSurface(VkInstance instance, VkSurfaceKHR *surface){
2022-09-19 01:20:51 +00:00
if (glfwCreateWindowSurface(instance, window, nullptr, surface) != VK_SUCCESS) {
throw std::runtime_error("failed to create window surface");
}
}
2022-09-25 01:16:13 +00:00
void Window::framebufferResizeCallback(GLFWwindow *window, int width, int height){
auto xeWindow = reinterpret_cast<Window *>(glfwGetWindowUserPointer(window));
2022-09-19 01:20:51 +00:00
xeWindow->frameBufferResized = true;
xeWindow->width = width;
xeWindow->height = height;
}
}