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 thewglAPI 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-
NULLresult 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 withSDL_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
NULLif a function isn't supported β but you can't count on this behavior. check for extensions you use, and if you get aNULLanyway, 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
APIENTRYas 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
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms