-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHexWindow.cpp
More file actions
38 lines (30 loc) · 1.08 KB
/
HexWindow.cpp
File metadata and controls
38 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "HexWindow.h"
#include <stdexcept>
namespace hex {
HexWindow::HexWindow(int w, int h, std::string name) : width{w}, height{h}, windowName{name} {
initWindow();
}
HexWindow::~HexWindow() {
glfwDestroyWindow(window);
glfwTerminate();
}
void HexWindow::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 HexWindow::createWindowSurface(VkInstance instance, VkSurfaceKHR *surface) {
if (glfwCreateWindowSurface(instance, window, nullptr, surface) != VK_SUCCESS) {
throw std::runtime_error("Failed to create window surface");
}
}
void HexWindow::framebufferResizeCallback(GLFWwindow *window, int width, int height) {
auto hexWindow = reinterpret_cast<HexWindow*>(glfwGetWindowUserPointer(window));
hexWindow->framebufferResize = true;
hexWindow->width = width;
hexWindow->height = height;
}
}