commit 604a8b3df897781a5de8201ea1576ccfeb67a1cf Author: Nigel Date: Fri Oct 15 22:14:57 2021 +0100 Initial commit diff --git a/Hello_triangle/Makefile b/Hello_triangle/Makefile new file mode 100644 index 0000000..92c7f60 --- /dev/null +++ b/Hello_triangle/Makefile @@ -0,0 +1,15 @@ +CFLAGS = -std=c++17 -O2 +LDFLAGS = -lglfw3 -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi + +VulkanTest: main.cpp + g++ $(CFLAGS) -o VulkanTest main.cpp $(LDFLAGS) + +.PHONY: test clean + +test: VulkanTest + ./VulkanTest + +clean: + rm -f VulkanTest +# For information on Makefile's check +# https://makefiletutorial.com diff --git a/Hello_triangle/VulkanTest b/Hello_triangle/VulkanTest new file mode 100755 index 0000000..ad5442c Binary files /dev/null and b/Hello_triangle/VulkanTest differ diff --git a/Hello_triangle/main.cpp b/Hello_triangle/main.cpp new file mode 100644 index 0000000..efe924f --- /dev/null +++ b/Hello_triangle/main.cpp @@ -0,0 +1,103 @@ +/* + Following the vulkan tutorial on : + https://vulkan-tutorial.com/en/Drawing_a_triangle/Setup/Instance + +*/ + + + + +#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; + VkInstance instance; + + void initWindow(){ + glfwInit(); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); + + window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr); + } + + void initVulkan(){ + createInstance(); + } + + + + void createInstance(){ + VkApplicationInfo appInfo{}; + appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + appInfo.pApplicationName = "Hello Triangle"; + appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0); + appInfo.pEngineName = "No Engine"; + appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0); + appInfo.apiVersion = VK_API_VERSION_1_0; + + VkInstanceCreateInfo createInfo{}; + createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + createInfo.pApplicationInfo = &appInfo; + + uint32_t glfwExtesionCount = 0; + const char** glfwExtensions; + + glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtesionCount); + + createInfo.enabledExtensionCount = glfwExtesionCount; + createInfo.ppEnabledExtensionNames = glfwExtensions; + createInfo.enabledLayerCount = 0; + + if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS ){ + throw std::runtime_error("Failed to create instance!"); + } + + + + } + + 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; + +} \ No newline at end of file diff --git a/Hello_vulkan/Makefile b/Hello_vulkan/Makefile new file mode 100644 index 0000000..25a5adb --- /dev/null +++ b/Hello_vulkan/Makefile @@ -0,0 +1,13 @@ +CFLAGS = -std=c++17 -O2 +LDFLAGS = -lglfw3 -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi + +VulkanTest: main.cpp + g++ $(CFLAGS) -o VulkanTest main.cpp $(LDFLAGS) + +.PHONY: test clean + +test: VulkanTest + ./VulkanTest + +clean: + rm -f VulkanTest diff --git a/Hello_vulkan/VulkanTest b/Hello_vulkan/VulkanTest new file mode 100755 index 0000000..6a825d0 Binary files /dev/null and b/Hello_vulkan/VulkanTest differ diff --git a/Hello_vulkan/main.cpp b/Hello_vulkan/main.cpp new file mode 100644 index 0000000..879f78a --- /dev/null +++ b/Hello_vulkan/main.cpp @@ -0,0 +1,36 @@ +#define GLFW_INCLUDE_VULKAN +#include + +#define GLM_FORCE_RADIANS +#define GLM_FORCE_DPETH_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; +} \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..22d50b0 --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +# Vulkan API demo's + +![Vulkan](https://www.vulkan.org/user/pages/01.home/Vulkan-Wide.png) \ No newline at end of file