SDL_SetRenderVSync(3)

πŸ’– SDL_SetRenderVSync(3) πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_SetRenderVSync β€” she's here to fix your screen tearing era. πŸ¦‹


✨ NAME ✨

SDL_SetRenderVSync β€” toggle VSync of the given renderer. no cap, that's the whole job. πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_render.h>

bool SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync);

#define SDL_RENDERER_VSYNC_DISABLED 0
#define SDL_RENDERER_VSYNC_ADAPTIVE (-1)

like. look at her. so clean. so demure. πŸŽ€


✨ DESCRIPTION ✨

so when a renderer gets created, vsync defaults to SDL_RENDERER_VSYNC_DISABLED. that's the factory setting, that's the vibe it was born with, periodt.

now the vsync parameter is lowkey a choose-your-own-adventure:

  • 1 β†’ synchronize present with every vertical refresh
  • 2 β†’ synchronize present with every second vertical refresh
  • etc. (you get the pattern, you're smart, i believe in you 🫢)
  • SDL_RENDERER_VSYNC_ADAPTIVE β†’ for late swap tearing (adaptive vsync)
  • SDL_RENDERER_VSYNC_DISABLED β†’ just disable it, she's free
⚠️ okay important bestie: not every value is supported by every driver. so please, please check the return value to see whether the requested setting is actually supported. don't just assume and then act surprised. πŸ™ˆ

✨ FUNCTION PARAMETERS ✨

  • renderer β€” the renderer to toggle. she's the one getting the glow-up. πŸ’«
  • vsync β€” the vertical refresh sync interval. yes that's the fancy way of saying "how often do we sync".

✨ RETURN VALUE ✨

returns true on success or false on failure. and if it's giving failure, call SDL_GetError() for more info β€” she will tell you what went wrong, she's not mysterious, she's just dramatic. 😭


✨ THREAD SAFETY ✨

this function should only be called on the main thread. do not try to be sneaky from a side thread, it's not that girl. 🚫🧡


✨ AVAILABILITY ✨

this function is available since SDL 3.2.0. so if you're on something older... yeah. upgrade era. ⭐


✨ SEE ALSO ✨


and that's the whole page, you ate that fr fr πŸ’–βœ¨

this has been a Simple Directmedia Layer moment, brought to you by SDL 3.4.18 β€” go forth and sync those refreshes, queen πŸŽ€πŸ¦‹πŸ’…

πŸ“¦ where this page comes from