Search code examples
c++sfmlvulkan

Using Vulkan with SFML?


Im currently using GLFW for window creation and user input. GLFW simply allows us to say:

glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);

To tell GLFW were not working with OpenGL. It even provides function like

glfwCreateWindowSurface(...)

To automate window surface creation for different platforms.

Is there any way I can do something similar with SFML? I could not find any information about it on their website, so i assume the answer is no. But maybe there is some kind of hack, or is this not advised?


Solution

  • Vulkan is supported in the next minor release; SFML 2.6.0.

    The new sf::WindowBase class, serves as the base class for all Windows. It provides a simple interface for manipulating the window: move, resize, show/hide, control mouse cursor, etc. It also provides event handling through its pollEvent() and waitEvent() functions.

    sf::Window still serves as a target for OpenGL rendering, but it now inherits the above functionality from sf::WindowBase. This design choice was done, so as to not break existing code: see the full discussion for info.

    The new sf::WindowBase does not create an OpenGL context by default. Instead it provides a public member function createVulkanSurface with the following definition.

    ////////////////////////////////////////////////////////////
    /// \brief Create a Vulkan rendering surface
    ///
    /// \param instance  Vulkan instance
    /// \param surface   Created surface
    /// \param allocator Allocator to use
    ///
    /// \return True if surface creation was successful, false otherwise
    ///
    ////////////////////////////////////////////////////////////
    bool createVulkanSurface(const VkInstance& instance, VkSurfaceKHR& surface, const VkAllocationCallbacks* allocator = 0);
    

    A demonstration of usage (some 2.600 lines of code), can be found under examples in the SFML respiratory.