sdlCreateRenderer function

Pointer<SdlRenderer> sdlCreateRenderer(
  1. Pointer<SdlWindow> window,
  2. String? name
)

Create a 2D rendering context for a window.

If you want a specific renderer, you can specify its name here. A list of available renderers can be obtained by calling SDL_GetRenderDriver() multiple times, with indices from 0 to SDL_GetNumRenderDrivers()-1. If you don't need a specific renderer, specify NULL and SDL will attempt to choose the best option for you, based on what is available on the user's system.

By default the rendering size matches the window size in pixels, but you can call SDL_SetRenderLogicalPresentation() to change the content size and scaling options.

\param window the window where rendering is displayed. \param name the name of the rendering driver to initialize, or NULL to let SDL choose one. \returns a valid rendering context or NULL if there was an error; call SDL_GetError() for more information.

\threadsafety This function should only be called on the main thread.

\since This function is available since SDL 3.1.3.

\sa SDL_CreateRendererWithProperties \sa SDL_CreateSoftwareRenderer \sa SDL_DestroyRenderer \sa SDL_GetNumRenderDrivers \sa SDL_GetRenderDriver \sa SDL_GetRendererName

extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window *window, const char *name)

Implementation

Pointer<SdlRenderer> sdlCreateRenderer(
    Pointer<SdlWindow> window, String? name) {
  final sdlCreateRendererLookupFunction = libSdl3.lookupFunction<
      Pointer<SdlRenderer> Function(
          Pointer<SdlWindow> window, Pointer<Utf8> name),
      Pointer<SdlRenderer> Function(
          Pointer<SdlWindow> window, Pointer<Utf8> name)>('SDL_CreateRenderer');
  final namePointer = name != null ? name.toNativeUtf8() : nullptr;
  final result = sdlCreateRendererLookupFunction(window, namePointer);
  calloc.free(namePointer);
  return result;
}