Skip to content
Snippets Groups Projects
Commit 96193aaf authored by Sebastian Gaida's avatar Sebastian Gaida
Browse files

[#8] add basic Window-Class

parent 3baef895
No related branches found
No related tags found
1 merge request!9Resolve "Window creation"
This commit is part of merge request !9. Comments created here will be created in the context of that merge request.
......@@ -2,6 +2,8 @@
set(vkcv_sources
${vkcv_source}/vkcv/Context.hpp
${vkcv_source}/vkcv/Context.cpp
${vkcv_source}/vkcv/Window.hpp
${vkcv_source}/vkcv/Window.cpp
${vkcv_source}/vkcv/CoreManager.hpp
${vkcv_source}/vkcv/CoreManager.cpp
)
#include <iostream>
#include <vkcv/Context.hpp>
#include <vkcv/Window.hpp>
#include <vkcv/CoreManager.hpp>
int main(int argc, const char** argv) {
vkcv::initGLFW();
vkcv::Window window = vkcv::Window::create(
"first triangle",
800,
600,
false
);
vkcv::Context context = vkcv::Context::create(
"First Triangle",
VK_MAKE_VERSION(0, 0, 1)
......@@ -23,5 +33,9 @@ int main(int argc, const char** argv) {
default: std::cout << "Unknown GPU vendor?! Either you're on an exotic system or your driver is broken..." << std::endl;
}
while (window.isWindowOpen()) {
window.pollEvents();
}
vkcv::terminateGLFW();
return 0;
}
#include "Window.hpp"
#include "CoreManager.hpp"
namespace vkcv {
Window::Window(GLFWwindow *window)
: m_window(window) {
}
Window::~Window() {
glfwDestroyWindow(m_window);
vkcv::terminateGLFW();
}
Window Window::create(const char *windowTitle, int width, int height, bool resizable) {
vkcv::initGLFW();
width = width <= 0 ? 1 : width;
height = height <= 0 ? 1 : height;
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, resizable ? GLFW_TRUE : GLFW_FALSE);
GLFWwindow *window;
window = glfwCreateWindow(width, height, windowTitle, nullptr, nullptr);
return Window(window);
}
bool Window::isWindowOpen() const {
return !glfwWindowShouldClose(m_window);
}
void Window::pollEvents() {
glfwPollEvents();
}
GLFWwindow *Window::getWindow() const {
return m_window;
}
int Window::getWidth() const {
int width;
glfwGetWindowSize(m_window, &width, nullptr);
return width;
}
int Window::getHeight() const {
int height;
glfwGetWindowSize(m_window, nullptr, &height);
return height;
}
}
\ No newline at end of file
#pragma once
#include <vulkan/vulkan.hpp>
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
namespace vkcv {
class Window final {
private:
explicit Window(GLFWwindow *window);
GLFWwindow *m_window;
public:
static Window create(const char *windowTitle, int width = -1, int height = -1, bool resizable = false);
[[nodiscard]]
bool isWindowOpen() const;
static void pollEvents();
[[nodiscard]]
GLFWwindow *getWindow() const;
[[nodiscard]]
int getWidth() const;
[[nodiscard]]
int getHeight() const;
Window &operator=(const Window &other) = delete;
Window &operator=(Window &&other) = default;
virtual ~Window();
};
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment