SDL_CreateRenderer(3)

πŸ’– SDL_CreateRenderer πŸ’–

okay bestie, so SDL_CreateRenderer is literally the moment your window gets its whole 2D rendering era ✨ It spins up a 2D rendering context for a window. That's the function, that's the vibe, that's the whole thing. πŸŽ€

This page lives in the SDL3 FUNCTIONS collection, btw, so you know it's the new-gen stuff. πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_render.h>

SDL_Renderer * SDL_CreateRenderer(SDL_Window *window, const char *name);

like, that's it. two args. one renderer. slay. πŸ¦‹


🌸 DESCRIPTION 🌸

So here's the tea β˜• β€” if you already know which renderer you want, you can just specify its name right there in the name argument. Not sure what's available? You can build the whole list yourself by calling SDL_GetRenderDriver() over and over again, with indices running from 0 all the way up to SDL_GetNumRenderDrivers()-1. Go ahead, loop it, it's fine. πŸ’œ

But if you genuinely don't care which one you get β€” and honestly, sometimes you just don't, and that's valid β€” pass NULL and SDL will pick the best option for you based on whatever is actually available on the user's system. main character energy, but make it automatic. πŸ‘‘

Oh and this part is iconic: if name is a comma-separated list, SDL will try each name in the order you listed them, one after another, until one succeeds or all of them fail. It's giving "I have backups for my backups." 🫢

By default, the rendering size matches the window size in pixels. But β€” and this is the fun part β€” you can call SDL_SetRenderLogicalPresentation() to change the content size and the scaling options. So yeah, go off, restyle your whole presentation layer. πŸ’…


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • window β€” the window where the rendering is displayed. Your canvas, your stage, your moment. πŸ–ΌοΈ
  • name β€” the name of the rendering driver to initialize, or NULL to just let SDL choose one for you. (No wrong answers here, bestie.) πŸ’«

⭐ RETURN VALUE ⭐

You get back a valid rendering context on success β€” or NULL if something went wrong 😭. And if it is NULL? Call SDL_GetError() for more info, because SDL is absolutely going to tell you what happened. Always check, fr fr. πŸ™ˆ


πŸ”₯ THREAD SAFETY πŸ”₯

This function should only be called on the main thread. No side quests, no background threads, no exceptions. Main thread only, periodt. πŸ’€

🌈 AVAILABILITY 🌈

This function is available since SDL 3.2.0. If you're on something older, sorry bestie, it's not happening. 🧚


πŸ’œ SEE ALSO πŸ’œ


and that's the whole page, bestie!! 🫢 this lil' writeup came to you straight from the Simple Directmedia Layer girlies, shipped with SDL 3.4.18. go forth and render something gorgeous. mwah. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from