Featured Article

Vulkan Hello Triangle Tutorial: Master the Basics with This Easy-to-Follow Code Guide

Cynthia Jul 13, 2026

Embarking on a journey into 3D graphics programming with Vulkan? Your first milestone, the classic "Hello Triangle", is not just a simple shape but a rite of passage that signifies your initiation into this powerful, low-overhead graphics API. Let's dive into the code, explore its nuances, and make sure your Vulkan hello triangle is not just a triangle, but a story of your graphics programming odyssey.

the numbers and symbols are arranged in order to make it look like they have different shapes
the numbers and symbols are arranged in order to make it look like they have different shapes

The Vulkan API, developed by the Khronos Group, is designed to provide applications almost direct hardware control over graphics processing. To start, you'll need a Vulkan-capable GPU and the appropriate drivers. Then, let's get our hands dirty with some code.

a neon sign that is on the side of a building in the dark with circles around it
a neon sign that is on the side of a building in the dark with circles around it

Vulkan Application Basics

The Vulkan application structure is built around creating and destroying several instances, such as the Vulkan Instance, Physical Device, Logical Device, Swap Chain, Render Pass, and Framebuffers. Understanding these elements is crucial for any Vulkan development.

the hexcode version 2 is shown with different colors and numbers on it's side
the hexcode version 2 is shown with different colors and numbers on it's side

Before we begin, ensure you have a Vulkan installation and head over to the official documentation, a valuable resource for any Vulkan developer. Now, let's set the stage for our "Hello Triangle" by initializing our Vulkan instance and surface:

Vulkan Instance Creation

an image of the numbers and symbols for stuffed animals in different colors, sizes and shapes
an image of the numbers and symbols for stuffed animals in different colors, sizes and shapes

The Vulkan instance is the entry point to Vulkan, representing our application's connection to the Vulkan library. Creating an instance involves setting up validation layers and extensions, along with providing Vulkan with the necessary information about our application.

The following code snippet demonstrates creating a Vulkan instance:
VkApplicationInfo appInfo = {}; ...
VkInstanceCreateInfo createInfo = {}; ...
vkCreateInstance(&createInfo, nullptr, &instance);

Acquiring a Physical Device

an orange, yellow and red color scheme
an orange, yellow and red color scheme

Once our instance is ready, we need to find a suitable physical device within our instance. In other words, we're looking for a Vulkan-capable GPU that meets our application's requirements. This involves retrieving a list of physical devices, querying their support for required extensions, and selecting the preferred device.

The following code demonstrates querying available physical devices:
uint32_t deviceCount = 0;
vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr);
std::vector devices(deviceCount); ...

Setting Up Swap Chain and Framebuffers

Dinosaur suit
Dinosaur suit

The swap chain is a set of images used to facilitate the drawing on the screen. It's a fundamental aspect of any Vulkan application, as it handles moving images from the application to the display. Creating a swap chain involves selecting a surface format, determining the number of images, and creating the swap chain itself.

Framebuffers, in turn, are used to pass image data to the pipeline. For a window-based application, we'll typically create one framebuffer per swap chain image:

the different colors of an iphone's keyboard and phone numbers are shown in this screenshot
the different colors of an iphone's keyboard and phone numbers are shown in this screenshot
an abstract red background with wavy lines in the middle and dark bottom corner, on a black background
an abstract red background with wavy lines in the middle and dark bottom corner, on a black background
ꜱɪɢɪʟ ꜱᴜᴍᴍᴏɴɪɴɢ, ᴛʜᴇ ᴅᴇᴇᴘ ᴅᴇᴘᴛʜ ᴏꜰ ꜱᴄᴏʀɴɪɴɢ, ʙʟᴀꜱᴛ ʙᴇꜰᴏʀᴇ ᴛʜᴇ ɴᴏᴡ, ɴᴏᴛʜɪɴɢ ꜱʜᴀʟʟ ʀᴇᴍᴀɪɴ...
ꜱɪɢɪʟ ꜱᴜᴍᴍᴏɴɪɴɢ, ᴛʜᴇ ᴅᴇᴇᴘ ᴅᴇᴘᴛʜ ᴏꜰ ꜱᴄᴏʀɴɪɴɢ, ʙʟᴀꜱᴛ ʙᴇꜰᴏʀᴇ ᴛʜᴇ ɴᴏᴡ, ɴᴏᴛʜɪɴɢ ꜱʜᴀʟʟ ʀᴇᴍᴀɪɴ...
Therian
Therian
a qr code with an image of two blue crosses on the front and one white cross on the back
a qr code with an image of two blue crosses on the front and one white cross on the back
opsucht whats going in??
opsucht whats going in??
a large building with lots of lights on top of it
a large building with lots of lights on top of it
Should minecraft add volcanos in minecraft? | minecraft
Should minecraft add volcanos in minecraft? | minecraft
aera--rep__-U-.jpg
aera--rep__-U-.jpg

Creating the Swap Chain

To create a Vulkan swap chain, we first need to find a suitable surface format and present mode. The surface format determines the color space, bits per channel, and other properties of the swap chain images. The present mode dictates how the swap chain presents its images to the screen.

The following code demonstrates creating a basic swap chain:
VkSwapchainCreateInfoKHR createInfo = {}; ...
vkCreateSwapchainKHR(device, &createInfo, nullptr, &swapChain);

Creating Framebuffers

With our swap chain created, we can now create framebuffers. Each framebuffer is tied to a single swap chain image, providing the data needed to render to that image.

The following code demonstrates creating a framebuffer:
VkFramebufferCreateInfo framebufferInfo = {}; ...
vkCreateFramebuffer(device, &framebufferInfo, nullptr, &framebuffer);

By now, our "Hello Triangle" Vulkan application is well on its way. We've initialized our Vulkan instance, acquired a physical device, and set up our swap chain and framebuffers. The next step is to create a render pass, which will define the process of drawing our triangle to the swap chain image.

Vulkan is an exciting API that allows for a high degree of control and performance. The "Hello Triangle" code serves as an excellent foundation for building more complex Vulkan applications. So, keep exploring, keep experimenting, and happy coding! As you continue your Vulkan adventure, you'll find that each new challenge is another opportunity to master this powerful API and create stunning 3D graphics."