Code Monkey home page Code Monkey logo

vk2d's Introduction

basic demo

another demo

another demo

Vulkan2D

VK2D is a 2D renderer using Vulkan and SDL2 primarily for C games. VK2D aims for an extremely simple API, requiring no Vulkan experience to use. Astro and more recently Bedlam internally use Vulkan2D for rendering. My other projects Spacelink and Peace & Liberty also used Vulkan2D, although a much older version of it. Check out the quick-start guide.

Features

  • Simple and intuitive API built on top of SDL
  • Draw shapes/textures/3D models/arbitrary polygons to the screen or other textures
  • Fast, built with Vulkan 1.2 and doesn't require any device features (but it can make use of some)
  • Simple and fully-featured cameras, allowing for multiple concurrent cameras
  • Powerful and very simple shader interface
  • Simple access to the Vulkan implementation through VK2D/VulkanInterface.h
  • Easily load multiple resources in the background while your application gets prepared

Documentation

Every file in VK2D is properly documented for doxygen, run doxygen in Vulkan2D/ and an html folder will be created containing the documentation.

Usage

There are two parts to building it with your project: you must build VK2D and also VMA since VK2D needs VMA to function. You'll likely need to do something like this in CMake:

set(VMA_FILES VK2D/VulkanMemoryAllocator/src/vk_mem_alloc.h VK2D/VulkanMemoryAllocator/src/VmaUsage.cpp)
file(GLOB VK2D_FILES VK2D/VK2D/*.c)
...
include_directories(... Vulkan2D/ tinyobjloader-c VulkanMemoryAllocator/src/)
add_executable(... ${VK2D_FILES} ${VMA_FILES})

You also need to link/include SDL2 and Vulkan but that will not be covered here as there are great guides elsewhere. Feel free to use the included CMakeLists.txt as a starting point.

Example

Using the renderer is quite simple, but there are some things to be aware of. For the sake of brevity, error checking is removed from the following example

SDL_Window *window = SDL_CreateWindow("VK2D", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_VULKAN);
SDL_Event e;
VK2DRendererConfig config = {VK2D_MSAA_32X, VK2D_SCREEN_MODE_TRIPLE_BUFFER, VK2D_FILTER_TYPE_NEAREST};
vk2dRendererInit(window, config, NULL);
vec4 clearColour;
vk2dColourHex(clearColour, "#59d9d7");
bool stopRunning = false;

// Load your resources

while (!stopRunning) {
    while (SDL_PollEvent(&e)) {
        if (e.type == SDL_QUIT) {
            stopRunning = true;
        }
    }

    vk2dRendererStartFrame(clearColour);

    // Draw your things

    vk2dRendererEndFrame();
}

vk2dRendererWait();

// Free your resources

vk2dRendererQuit();
SDL_DestroyWindow(window);

And that's about all you need. You can freely manipulate the window, if Vulkan2D detects a window change the renderer will automatically adjust. Check the examples in examples/ for full examples you can compile.

TODO

  • 3D shaders

vk2d's People

Contributors

paolomazzon avatar mewmew avatar illusion0001 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.