From e0b8a0c08b19ac90a8b5c069db4c4e3e6d9d5bd6 Mon Sep 17 00:00:00 2001 From: bwbl Date: Thu, 14 Aug 2025 03:50:24 +0200 Subject: [PATCH] added the exemple main and base shaders --- .gitignore | 4 ++++ .gitmodules | 3 +++ main.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ shaders/frag.spv | 9 ++++++++ shaders/vert.spv | 20 ++++++++++++++++ 5 files changed, 96 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 main.cpp create mode 100644 shaders/frag.spv create mode 100644 shaders/vert.spv diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0906c29 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/target +GLFW/ +a.out +compile.sh \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..353b3c8 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "GLFW"] + path = GLFW + url = https://github.com/glfw/glfw.git diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e2aba60 --- /dev/null +++ b/main.cpp @@ -0,0 +1,60 @@ +#define GLFW_INCLUDE_VULKAN +#include + +#include +#include +#include + +const uint32_t WIDTH = 800; +const uint32_t HEIGHT = 600; + +class HelloTriangleApplication { +public: + void run() { + initWindow(); + initVulkan(); + mainLoop(); + cleanup(); + } + +private: + GLFWwindow* window; + + void initWindow() { + glfwInit(); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + + window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr); + } + + void initVulkan() { + + } + + void mainLoop() { + while (!glfwWindowShouldClose(window)) { + glfwPollEvents(); + } + } + + void cleanup() { + glfwDestroyWindow(window); + + glfwTerminate(); + } +}; + +int main() { + HelloTriangleApplication app; + + try { + app.run(); + } catch (const std::exception& e) { + std::cerr << e.what() << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/shaders/frag.spv b/shaders/frag.spv new file mode 100644 index 0000000..7c5b0e7 --- /dev/null +++ b/shaders/frag.spv @@ -0,0 +1,9 @@ +#version 450 + +layout(location = 0) in vec3 fragColor; + +layout(location = 0) out vec4 outColor; + +void main() { + outColor = vec4(fragColor, 1.0); +} diff --git a/shaders/vert.spv b/shaders/vert.spv new file mode 100644 index 0000000..f5b2f8d --- /dev/null +++ b/shaders/vert.spv @@ -0,0 +1,20 @@ +#version 450 + +layout(location = 0) out vec3 fragColor; + +vec2 positions[3] = vec2[]( + vec2(0.0, -0.5), + vec2(0.5, 0.5), + vec2(-0.5, 0.5) +); + +vec3 colors[3] = vec3[]( + vec3(1.0, 0.0, 0.0), + vec3(0.0, 1.0, 0.0), + vec3(0.0, 0.0, 1.0) +); + +void main() { + gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); + fragColor = colors[gl_VertexIndex]; +}