40 lines
1.1 KiB
C++
40 lines
1.1 KiB
C++
#include "cve_window.hpp"
|
|
|
|
#include <stdexcept>
|
|
|
|
namespace cve {
|
|
CveWindow::CveWindow(int w, int h, std::string name) : width{w},
|
|
height{h}, windowName{name} {
|
|
initWindow();
|
|
}
|
|
|
|
CveWindow::~CveWindow() {
|
|
glfwDestroyWindow(window);
|
|
glfwTerminate();
|
|
}
|
|
|
|
void CveWindow::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, framebufferResizedCallback);
|
|
}
|
|
|
|
void CveWindow::createWindowSurface(VkInstance instance, VkSurfaceKHR *surface) {
|
|
if (glfwCreateWindowSurface(instance, window, nullptr, surface) != VK_SUCCESS) {
|
|
throw std::runtime_error("Failed to create window surface");
|
|
}
|
|
}
|
|
|
|
void CveWindow::framebufferResizedCallback(GLFWwindow *window, int width, int height) {
|
|
auto cveWindow = reinterpret_cast<CveWindow *>(glfwGetWindowUserPointer(window));
|
|
cveWindow->framebufferResized = true;
|
|
cveWindow->width = width;
|
|
cveWindow->height = height;
|
|
}
|
|
}
|