SDL_SetWindowSurfaceVSync(3)

πŸ’– SDL_SetWindowSurfaceVSync(3) β€” from the SDL3 FUNCTIONS girlies πŸ’–

okay so bestie, welcome to the SDL3 video corner of the manual, where we're talking about SDL_SetWindowSurfaceVSync β€” aka the "toggle VSync for the window surface" function. yes that's literally the whole NAME section, she's short and she knows it. πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_video.h>

bool SDL_SetWindowSurfaceVSync(SDL_Window *window, int vsync);

#define SDL_WINDOW_SURFACE_VSYNC_DISABLED 0
#define SDL_WINDOW_SURFACE_VSYNC_ADAPTIVE (-1)

like, two defines and a function, that's the whole vibe. πŸŽ€


🌸 DESCRIPTION 🌸

so when a window surface gets created, vsync defaults to SDL_WINDOW_SURFACE_VSYNC_DISABLED. that's the starting state, no cap. πŸ™ˆ

now the vsync parameter, listen closely because this is the main character:

  • 1 β€” synchronize present with every vertical refresh
  • 2 β€” synchronize present with every second vertical refresh
  • and so on and so on, etc., you get the pattern
  • SDL_WINDOW_SURFACE_VSYNC_ADAPTIVE β€” for late swap tearing (that's the adaptive vsync, iykyk)
  • SDL_WINDOW_SURFACE_VSYNC_DISABLED β€” disables it entirely
⚠️ not every value is supported by every driver!! so you should check the return value to see whether the requested setting is actually supported. do not just assume, bestie, that's how you get humbled. 😭

🫢 FUNCTION PARAMETERS 🫢

  • window β€” the window. yes. that's it. she's the window.
  • vsync β€” the vertical refresh sync interval.

πŸ’€ RETURN VALUE πŸ’€

returns true on success or false on failure. and if it fails? call SDL_GetError() for more information, she'll tell you what went wrong. πŸ”₯


πŸ‘‘ THREAD SAFETY πŸ‘‘

this function should only be called on the main thread. periodt. don't be out here calling her from a random thread, she will not answer. πŸ’…


🌈 AVAILABILITY 🌈

this function is available since SDL 3.2.0. iconic, honestly. ⭐


πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page!! simple directmedia layer energy, SDL 3.4.18, and no date on this footer so she's giving timeless πŸŽ€ β€” stay synced bestie, mwah πŸ’–βœ¨

πŸ“¦ where this page comes from