Jump to content
  • Advertisement

Vulkan Vulkan with SDL2 getting started

Recommended Posts


I tried to google Vulcan and sdl2 but they did not help so well.  I only found stand-alone or GLFW tutorials.

Does anyone have good tutorial about Vulkan with SDL2?


Share this post

Link to post
Share on other sites

There are only a handful of Vulkan functions you need to be aware of with SDL:


Assuming you are already familiar with SDL here are some code snippets that may help...

// be sure to initialize your SDL window with the vulkan flag
window = SDL_CreateWindow("My App",
    1280, 720,
// initialize the vulkan instance
#include <SDL.h>
#include <SDL_vulkan.h>
#include <vector>

// in some init function...
uint32_t extensionCount;
SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, nullptr);
std::vector<const char *> extensionNames(extensionCount);
SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, extensionNames.data());

VkApplicationInfo appInfo {};
// TODO: fill this out

std::vector<const char *> layerNames {};
// uncomment below if you want to use validation layers
// layerNames.push_back("VK_LAYER_LUNARG_standard_validation");

VkInstanceCreateInfo info {};
info.pApplicationInfo = &appInfo;
info.enabledLayerCount = layerNames.size();
info.ppEnabledLayerNames = layerNames.data();
info.enabledExtensionCount = extensionNames.size();
info.ppEnabledExtensionNames = extensionNames.data();

VkResult res;
VkInstance instance;
res = vkCreateInstance(&info, nullptr, &instance);
if (res != VK_SUCCESS) {
  // do some error checking
// now that you have a window and a vulkan instance you need a surface
VkSurfaceKHR surface;
if (!SDL_Vulkan_CreateSurface(window, instance, &surface)) {
  // failed to create a surface!

// at this point you have a window, vulkan instance and a vulkan surface
// SDL is out of your way and you can use the vulkan api to enumerate the
// physical devices, create a logical device plus queues, and create your
// swapchain.

Hope that helps.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!