-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuzumeWindow.cpp
More file actions
44 lines (39 loc) · 1.34 KB
/
Copy pathSuzumeWindow.cpp
File metadata and controls
44 lines (39 loc) · 1.34 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
39
40
41
42
43
44
#include "SuzumeWindow.hpp"
#include <stdexcept>
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include <vulkan/vulkan.h>
namespace Suzume {
void SuzumeWindow::framebufferResizeCallback(GLFWwindow *window, int width,
int height) {
auto suzumeWindow =
reinterpret_cast<SuzumeWindow *>(glfwGetWindowUserPointer(window));
suzumeWindow->framebufferResized = true;
suzumeWindow->width = width;
suzumeWindow->height = height;
}
SuzumeWindow::SuzumeWindow(int w, int h, const std::string &title)
: width(w), height(h), windowName(title), window(nullptr) {
initwindow();
}
SuzumeWindow::~SuzumeWindow() {
glfwDestroyWindow(window);
glfwTerminate();
}
void SuzumeWindow::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 SuzumeWindow::createWindowSurface(VkInstance instance,
VkSurfaceKHR *surface) {
if (glfwCreateWindowSurface(instance, window, nullptr, surface) !=
VK_SUCCESS) {
throw std::runtime_error("failed to create window surface!");
}
}
} // namespace Suzume