SDL_GL_GetProcAddress(3)

πŸ’– SDL_GL_GetProcAddress πŸ’–

okay so bestie, this is a page from the SDL3 FUNCTIONS manual set, and it's all about grabbing an OpenGL function by name. yes, by name. like calling your friend across the cafeteria but for function pointers. iconic behavior honestly 🫢


✨ NAME ✨

SDL_GL_GetProcAddress β€” Get an OpenGL function by name.


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_video.h>

SDL_FunctionPointer SDL_GL_GetProcAddress(const char *proc);

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the tea. If the GL library got loaded at runtime with SDL_GL_LoadLibrary(), then every single GL function has to be retrieved this way. no shortcuts, no sneaking around it. and usually? this is the move you use to get function pointers to OpenGL extensions. slay.

but babes, there are some quirks to looking up OpenGL functions that need extra care from the application. the good news: if you code carefully, you can handle all of these quirks without any platform-specific code. periodt. here's the list:

  • On Windows, function pointers are specific to the current GL context. this means you need to have created a GL context and made it current before calling SDL_GL_GetProcAddress(). and if you recreate your context or create a second context, you should assume that any existing function pointers aren't valid to use with it. this is (currently) a Windows-specific limitation, and in practice lots of drivers don't suffer this limitation, but it is still the way the wgl API is documented to work, and you should expect crashes if you don't respect it 😭. store a copy of the function pointers that comes and goes with context lifespan.
  • On X11, function pointers returned by this function are valid for any context, and can even be looked up before a context is created at all. which means that, for at least some common OpenGL implementations, if you look up a function that doesn't exist, you'll get a non-NULL result that is _NOT_ safe to call πŸ’€. you must always make sure the function is actually available for a given GL context before calling it β€” by checking for the existence of the appropriate extension with SDL_GL_ExtensionSupported(), or by verifying that the version of OpenGL you're using offers the function as core functionality.
  • Some OpenGL drivers, on all platforms, will return NULL if a function isn't supported β€” but you can't count on this behavior. check for extensions you use, and if you get a NULL anyway, act as if that extension wasn't available. this is probably a bug in the driver, but you can code defensively for this scenario anyhow. no cap.
  • Just because you're on Linux/Unix, don't assume you'll be using X11. next-gen display servers are waiting to replace it, and may or may not make the same promises about function pointers. keep that in mind bestie πŸ‘‘
  • OpenGL function pointers must be declared APIENTRY as in the example code. this will ensure the proper calling convention is followed on platforms where this matters (Win32), thereby avoiding stack corruption. like, actually. do not skip this one πŸ™ˆ
fr fr, read the quirks twice. they are not vibes, they are rules.

πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • proc β€” the name of an OpenGL function.

🌈 RETURN VALUE 🌈

Returns a pointer to the named OpenGL function. the returned pointer should be cast to the appropriate function signature. that part is on you, hun πŸ’…


🧚 THREAD SAFETY 🧚

This function should only be called on the main thread. main character energy only, no side quests ⭐


πŸ’œ AVAILABILITY πŸ’œ

This function is available since SDL 3.2.0.


πŸ”₯ SEE ALSO πŸ”₯


and that's the whole page bestie, you ate it πŸ’– this one shipped from the Simple Directmedia Layer crew as part of SDL 3.4.18 β€” go get those function pointers, and remember: check your extensions, declare APIENTRY, and stay on the main thread. mwah πŸŽ€βœ¨

πŸ“¦ where this page comes from