Can you please explain SDL_Hints

I disregarded hints until now because they didn’t click with me.
But after looking into them, I’m even more confused.

  • each hint is actually a macro for a literal string
  • SDL_hints is an array of pointers to SDL_hint structs (linked list? (since they have ->next))
  • something with SDL_env
  • the array of hint pointers gets looped over to find the string literal that fits (why are string literals used? one would imagine strcmp() is super slow compared to just making the macro a number)
  • then you can somehow change the setting by passing a value (given to you in a comment next to the hint macro) with SDL_SetHint()

Specific example:

in SDL_events.c, you have static int SDL_EventLoggingVerbosity = 0;, that tells you the value can be 0-4 “as defined in SDL_HINT_EVENT_LOGGING”, and when you go find SDL_HINT_EVENT_LOGGING, you see it is used in an SDL_AddHintCallback. I guess I now understand how hints are set, and how their callback is being added so you can change the value.


Let’s take a look at another example:

SDL_HINT_RENDER_VSYNC is used only in SDL_CreateRenderer(), but when actually checking if the vsync is set in SDL_RenderPresent(), it is done through renderer->wanted_vsync.

So unless I am wrong and couldn’t find the link, it would appear that using SDL_GetHint(SDL_HINT_RENDER_VSYNC) after SDL_RenderSetVSync(), wouldn’t return the current state of VSYNC.

Which brings me to the confusions about Hints. What are they and what are they used for?

The hint category is where they put options that aren’t supported on some platforms.
If your plan is to port your code to every available platform then it would be best not to rely on the hints behavior.
On the other hand, there are some interesting hints in the list and can be used to get the desired behavior on your system.
Some of the hints are supported on most platforms while others are single platform specific.

Hints are just optional runtime configuration knobs for SDL.

In the case of vsync, the hint is just whether or not the renderer should be created with vsync turned on. One could make the argument that the renderer should set a hint callback to be informed if the hint value changes, but the hint apparently isn’t meant to be the primary way vsync is turned on/off.