Tutorial 1: SDK
Tutorial 2: Creating a Window
Tutorial 3: Vulkan Instance
Tutorial 4: SPIR-V Shaders wip
Tutorial 5: Hello Triangle wip
Tutorial 6: Supported Extensions wip
Tutorial 7: Drawing Points wip
Tutorial 8: Drawing Lines wip
Tutorial 9: Drawing Triangles wip
Tutorial 10: Loading Shaders wip
Tutorial 11: Multiple Shaders wip
Tutorial 12: Loading 3D Model wip
Tutorial 13: Displaying 3D Model wip
Tutorial 14: Vertex Animation wip
Tutorial 15: Bone Animation wip
Vulkan Tutorials
Only New Vulkan Tutorial Updates
Follow
Tutorial 1 - SDK
Setting up Vulkan development environment on Windows OS, MVC, Run-time, SDK.
Tutorial 2 - Creating a Vulkan Window
Creating your first Vulkan rendering window.
Tutorial 3 - Drawing Triangles
Drawing your first Vulkan triangle.

Tutorial 2 - Creating Vulkan Instance & Window (Win32)

All tutorials on this site assume that you have Vulkan SDK installed, your graphics card supports Vulkan and you also have latest Vulkan drivers already installed. You have to check for these on your GPU manufacturer's website like nVidia or AMD.

  • In this tutorial
  • Preliminary Compiler Settings - the boring stuff.
  • Including main "vulkan.h" header to our MVS project.
  • Creating and testing a Vulkan instance.
  • Does your GPU support Vulkan? A test.
  • Creating first Vulkan Window.

Installing Microsoft Visual Studio 2015 has already been outlined in my other tutorial. But here is a bit more info, just in case. You can expand / collapse (instructions) to look up MVS installation steps. I collapsed it because most people will already have an IDE installed and ready to go.

Quick test to see if Vulkan is supported and works on your GPU

Before creating our first Vulkan window using standard win32 functions let's test Vulkan's availability on our system. I assume you already downloaded latest LunarG SDK runtime and ran the executable installer file. But first, let's set up our compiler to include important Vulkan header files containing definitions of Vulkan library functions.

First, let's create a quick console application just to see if Vulkan is supported by your video card. Go to New Project and start a new Window Console Application. This is simple just go to the following pane and tabs on the dialog window that shows up:

Visual C++ > Win32 > Win32 Console Application

A new console program will be created and you will see the default main() function already created for us. But there is one more thing we need to take care of.

We should disable the stdafx.h header for clarity's sake. It's not necessary and makes our Vulkan tutorial much cleaner. It was enabled by default in MVS when you started new Console Application project. To disable it, follow the screenshot below:

Disable precompiled headers - stdafx.h in Microsoft Visual Studio 2015 (MVS)

Click "Apply" and we're ready to start writing out first Vulkan application.

Including main Vulkan SDK header

At the very top of the file add Vulkan header as shown below.

At this point you'll see something like this:

Looks like vulkan header .H file cannot be found. No problem, let's include it!

Note that in MVS 2015, a red wavy underline beneath include keyword means the header file cannot be found. This happens because the IDE doesn't know where Vulkan header files are. But we do! If you installed Vulkan to its default location, the header files should be located in a folder similar to:

   C:\VulkanSDK\1.0.37.0\Include\vulkan\vulkan.h

To resolve this problem, in MVS 2015 we need to navigate to Project > Application Settings.

Then type it under C/C++ > General > Additional Include Directories as shown on the screenshot below:

MVS 2015 CE c c++ general additional include directories

This will fix header not found error, and the wavy red line will disappear!

We're now ready to write our first Vulkan test application.

Initializing Vulkan Instance and Passing Application Information

Note Vulkan naming convention for objects starts with Vk (uppercase V) not vk.

But functions start with lowercase vk, like vkCreateInstance.

Vulkan initialization requires creation of a Vulkan instance by first filling out two information-carrying object structures and passing one of them to VkCreateInstance function.

To successfully create an instance we first must fill out two objects with basic application information. These objects are VkApplicationInfo and VkInstanceCreateInfo. The order of the process for creating and initializing a Vulkan instance is outlined below:

  • Create VkApplicationInfo that stores basic Vulkan application information.
  • Create VkInstanceCreateInfo which is a secondary object containing additional app details and a link to the memory address of VkApplicationInfo object we have filled out in the previous step.
  • Create VkInstance by passing the address of VkApplicationInfo as first parameter of VkCreateInstance function.

The source code to initialize a Vulkan instance is shown below.

