Used this tutorial to set up an immediately better structure than my last graphics project: https://youtu.be/lr93-_cC8v4
This commit is contained in:
parent
9872b960a5
commit
562f4ceda2
8 changed files with 116 additions and 41 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
# Ignore build directory
|
||||
# Ignore build directories
|
||||
build/
|
||||
.cache/
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
#define GLFW_INCLUDE_VULKAN
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#define GLM_FORCE_RADIANS
|
||||
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
||||
#include <glm/vec4.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
11
src/application.cpp
Normal file
11
src/application.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include "application.hpp"
|
||||
|
||||
namespace yave {
|
||||
|
||||
void Application::run() {
|
||||
while (!yaveWindow.shouldClose()) {
|
||||
glfwPollEvents();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace yave
|
||||
17
src/application.hpp
Normal file
17
src/application.hpp
Normal file
|
|
@ -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
|
||||
16
src/main.cpp
Normal file
16
src/main.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include "application.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
25
src/yave_window.cpp
Normal file
25
src/yave_window.cpp
Normal file
|
|
@ -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
|
||||
28
src/yave_window.hpp
Normal file
28
src/yave_window.hpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#define GLFW_INCLUDE_VULKAN
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
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); }
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue