summaryrefslogtreecommitdiff
path: root/engine/xe_window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engine/xe_window.cpp')
-rwxr-xr-xengine/xe_window.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/engine/xe_window.cpp b/engine/xe_window.cpp
new file mode 100755
index 0000000..2721279
--- /dev/null
+++ b/engine/xe_window.cpp
@@ -0,0 +1,41 @@
+#include "xe_window.hpp"
+#include <GLFW/glfw3.h>
+#include <stdexcept>
+
+#include <stdexcept>
+
+namespace xe {
+
+ XeWindow::XeWindow(int w, int h, std::string name) : width{w}, height{h}, windowName{name} {
+ initWindow();
+ }
+
+ XeWindow::~XeWindow() {
+ glfwDestroyWindow(window);
+ glfwTerminate();
+ }
+
+ void XeWindow::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 XeWindow::createWindowSurface(VkInstance instance, VkSurfaceKHR *surface){
+ if (glfwCreateWindowSurface(instance, window, nullptr, surface) != VK_SUCCESS) {
+ throw std::runtime_error("failed to create window surface");
+ }
+ }
+
+ void XeWindow::framebufferResizeCallback(GLFWwindow *window, int width, int height){
+ auto xeWindow = reinterpret_cast<XeWindow *>(glfwGetWindowUserPointer(window));
+ xeWindow->frameBufferResized = true;
+ xeWindow->width = width;
+ xeWindow->height = height;
+ }
+
+} \ No newline at end of file