Jump to content
  • Advertisement
Sword7

Vulkan Vulkan with SDL2 getting started

Recommended Posts

Folks,

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?

Thanks

Share this post


Link to post
Share on other sites
Advertisement

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

http://wiki.libsdl.org/CategoryVulkan

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",
    SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
    1280, 720,
    SDL_WINDOW_VULKAN);
// 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.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!