The UImGui::RendererUtils interface gives you utility functions for creating custom renderers. It looks like this:

class RendererUtils
{
public:
    // Call this inside the window hints interface function of the GenericRenderer class
    // Event safety - startup, post-startup
    static void setupManually();

    // Returns a pointer to the current renderer
    // Event safety - any-time
    static GenericRenderer* getRenderer();

    // Renderer a new dear imgui frame
    // Event safety - post-begin
    static void beginImGuiFrame();

    class OpenGL
    {
    public:
        // Call this inside the window hints interface function of the GenericRenderer class
        //
        // Recommended args:
        // Emscripten/Web targets - UIMGUI_LATEST_OPENGL_VERSION, UIMGUI_RENDERER_CLIENT_API_OPENGL_ES, UIMGUI_OPENGL_PROFILE_ANY,
        // Desktop - UIMGUI_LATEST_OPENGL_VERSION, UIMGUI_RENDERER_CLIENT_API_OPENGL, UIMGUI_OPENGL_PROFILE_CORE, true
        //
        // Event safety - startup, post-startup
        static void setHints(int majorVersion, int minorVersion, RendererClientAPI clientApi, Profile profile, bool bForwardCompatible);
        
        // Swaps buffers for OpenGL.
        // Event safety - post-begin
        static void swapFramebuffer();
    };
    class WebGPU
    {
    public:
        // Check for WebGPU support
        // Event safety - any time
        static bool supported();
    };
private:
};

Platform-independent functions

The following members are platform-independent:

  1. setupManually() - tells the windowing library to set up your custom renderer manually, instead of creating a rendering context for you(Call this for every non-OpenGL renderer)
  2. getRenderer() - return an abstract GenericRenderer pointer to the current active renderer
  3. beginImGuiFrame() - begins a dear imgui frame. Should be called after the rendering API calls its own begin frame function from its corresponding dear imgui backend

OpenGL functions

OpenGL requires some additional setup.

The setHints member

The set setHints function allows you to initialise a custom renderer context for OpenGL.

It looks like this:

void setHints(int majorVersion, int minorVersion, RendererClientAPI clientApi, Profile profile, bool bForwardCompatible);

The majorVersion and minorVersion arguments should be set to a corresponding OpenGL/OpenGL ES version. You can use the UIMGUI_LATEST_OPENGL_VERSION macro to set it to the latest version that's supported on your system

The clientApi argument is an enum of type RendererClientAPI, which looks like this:

enum RendererClientAPI
{
    UIMGUI_RENDERER_CLIENT_API_MANUAL,
    UIMGUI_RENDERER_CLIENT_API_OPENGL,
    UIMGUI_RENDERER_CLIENT_API_OPENGL_ES
};

On desktop systems it should be set to UIMGUI_RENDERER_CLIENT_API_OPENGL, while when targeting the web it should be set to UIMGUI_RENDERER_CLIENT_API_OPENGL_ES.

The profile argument is an enum of type OpenGLProfile, which looks like this:

enum OpenGLProfile
{
    UIMGUI_OPENGL_PROFILE_ANY,
    UIMGUI_OPENGL_PROFILE_CORE,
    UIMGUI_OPENGL_PROFILE_COMPAT,
};

On desktop systems is should be set to UIMGUI_OPENGL_PROFILE_CORE, while when targeting the web it should be set to UIMGUI_OPENGL_PROFILE_ANY.

Finally, the bForwardCompatible argument toggles OpenGL forward compatibility. It should be set to true on desktop systems and to false on the web

The swapBuffers() function

This function swaps the current framebuffer to the next frame. This should be called every frame.

WebGPU functions

There is only 1 WebGPU function, which is the supported() function. This function returns true if WebGPU is supported in the client's browser.

Macros

The RendererUtils' header also includes a number of useful macros. They look like this:

#define UIMGUI_EMSCRIPTEN_LATEST_OPENGL_VERSION 2, 0
#define UIMGUI_EMSCRIPTEN_LATEST_GLSL_VERSION "#version 100"

#define UIMGUI_APPLE_LATEST_OPENGL_VERSION 4, 1
#define UIMGUI_APPLE_LATEST_GLSL_VERSION "#version 410"

#define UIMGUI_ANY_LATEST_OPENGL_VERSION 4, 5
#define UIMGUI_ANY_LATEST_GLSL_VERSION "#version 450"

#ifdef __EMSCRIPTEN__
    #define UIMGUI_LATEST_OPENGL_VERSION UIMGUI_EMSCRIPTEN_LATEST_OPENGL_VERSION
    #define UIMGUI_LATEST_GLSL_VERSION UIMGUI_EMSCRIPTEN_LATEST_GLSL_VERSION
#else
    #ifdef __APPLE__
        #define UIMGUI_LATEST_OPENGL_VERSION UIMGUI_APPLE_LATEST_OPENGL_VERSION
        #define UIMGUI_LATEST_GLSL_VERSION UIMGUI_APPLE_LATEST_GLSL_VERSION
    #else
        #define UIMGUI_LATEST_OPENGL_VERSION UIMGUI_ANY_LATEST_OPENGL_VERSION
        #define UIMGUI_LATEST_GLSL_VERSION UIMGUI_ANY_LATEST_GLSL_VERSION
    #endif
#endif

We already showcased how the macros for the OpenGL versions are used.

For OpenGL custom renderers, one should also provide a GLSL version to dear imgui when calling ImGui_ImplOpenGL3_Init(). This is where the UIMGUI_LATEST_GLSL_VERSION macro is used.

C API

The C API is the same as the C++ one, but using standard C API semantics such as prefixing each function with UImGui_RendererUtils_, as defined here.