Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dev/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ if (NOT TINYOBJ_PATH)
message(STATUS "TINYOBJ_PATH not specified in .env.cmake, using external/tinyobjloader")
set(TINYOBJ_PATH external/tinyobjloader)
endif()
file(GLOB_RECURSE SOURCES "../src/*.cpp")

file(GLOB_RECURSE SOURCES "../src1/*.cpp")

add_executable(${PROJECT_NAME} ${SOURCES})

target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)
Expand All @@ -88,7 +88,7 @@ if (WIN32)
endif()

target_include_directories(${PROJECT_NAME} PUBLIC
../src
../src1
${Vulkan_INCLUDE_DIRS}
${TINYOBJ_PATH}
${GLFW_INCLUDE_DIRS}
Expand Down
Empty file added src/collision/collision.cpp
Empty file.
Empty file added src/collision/collision.h
Empty file.
Empty file added src/input/input.cpp
Empty file.
Empty file added src/input/input.h
Empty file.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <iostream>
#include <cstring>
#include <cstdlib>
#include "./render/AvantGardeRender.hpp"
#include "./renderer/vulkan/AvantGardeRender.hpp"


int main() {
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion src/shaders/shader.vert → src/renderer/shaders/shader.vert
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ layout(binding = 0) uniform UniformBufferObject {
mat4 proj;
} ubo;

layout(std140, binding = 1) readonly buffer storageBuffer {
mat4 model[];
} ObjectData;

layout(location = 0) in vec2 inPosition;
layout(location = 1) in vec3 inColor;

layout(location = 0) out vec3 fragColor;

void main() {
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 0.0, 1.0);
gl_Position = ubo.proj * ubo.view * ObjectData.model[gl_InstanceIndex] * vec4(inPosition, 0.0, 1.0);
fragColor = inColor;
}

File renamed without changes.
73 changes: 70 additions & 3 deletions src/render/mainLoop.cpp → src/renderer/vulkan/mainLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,71 @@
#include <stdexcept>
#include "AvantGardeRender.hpp"

bool KEY_W = false;
bool KEY_S = false;
bool KEY_A = false;
bool KEY_D = false;

int height = 0;
float offset_y = 0.0f;
float offset_x = 0.0f;

void GLFW_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
glfwSetWindowShouldClose(window, GLFW_TRUE);
}

if (key == GLFW_KEY_W && action == GLFW_PRESS) {
KEY_W = true;
std::cout << 1 << std::endl;
}
if (key == GLFW_KEY_W && action == GLFW_RELEASE) {
KEY_W = false;
std::cout << 0 << std::endl;
}

if (key == GLFW_KEY_S && action == GLFW_PRESS) {
KEY_S = true;
}
if (key == GLFW_KEY_S && action == GLFW_RELEASE) {
KEY_S = false;
}

if (key == GLFW_KEY_A && action == GLFW_PRESS) {
KEY_A = true;
}
if (key == GLFW_KEY_A && action == GLFW_RELEASE) {
KEY_A = false;
}

if (key == GLFW_KEY_D && action == GLFW_PRESS) {
KEY_D = true;
}
if (key == GLFW_KEY_D && action == GLFW_RELEASE) {
KEY_D = false;
}
}

