



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.
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
- 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/)
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.
VK2DResult vk2dRendererEndFrame()
Completes the end-of-frame drawing tasks.
void vk2dRendererQuit()
Frees resources used by the renderer.
void vk2dRendererStartFrame(const vec4 clearColour)
Sets up the renderer to prepare for drawing.
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
Running the Examples
Be sure to compile the test shader before running the examples/main/ example with:
glslc assets/test.frag -o assets/test.frag.spv
glslc assets/test.vert -o assets/test.vert.spv
Then build the CMakeLists.txt file with the flag -DVK2D_BUILD_EXAMPLES:BOOL=ON.
Roadmap
- Better shader support
- Texture readback