Featured Article

Vulkan Hello Triangle Tutorial: Mastering the Basics

Cynthia Jul 13, 2026

Embarking on your Vulkan graphics and computing journey? Let's get started by creating a simple "Hello, Triangle!" program. This tutorial promises a hands-on, step-by-step guide, transforming you from a Vulkan beginner into a confident developer ready to explore more graphics API wonders.

Easy How to Draw a Volcano Tutorial Video and Volcano Coloring Page
Easy How to Draw a Volcano Tutorial Video and Volcano Coloring Page

First, we'll set up our environment, then dive into creating and rendering our first 3D shape - a triangle. By the end, you'll have a solid foundation in Vulkan, ready to build upon with more complex graphics and computing tasks.

TUTORIAL| Triangle Scarf Pattern BY BELINA | Beginner Friendly
TUTORIAL| Triangle Scarf Pattern BY BELINA | Beginner Friendly

Setting Up the Development Environment

Before we begin, ensure you have the necessary tools installed: Vulkan SDK, C++ compiler (e.g., MinGW), and a text editor or IDE (like Visual Studio Code). For this tutorial, we'll use GLFW for window creation and Vulkan's official headers.

the table shows how many different measurements are used
the table shows how many different measurements are used

The Vulkan SDK installation includes the relevant headers and libraries. Once set up, we can start coding our "Hello, Triangle!" application.

Creating the Project Structure

All About Volcanoes for Kids, Volcano Parts, Worksheet, Craft
All About Volcanoes for Kids, Volcano Parts, Worksheet, Craft

Let's organize our project. Create a new folder named "vulkanhello" and inside it, add a "src" folder. Our main application file ("hello_triangle.cpp") will live here. There's no need for a CMake file for this simple project.

Your project structure should look like this:

/
└── vulkanhello
    └── src
        └── hello_triangle.cpp

Including Necessary Headers

two hands holding an origami piece with the text how to make hsts two - at - a - time half square triangles
two hands holding an origami piece with the text how to make hsts two - at - a - time half square triangles

Open "hello_triangle.cpp" and include the following headers:

```cpp #define GLFW_INCLUDE_VULKAN #include #include #include #include ```

The GLFW header includes Vulkan's headers. We'll use GLFW for window creation and to interact with Vulkan.

Initializing GLFW and Vulkan

a graphic representation of how to use the cube v's triangle controls for mixing
a graphic representation of how to use the cube v's triangle controls for mixing

Now, let's set up GLFW and create a Vulkan instance. Add the following code after the included headers:

```cpp int main() { glfwInit(); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); auto window = glfwCreateWindow(800, 600, "Hello, Triangle!", nullptr, nullptr); if (window == nullptr) { throw std::runtime_error("Failed to create GLFW window!"); } VkInstance instance = {}; VkApplicationInfo app_info = {}; app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; app_info.pNext = nullptr; app_info.pApplicationName = "Hello, Triangle!"; app_info.applicationVersion = VK_MAKE_VERSION(1, 0, 0); app_info.pEngineName = "No Engine"; app_info.engineVersion = VK_MAKE_VERSION(1, 0, 0); app_info.apiVersion = VK_API_VERSION_1_0; VkInstanceCreateInfo instance_info = {}; instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_create_INFO; instance_info.pNext = nullptr; instance_info.flags = 0; instance_info.pApplicationInfo = &app_info; instance_info.enabledLayerCount = 0; instance_info.ppEnabledLayerNames = nullptr; instance_info.enabledExtensionCount = 1; instance_info.ppEnabledExtensionNames = &EXTENSION_NAME; if (vkCreateInstance(&instance_info, nullptr, &instance) < 0) { throw std::runtime_error("Failed to create Vulkan instance!"); } ```

We've initialized GLFW and created a window without a Vulkan context by setting `GLFW_CLIENT_API` to `GLFW_NO_API`. Then, we created a Vulkan instance, enabling required extensions without any validation or debugging layers.

15 Volcano Drawing Ideas - How To Draw Volcano
15 Volcano Drawing Ideas - How To Draw Volcano
Cresco gioco imparo: i vulcani |
Cresco gioco imparo: i vulcani |
How to Draw a Volcano
How to Draw a Volcano
a rock sitting on top of a tiled floor
a rock sitting on top of a tiled floor
Super Easy Volcanos
Super Easy Volcanos
Volcano Unit Study
Volcano Unit Study
How to sew equilateral triangles - a tutorial
How to sew equilateral triangles - a tutorial
How to: Make Half-Square Triangles (HSTs) using the 4-at-a-time method
How to: Make Half-Square Triangles (HSTs) using the 4-at-a-time method
Pop up volcano instructions _ Mrs Eastham
Pop up volcano instructions _ Mrs Eastham

Choosing a Physical Device

The next step is selecting a suitable physical device - a Vulkan-enabled GPU. Add this function below the main function:

```cpp std::vector enumeratePhysicalDevices(VkInstance instance) { uint32_t device_count = 0; vkEnumeratePhysicalDevices(instance, &device_count, nullptr); if (device_count == 0) { throw std::runtime_error("Could not find any available Vulkan devices!"); } std::vector devices(device_count); vkEnumeratePhysicalDevices(instance, &device_count, devices.data()); return devices; } ```

This function enumerates and returns all available Vulkan-enabled physical devices on the system.

Next, we'll discover and exchange information about the physical device's queues and queue families. In our simple application, we'll only need one queue to present images.

Enumerating Queue Families

Add the following function below the previous one:

```cpp std::optional findGraphicsQueueFamilyIndex(VkPhysicalDevice device) { uint32_t queue_family_count = 0; vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_family_count, nullptr); std::vector queue_family_properties(queue_family_count); vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_family_count, queue_family_properties.data()); for (uint32_t i = 0; i < queue_family_count; ++i) { if ((queue_family_properties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) { return i; } } return std::nullopt; } ```

This function scans for queue families with the `VK_QUEUE_GRAPHICS_BIT` flag set, indicating support for graphics operations. If it finds any, it returns its index. If not, it returns `std::nullopt`.

Now, we're ready to create a Vulkan logical device using the graphics queue chosen above. Let's wrap up this tutorial with the creation and rendering of our first Vulkan 3D shape - a triangle!

As you've seen, Vulkan may seem intricate, but once mastered, it opens a world of possibilities for rendering and computing tasks. With this "Hello, Triangle!" guideline, you've overcome your first Vulkan hurdle. Ready to push your newly acquired skills and dive deeper? Happy coding!