vengine  0.1.0
3D graphics engine made with Vulkan
Loading...
Searching...
No Matches
window.cpp
Go to the documentation of this file.
1#include <stdexcept>
2
3#include "VEngine/Window.hpp"
4
5GLFWwindow* ven::Window::createWindow(const uint32_t width, const uint32_t height, const std::string &title)
6{
7 if (glfwInit() == GLFW_FALSE) {
8 throw std::runtime_error("Failed to initialize GLFW");
9 }
10
11 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
12 glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
13
14 GLFWwindow *window = glfwCreateWindow(static_cast<int>(width), static_cast<int>(height), title.c_str(), nullptr, nullptr);
15 if (window == nullptr) {
16 glfwTerminate();
17 throw std::runtime_error("Failed to create window");
18 }
19 glfwSetWindowUserPointer(window, this);
20 glfwSetFramebufferSizeCallback(window, framebufferResizeCallback);
21 return window;
22}
23
24void ven::Window::createWindowSurface(const VkInstance instance, VkSurfaceKHR *surface) const
25{
26 if (glfwCreateWindowSurface(instance, m_window, nullptr, surface) != VK_SUCCESS) {
27 throw std::runtime_error("Failed to create window surface");
28 }
29}
30
31void ven::Window::framebufferResizeCallback(GLFWwindow *window, const int width, const int height)
32{
33 auto *app = static_cast<Window *>(glfwGetWindowUserPointer(window));
34 app->m_framebufferResized = true;
35 app->m_width = static_cast<uint32_t>(width);
36 app->m_height = static_cast<uint32_t>(height);
37}
This file contains the Window class.
void createWindowSurface(VkInstance instance, VkSurfaceKHR *surface) const
Definition window.cpp:24
GLFWwindow * createWindow(uint32_t width, uint32_t height, const std::string &title)
Definition window.cpp:5
static void framebufferResizeCallback(GLFWwindow *window, int width, int height)
Definition window.cpp:31
bool m_framebufferResized
Definition Window.hpp:41