void AvantGardeRender::mainLoop() {
glfwSetKeyCallback(window, GLFW_KeyCallback);

while (!glfwWindowShouldClose(window)) {
if (KEY_W) {
std::cout << "W" << std::endl;
offset_y += 10.0f;
}
if (KEY_S) {
std::cout << "S" << std::endl;
offset_y -= 10.0f;
}
if (KEY_A) {
std::cout << "A" << std::endl;
offset_x += 10.0f;
}
if (KEY_D) {
std::cout << "D" << std::endl;
offset_x -= 10.0f;
}
glfwPollEvents();
drawFrame();
}
Expand Down Expand Up @@ -83,14 +145,19 @@ void AvantGardeRender::drawFrame() {

void AvantGardeRender::updateUniformBuffer(uint32_t currentImage) {
static auto startTime = std::chrono::high_resolution_clock::now();

auto currentTime = std::chrono::high_resolution_clock::now();
float time = std::chrono::duration<float, std::chrono::seconds::period>(currentTime - startTime).count();

// UniformBufferObject ubo{};
// ubo.model = glm::rotate(glm::mat4(1.0f), time * glm::radians(60.0f), glm::vec3(0.0f, 0.0f, 1.0f));
// ubo.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
// ubo.proj = glm::perspective(glm::radians(45.0f), swapChainExtent.width / (float) swapChainExtent.height, 0.1f, 10.0f);
// ubo.proj[1][1] *= -1;

UniformBufferObject ubo{};
ubo.model = glm::rotate(glm::mat4(1.0f), time * glm::radians(90.0f), glm::vec3(0.0f, 0.0f, 1.0f));
ubo.model = glm::rotate(glm::mat4(1.0f), time * glm::radians(60.0f), glm::vec3(0.0f, 0.0f, 1.0f));
ubo.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
ubo.proj = glm::perspective(glm::radians(45.0f), swapChainExtent.width / (float) swapChainExtent.height, 0.1f, 10.0f);
ubo.proj = glm::perspective(glm::radians(45.0f), (swapChainExtent.width + offset_y) / ((float) swapChainExtent.height + offset_x), 0.1f, 10.0f);
ubo.proj[1][1] *= -1;

memcpy(uniformBuffersMapped[currentImage], &ubo, sizeof(ubo));
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added src/sound/sound.cpp
Empty file.
Empty file added src/sound/sound.h
Empty file.
Empty file added src/sys/sys.cpp
Empty file.
Empty file added src/sys/sys.h
Empty file.
Empty file added src/ui/ui_game.cpp
Empty file.
Empty file added src/ui/ui_game.h
Empty file.
Empty file added src/ui/ui_home.cpp
Empty file.
Empty file added src/ui/ui_home.h
Empty file.
4 changes: 4 additions & 0 deletions src1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GetIntoGameDev Tutorial Playlist: https://www.youtube.com/playlist?list=PLn3eTxaOtL2NH5nbPHMK7gE07SqhcAjmk
His Repository: https://github.com/amengede/getIntoGameDev/tree/main/vulkan%202022

Using this tutorial to learn and refactor. We really liked his formatting and explanation comparing to the Khronos Vulkan tutorial.
7 changes: 7 additions & 0 deletions src1/engine/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// config.h loads all the libraries
#pragma once

// #include <vulkan/vulkan.h> // c api
#include <vulkan/vulkan.hpp> // cpp api, static load vulkan

#include <iostream>
50 changes: 50 additions & 0 deletions src1/engine/engine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "engine.h"
#include "instance.h"
#include <iostream>

const char* projectName = "AvantGarde";

Engine::Engine() {

if (debugMode) {
std::cout << "Making a graphics engine...\n";
}

build_glfw_window();

make_instance();
}

void Engine::build_glfw_window() {
// init glfw
glfwInit();

glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);

// window resizing, breaks swapchain, disabled for now
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);

if ((window = glfwCreateWindow(width, height, projectName, nullptr, nullptr))) {
if (debugMode) {
std::cout << "Success: glfw window creation, width: " << width << ", height: " << height << '\n';
}
} else {
if (debugMode) {
std::cout << "Failed: glfw window creation\n";
}
}
}

void Engine::make_instance() {
instance = vkInit::make_instance(debugMode, projectName);
}

Engine::~Engine() {
if (debugMode) {
std::cout << "Closing Engine...\n";
}

instance.destroy();

glfwTerminate();
}
31 changes: 31 additions & 0 deletions src1/engine/engine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once
// #define GLFW_INCLUDE_VULKAN // includes the vulkan headers
#include <GLFW/glfw3.h>

#include "config.h"
class Engine {

public:

Engine();

~Engine();

private:

bool debugMode = true; // to print debug messages in functions

// glfw parameters
int width { 640 };
int height { 480 };
GLFWwindow* window { nullptr };

// vulkan instance
vk::Instance instance {nullptr };

// glfw setup
void build_glfw_window();

// instance setup
void make_instance();
};
68 changes: 68 additions & 0 deletions src1/engine/instance.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#pragma once

// namespace for createion functions/definitions
namespace vkInit {
vk::Instance make_instance(bool debug, const char* applicationName) {
if (debug) {
std::cout << "Making an instance...\n";
}

uint32_t version { 0 };
vkEnumerateInstanceVersion(&version);
if (debug) {
std::cout << "System can support vulkan variant: " << VK_API_VERSION_VARIANT(version)
<< ", Major: " << VK_API_VERSION_MAJOR(version)
<< ", Minor: " << VK_API_VERSION_MINOR(version)
<< ", Patch: " << VK_API_VERSION_PATCH(version) << '\n';
}

version &= ~(0xFFFU); // set the patch to 0 for best compatibility/stability
// ^^^ lower 12 bytes are patch

// or use VK_MAKE_API_VERSION(variant, major, minor, patch)
version = VK_MAKE_API_VERSION(0, 1, 0, 0);

vk::ApplicationInfo appInfo = vk::ApplicationInfo(
applicationName,
version,
"text",
version,
version
);

uint32_t glfwExtensionCount = 0;
const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);

std::vector<const char*> extensions(glfwExtensions, glfwExtensions + glfwExtensionCount);

if (debug) {
std::cout << "Extensions to be requested: \n";
for (const char* extensionName : extensions) {
std::cout << "\t\"" << extensionName << "\"\n";
}
}


vk::InstanceCreateInfo createInfo = vk::InstanceCreateInfo(
vk::InstanceCreateFlags().
&appInfo,
0, nullptr, // enabled layers
static_cast<uint32_t>(extension.size()), extensions,data() // enabled extensions
);

try {
return vk::createInstance(createInfo, nullptr);
}
catch (vk::SystemError err) {
if (debug) {
std::cout << "Failed: create instance"
}
}

if (debug) {
std::cout << "Success: instance creation"
}

return nullptr;
}
}
Binary file added src1/graphics_pipeline_notes.pdf
Binary file not shown.
9 changes: 9 additions & 0 deletions src1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "./engine/engine.h"

int main() {
Engine* graphicsEngine = new Engine();

delete graphicsEngine;

return 0;
}