diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..100b938 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +README \ No newline at end of file diff --git a/Makefile b/Makefile index 08551de..820991d 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ CFLAGS = -std=c++17 -O2 LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi -VulkanTest: main.cpp - g++ $(CFLAGS) -o VulkanTest main.cpp $(LDFLAGS) +VulkanTest: *.cpp *.hpp + g++ $(CFLAGS) -o a.out *.cpp $(LDFLAGS) .PHONY: test clean -test: VulkanTest - ./VulkanTest +test: a.out + ./a.out clean: - rm -f VulkanTest \ No newline at end of file + rm -f a.out diff --git a/VulkanTest b/VulkanTest deleted file mode 100755 index c34e554..0000000 Binary files a/VulkanTest and /dev/null differ diff --git a/a.out b/a.out new file mode 100755 index 0000000..0af150c Binary files /dev/null and b/a.out differ diff --git a/cve_window.cpp b/cve_window.cpp new file mode 100644 index 0000000..5b2d6cd --- /dev/null +++ b/cve_window.cpp @@ -0,0 +1,22 @@ +#include "cve_window.hpp" + +namespace cve { + CveWindow::CveWindow(int w, int h, std::string name) : width{w}, + height{h}, windowName{name} { + initWindow(); + } + + CveWindow::~CveWindow() { + glfwDestroyWindow(window); + glfwTerminate(); + } + + void CveWindow::initWindow() { + glfwInit(); + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + + window = glfwCreateWindow(width, height, + windowName.c_str(), nullptr, nullptr); + } +} diff --git a/cve_window.hpp b/cve_window.hpp new file mode 100644 index 0000000..f522ea2 --- /dev/null +++ b/cve_window.hpp @@ -0,0 +1,28 @@ +#pragma once + +#define GLFW_INCLUDE_VULKAN +#include + +#include +namespace cve { + +class CveWindow { + public: + CveWindow(int w, int h, std::string name); + ~CveWindow(); + + CveWindow(const CveWindow &) = delete; + CveWindow &operator=(const CveWindow &) = delete; + + bool shouldClose() { return glfwWindowShouldClose(window); }; + private: + void initWindow(); + + const int width; + const int height; + + std::string windowName; + GLFWwindow *window; +}; + +} diff --git a/first_app.cpp b/first_app.cpp new file mode 100644 index 0000000..4a87526 --- /dev/null +++ b/first_app.cpp @@ -0,0 +1,9 @@ +#include "first_app.hpp" + +namespace cve { + void FirstApp::run() { + while (!cveWindow.shouldClose()) { + glfwPollEvents(); + } + } +} diff --git a/first_app.hpp b/first_app.hpp new file mode 100644 index 0000000..e4bab1b --- /dev/null +++ b/first_app.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "cve_window.hpp" + +namespace cve { + class FirstApp { + public: + static constexpr int WIDTH = 800; + static constexpr int HEIGHT = 600; + + void run(); + private: + CveWindow cveWindow{WIDTH, HEIGHT, "Hello Vulkan!"}; + }; +} diff --git a/helloWorld.cpp b/helloWorld.cpp deleted file mode 100644 index a7bff40..0000000 --- a/helloWorld.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include - -using namespace std; - -int main() { - printf("Hello, World!\n"); - return 0; -} \ No newline at end of file diff --git a/main.cpp b/main.cpp index b8f6e6f..18ef125 100644 --- a/main.cpp +++ b/main.cpp @@ -1,35 +1,19 @@ -#define GLFW_INCLUDE_VULKAN -#include - -#define GLM_FORCE_RADIANS -#define GLM_FORCE_DEPTH_ZERO_TO_ONE -#include -#include +#include "first_app.hpp" +// std +#include #include +#include int main() { - glfwInit(); + cve::FirstApp app{}; - glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); - GLFWwindow* window = glfwCreateWindow(800, 600, "Vulkan window", nullptr, nullptr); + try { + app.run(); + } catch (const std::exception &e) { + std::cerr << e.what() << '\n'; + return EXIT_FAILURE; + } - uint32_t extensionCount = 0; - vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr); - - std::cout << extensionCount << " extensions supported\n"; - - glm::mat4 matrix; - glm::vec4 vec; - auto test = matrix * vec; - - while(!glfwWindowShouldClose(window)) { - glfwPollEvents(); - } - - glfwDestroyWindow(window); - - glfwTerminate(); - - return 0; -} \ No newline at end of file + return EXIT_SUCCESS; +}