SDL_ConvertE...erCoordinates(3)

✨ SDL_ConvertEventToRenderCoordinates ✨

okay bestie, gather round, we're in the SDL3 FUNCTIONS section of the manual and today's main character is SDL_ConvertEventToRenderCoordinates πŸ’… she takes an event's coordinates and turns them into render coordinates, no cap.


🌸 NAME 🌸

SDL_ConvertEventToRenderCoordinates β€” convert the coordinates in an event to render coordinates πŸ¦‹


πŸ’– SYNOPSIS πŸ’–

#include <SDL3/SDL_render.h>

bool SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event);

✨ DESCRIPTION ✨

so like. this function is doing the math for you and it's lowkey taking into account several whole states at once:

  • the window dimensions πŸ‘€
  • the logical presentation settings (SDL_SetRenderLogicalPresentation) πŸŽ€
  • the scale (SDL_SetRenderScale) πŸ“
  • the viewport (SDL_SetRenderViewport) πŸͺŸ

various event types get converted by this function, fr fr: mouse, touch, pen, etc. the whole squad 🫢

touch coordinates specifically come in as normalized coordinates in the window and go out as non-normalized rendering coordinates. glow up, honestly ✨

and NOT ME forgetting the relative mouse coordinates β€” the xrel and yrel event fields get converted also. like, also. so if your app does not want those fields touched, do NOT convert the entire event structure. instead, hit up SDL_RenderCoordinatesFromWindow() on the specific event fields you care about. iykyk πŸ™ˆ

once it's converted, the coordinates may be outside the rendering area. she does not care. she does not gatekeep. she simply converts. πŸ’€

πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • renderer β€” the rendering context. your whole vibe engine basically πŸ‘‘
  • event β€” the event to modify. yes bestie, we are modifying it in place 🫰

⭐ RETURN VALUE ⭐

returns true if the event got converted or doesn't even need conversion (she's already perfect, iconic), or false on failure 😭 and if that happens, call SDL_GetError() for more info, she'll spill the tea.


🌈 THREAD SAFETY 🌈

this function should only be called on the main thread. periodt. no side quests on other threads, bestie 🚫🧡


πŸ’œ AVAILABILITY πŸ’œ

this function is available since SDL 3.2.0 β€” she's been here, she's established, she ate 🌟


πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page, babe β€” written for Simple Directmedia Layer, version SDL 3.4.18, and yes that's the whole footer, no date to be found so don't come for me πŸ’… mwah, go convert some coordinates, you're doing amazing sweetie 🫢✨

πŸ“¦ where this page comes from