From 562f4ceda2691fe19b0dfe1b9a7d3b7bf37c9e9e Mon Sep 17 00:00:00 2001 From: Warwick Date: Sat, 29 Oct 2022 14:34:38 +0100 Subject: [PATCH] Used this tutorial to set up an immediately better structure than my last graphics project: https://youtu.be/lr93-_cC8v4 --- .gitignore | 3 ++- CMakeLists.txt | 21 +++++++++++++++++---- VulkanTest.cpp | 36 ------------------------------------ src/application.cpp | 11 +++++++++++ src/application.hpp | 17 +++++++++++++++++ src/main.cpp | 16 ++++++++++++++++ src/yave_window.cpp | 25 +++++++++++++++++++++++++ src/yave_window.hpp | 28 ++++++++++++++++++++++++++++ 8 files changed, 116 insertions(+), 41 deletions(-) delete mode 100644 VulkanTest.cpp create mode 100644 src/application.cpp create mode 100644 src/application.hpp create mode 100644 src/main.cpp create mode 100644 src/yave_window.cpp create mode 100644 src/yave_window.hpp diff --git a/.gitignore b/.gitignore index c6b9d55..2bc9dca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -# Ignore build directory +# Ignore build directories build/ +.cache/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 91d3c68..00d6161 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,21 @@ cmake_minimum_required(VERSION 3.16) -project(yave) #Yet Another Vulkan Engine +project(yave + VERSION 0 + DESCRIPTION "Yet Another Vulkan Engine" + HOMEPAGE_URL "https://git.warwicknew.xyz/yave/" + LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 17) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_CXX_CLANG_TIDY) + +file(GLOB_RECURSE SOURCE_FILES + ${CMAKE_SOURCE_DIR}/src/*.c + ${CMAKE_SOURCE_DIR}/src/*.cpp) + +file(GLOB_RECURSE HEADER_FILES + ${CMAKE_SOURCE_DIR}/src/*.h + ${CMAKE_SOURCE_DIR}/src/*.hpp) find_package(Vulkan REQUIRED) find_package(glfw3 REQUIRED) @@ -11,10 +25,9 @@ find_package(glm REQUIRED) include_directories( ${Vulkan_INCLUDE_DIRS} ${GLFW_INCLUDE_DIRS} - ${GLM_INCLUDE_DIRS} - ) + ${GLM_INCLUDE_DIRS}) -add_executable(${PROJECT_NAME} VulkanTest.cpp) +add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES}) target_link_libraries(${PROJECT_NAME} PUBLIC ${GLFW_LIBRARIES} diff --git a/VulkanTest.cpp b/VulkanTest.cpp deleted file mode 100644 index d207a63..0000000 --- a/VulkanTest.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#define GLFW_INCLUDE_VULKAN -#include - -#define GLM_FORCE_RADIANS -#define GLM_FORCE_DEPTH_ZERO_TO_ONE -#include -#include - -#include - -int main() { - glfwInit(); - - glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); - GLFWwindow* window = glfwCreateWindow(800, 600, "Vulkan window", nullptr, nullptr); - - 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; -} - diff --git a/src/application.cpp b/src/application.cpp new file mode 100644 index 0000000..f355a38 --- /dev/null +++ b/src/application.cpp @@ -0,0 +1,11 @@ +#include "application.hpp" + +namespace yave { + +void Application::run() { + while (!yaveWindow.shouldClose()) { + glfwPollEvents(); + } +} + +} // namespace yave diff --git a/src/application.hpp b/src/application.hpp new file mode 100644 index 0000000..604b2c2 --- /dev/null +++ b/src/application.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include "yave_window.hpp" + +namespace yave { +class Application { + public: + static constexpr int WIDTH = 800; + static constexpr int HEIGHT = 600; + + void run(); + + private: + YaveWindow yaveWindow{WIDTH, HEIGHT, "Hello Vulkan!"}; + +}; +} // namespace yave diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..4205da3 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,16 @@ +#include "application.hpp" + +#include +#include + +int main() { + yave::Application app{}; + + try { + app.run(); + } catch (const std::exception &e) { + std::cerr << e.what() << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/src/yave_window.cpp b/src/yave_window.cpp new file mode 100644 index 0000000..d077e8b --- /dev/null +++ b/src/yave_window.cpp @@ -0,0 +1,25 @@ +#include "yave_window.hpp" + +namespace yave { + +YaveWindow::YaveWindow(int w, int h, std::string name) + : width{w}, height{h}, windowName{name} { + initWindow(); +} + +YaveWindow::~YaveWindow() { + glfwDestroyWindow(window); + glfwTerminate(); +} + +void YaveWindow::initWindow() { + glfwInit(); + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); // Don't use OpenGL + glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // Vulkan doesn't like to be resized + + // Create window with no OpenGL context + window = + glfwCreateWindow(width, height, windowName.c_str(), nullptr, nullptr); +} + +} // namespace yave diff --git a/src/yave_window.hpp b/src/yave_window.hpp new file mode 100644 index 0000000..0d232f6 --- /dev/null +++ b/src/yave_window.hpp @@ -0,0 +1,28 @@ +#pragma once + +#define GLFW_INCLUDE_VULKAN +#include + +#include + +namespace yave { + +class YaveWindow { + private: + GLFWwindow *window; + + void initWindow(); + + const int width; + const int height; + std::string windowName; + + public: + YaveWindow(int w, int h, std::string name); + ~YaveWindow(); + + bool shouldClose() { return glfwWindowShouldClose(window); } + +}; + +}