#include <windows.h> // Main Windows header #include <stdio.h> // Basic console text inpit/output functions #include "vulkan.h"; // Include Vulkan SDK functions // Include Vulkan library // File "vulkan-1.lib" must also be either: // 1. Added in IDE's "library include path", // 2. Exist in root folder of your application. #pragma comment(lib, "vulkan-1.lib") // Create necessary Vulkan objects VkApplicationInfo applicationInfo; VkInstanceCreateInfo instanceInfo; VkInstance instance; int main() { applicationInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; // sType applicationInfo.pNext = NULL; // pNext applicationInfo.pApplicationName = "Blank Vulkan Window"; // Application name applicationInfo.pEngineName = NULL; // Name of your graphics/game engine applicationInfo.engineVersion = 1; // Engine development version applicationInfo.apiVersion = VK_API_VERSION_1_0; // Vulkan's version instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;// sType instanceInfo.pNext = NULL; // pNext instanceInfo.flags = 0; // flags, 0 for now instanceInfo.pApplicationInfo = &applicationInfo; // link to vkApplicationInfo object instanceInfo.enabledLayerCount = 0; // disable layers instanceInfo.ppEnabledLayerNames = NULL; instanceInfo.enabledExtensionCount = 0; // disable extensions instanceInfo.ppEnabledExtensionNames = NULL; // Create the instance VkResult result = vkCreateInstance(&instanceInfo, NULL, &instance); // Check the result and exit the app with error code if not successful if (result != VK_SUCCESS) { fprintf(stderr, "Cannot create VkInstance: %d\n", result); } else { printf("Successfully created VkInstance!\n"); } // Prevent closing application window sooner than we can read result messages above scanf_s("Press enter to quit.", buf, 32); vkDestroyInstance(instance, NULL); // release memory return 0; }

Trying to run this code without having included the Vulkan SDK LIB files is likely to produce the following errors in your MVS console output:

LNK2019 unresolved external symbol _vkCreateInstance@12 referenced in function _main LNK2019 unresolved external symbol _vkDestroyInstance@8 referenced in function _main Debug\ConsoleApplication1.exe : fatal error LNK1120: 2 unresolved externals

This tells us that including only the headers (.h) files wasn't enough.

I just wanted to show it here because it's a common linker error. You will face it every single time if you forget to include a path to LIB and/or DLL files when building your project that reference functions from that library. In this case we need to add LIB and/or DLL from the Vulkan SDK.

To remedy the situation and fix the linker error follow the steps below:

  • 1. Add the vulkan-1.lib from LunarG SDK and drop it into the root folder for your application. Which should be something like "C:\Users\JohnBrown\Documents\Visual Studio 2015\Projects\ConsoleApplication1\"
  • 2. Add #pragma comment(lib, "vulkan-1.lib") to your source code at the top

Compile and build your project. Run the program.

If your video card drivers do not support Vulkan, you will see the following message in the console window:

Cannot create VkInstance. Error code = -1

If that is not the case then your card supports Vulkan and we're ready to move forward to making a blank Vulkan window!

First Vulkan Window

Creating and testing a Vulkan instance is only the first step. If the example from the previous section worked, we're ready to start constructing our first Vulkan window!

Creating a windowed application for 3D graphics is almost identical to creating a standard window on Windows OS. The primary difference is setting the rendering context which should be tied to Vulkan output, just like you would do this in OpenGL. This tutorial walks you through this process below.

Once the window is created, graphics are then rendered on the screen occupied by the window via that rendering context. Without this step, your Win32 app is only capable of drawing using generic drawing operations provided by so called Window's GDI, a set of function for drawing points, lines, rectangles, circles, fills and the like. But that's not what we need.

In OpenGL there are third party libraries like glew or glut that help us set rendering context and start up a window without writing much code. But in this tutorial I won't resort to GL-helper libraries for raising up a blank Vulkan-enabled window either.

Instead, we will create a basic window straight in Win32 API. I cannot imagine skipping this process if you are serious about making games. Without understanding how to make a basic blank Win32 window you won't even be able to make a simple desktop app, let alone a 3D Vulcan game.

[wip... currently writing right this moment]

Join Tigris Discord Game Development server at

Click to join our Discord's Gamedev Server

Who are the members?
  • Game Developers Indie CEO's, hobbyists, and everyone who shares the common interest of making games.
  • Multi-Background Programmers, Artists, Level Designers, 3D Modelers, Animators, Writers, Voice Actors (and Actresses)
Acitivities
  • WIP Post your work in progress screenshots or game demos, for pre-production critique by others game developers.
  • Self Promotion Share a link to your game's official website, Green Light or KickStarter pages.
  • Networking Meet other game developers who share similar interests and passion for game development!