



Vulkan2D
Vulkan2D is a 2D renderer using Vulkan and SDL3 primarily for C games. VK2D aims for an extremely simple API, requiring no Vulkan experience to use. This project initially started out aiming to be a more feature complete drop-in replacement for the SDL renderer, but since then has grown in scope. Vulkan2D requires C++20, C11, and Vulkan 1.2+.
Features
- Intuitive API built on top of SDL3
- Very fine-grained camera control
- Direct access to Vulkan (at your own risk)
- Hardware-accelerated 2D light and shadows
- High-performance sprite batching
- Simple and user-friendly shader interface
- Only requires Vulkan 1.2
Documentation
Check out the documentation website.
Vulkan2D headers are all Doxygen commented and the documentation website is automatically generated from them (this also means the documentation will likely show up in your editor of choice!).
Usage
The only officially supported way to use VK2D is via add_subdirectory. For the least painful and most out-of-the-box way to use VK2D, include as a Git submodule and use add_subdirectory in your CMakeLists.txt file.
git submodule add --recursive https://github.com/PaoloMazzon/Vulkan2D.git
add_subdirectory(Vulkan2D/)
add_executable(my-game main.c)
target_link_libraries(my-game PRIVATE Vulkan2D)
If you want to use your own SDL version instead of whatever's latest (which VK2D defaults to) then you can do so with
set(VK2D_BUILD_SDL OFF)
add_subdirectory(Vulkan2D/)
You may also disable shader support entirely by supplying
set(VK2D_DISABLE_SHADERS ON)
add_subdirectory(Vulkan2D/)
This is an option because compiling Slang is a lengthy process and for projects that don't require them this can save users a significant amount of time.
Example
SDL_Init(SDL_INIT_EVENTS);
SDL_Window *window = SDL_CreateWindow("VK2D", 800, 600, SDL_WINDOW_VULKAN);
SDL_Event e;
};
bool stopRunning = false;
while (!stopRunning) {
while (SDL_PollEvent(&e)) {
if (e.type == SDL_EVENT_QUIT) {
stopRunning = true;
}
}
}
SDL_DestroyWindow(window);
SDL_Quit();
void vk2dColourHex(vec4 dst, const char *hex)
Converts a Hex colour into a vec4 normalized colour.
void vk2dRendererPresent()
Presents the frame Call this at the end of every frame to draw to the screen.
void vk2dRendererQuit()
Frees resources used by the renderer.
void vk2dRendererWait()
Waits until current GPU tasks are done before moving on.
VK2DResult vk2dRendererInit(SDL_Window *window, VK2DRendererConfig config, const VK2DStartupOptions *options)
Initializes VK2D's renderer.
@ VK2D_FILTER_TYPE_NEAREST
Nearest neighbor filter, good for pixel art.
Definition Structs.h:78
@ VK2D_MSAA_8X
8 samples per pixel
Definition Structs.h:57
@ VK2D_SCREEN_MODE_IMMEDIATE
Quickest mode, just plop to screen but may have screen tearing.
Definition Structs.h:70
float vec4[4]
4D vector of floats
Definition Structs.h:196
User configurable settings.
Definition Structs.h:285
VK2DMSAA msaa
Current MSAA.
Definition Structs.h:286
To run the examples in the examples/ folder, build the CMakeLists.txt file with the flag -DVK2D_BUILD_EXAMPLES:BOOL=ON.
Roadmap
- Texture readback
- Stability improvements
- Remove or improve 3D
- API lock