minecraftvulkan/engine/xe_window.cpp
2022-09-24 21:16:13 -04:00

41 lines
No EOL
1.1 KiB
C++
Executable file

#include "xe_window.hpp"
#include <GLFW/glfw3.h>
#include <stdexcept>
#include <stdexcept>
namespace xe {
Window::Window(int w, int h, std::string name) : width{w}, height{h}, windowName{name} {
initWindow();
}
Window::~Window() {
glfwDestroyWindow(window);
glfwTerminate();
}
void Window::initWindow() {
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);
}
void Window::createWindowSurface(VkInstance instance, VkSurfaceKHR *surface){
if (glfwCreateWindowSurface(instance, window, nullptr, surface) != VK_SUCCESS) {
throw std::runtime_error("failed to create window surface");
}
}
void Window::framebufferResizeCallback(GLFWwindow *window, int width, int height){
auto xeWindow = reinterpret_cast<Window *>(glfwGetWindowUserPointer(window));
xeWindow->frameBufferResized = true;
xeWindow->width = width;
xeWindow->height = height;
}
}