3#define STB_IMAGE_IMPLEMENTATION
10 if (glfwInit() == GLFW_FALSE) {
11 throw std::runtime_error(
"Failed to initialize GLFW");
14 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
15 glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
17 GLFWwindow *window = glfwCreateWindow(
static_cast<int>(width),
static_cast<int>(height), title.c_str(),
nullptr,
nullptr);
18 if (window ==
nullptr) {
20 throw std::runtime_error(
"Failed to create window");
22 glfwSetWindowUserPointer(window,
this);
29 if (glfwCreateWindowSurface(instance, m_window,
nullptr, surface) != VK_SUCCESS) {
30 throw std::runtime_error(
"Failed to create window surface");
36 auto *app =
static_cast<Window *
>(glfwGetWindowUserPointer(window));
38 app->m_width =
static_cast<uint32_t
>(width);
39 app->m_height =
static_cast<uint32_t
>(height);
44 GLFWmonitor* primaryMonitor = glfwGetPrimaryMonitor();
45 const GLFWvidmode* mode = glfwGetVideoMode(primaryMonitor);
64 int width, height, channels;
66 if (
unsigned char *pixels = stbi_load(path.c_str(), &width, &height, &channels, 4)) {
72 glfwSetWindowIcon(m_window, 1, &icon);
73 stbi_image_free(pixels);
75 throw std::runtime_error(
"Failed to load window icon with path: " + path);
This file contains the Window class.
void createWindowSurface(VkInstance instance, VkSurfaceKHR *surface) const
GLFWwindow * createWindow(uint32_t width, uint32_t height, const std::string &title)
static void framebufferResizeCallback(GLFWwindow *window, int width, int height)
bool m_framebufferResized
void setFullscreen(bool fullscreen, uint32_t width, uint32_t height)
void setWindowIcon(const std::string &path)