SDL_GLAttr(3type)
SDL_GLAttr π β¨
okay bestie, buckle up β this one lives in the SDL3 DATATYPES section of the manual, and the page is literally called SDL_GLAttr(3type). It's the big enum of OpenGL configuration attributes. Yes, the one. The "tell SDL what kind of GL context you want before it makes you a window" one. Obsessed, honestly.
β¨ SYNOPSIS β¨
#include <SDL3/SDL_video.h>
typedef enum SDL_GLAttr
{
SDL_GL_RED_SIZE, /**< the minimum number of bits for the red channel of the color buffer; defaults to 8. */
SDL_GL_GREEN_SIZE, /**< the minimum number of bits for the green channel of the color buffer; defaults to 8. */
SDL_GL_BLUE_SIZE, /**< the minimum number of bits for the blue channel of the color buffer; defaults to 8. */
SDL_GL_ALPHA_SIZE, /**< the minimum number of bits for the alpha channel of the color buffer; defaults to 8. */
SDL_GL_BUFFER_SIZE, /**< the minimum number of bits for frame buffer size; defaults to 0. */
SDL_GL_DOUBLEBUFFER, /**< whether the output is single or double buffered; defaults to double buffering on. */
SDL_GL_DEPTH_SIZE, /**< the minimum number of bits in the depth buffer; defaults to 16. */
SDL_GL_STENCIL_SIZE, /**< the minimum number of bits in the stencil buffer; defaults to 0. */
SDL_GL_ACCUM_RED_SIZE, /**< the minimum number of bits for the red channel of the accumulation buffer; defaults to 0. */
SDL_GL_ACCUM_GREEN_SIZE, /**< the minimum number of bits for the green channel of the accumulation buffer; defaults to 0. */
SDL_GL_ACCUM_BLUE_SIZE, /**< the minimum number of bits for the blue channel of the accumulation buffer; defaults to 0. */
SDL_GL_ACCUM_ALPHA_SIZE, /**< the minimum number of bits for the alpha channel of the accumulation buffer; defaults to 0. */
SDL_GL_STEREO, /**< whether the output is stereo 3D; defaults to off. */
SDL_GL_MULTISAMPLEBUFFERS, /**< the number of buffers used for multisample anti-aliasing; defaults to 0. */
SDL_GL_MULTISAMPLESAMPLES, /**< the number of samples used around the current pixel used for multisample anti-aliasing. */
SDL_GL_ACCELERATED_VISUAL, /**< set to 1 to require hardware acceleration, set to 0 to force software rendering; defaults to allow either. */
SDL_GL_RETAINED_BACKING, /**< not used (deprecated). */
SDL_GL_CONTEXT_MAJOR_VERSION, /**< OpenGL context major version. */
SDL_GL_CONTEXT_MINOR_VERSION, /**< OpenGL context minor version. */
SDL_GL_CONTEXT_FLAGS, /**< some combination of 0 or more of elements of the SDL_GLContextFlag enumeration; defaults to 0. */
SDL_GL_CONTEXT_PROFILE_MASK, /**< type of GL context (Core, Compatibility, ES). See SDL_GLProfile; default value depends on platform. */
SDL_GL_SHARE_WITH_CURRENT_CONTEXT, /**< OpenGL context sharing; defaults to 0. */
SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, /**< requests sRGB-capable visual if 1. Defaults to -1 ("don't care"). This is a request; GL drivers might not comply! */
SDL_GL_CONTEXT_RELEASE_BEHAVIOR, /**< sets context the release behavior. See SDL_GLContextReleaseFlag; defaults to FLUSH. */
SDL_GL_CONTEXT_RESET_NOTIFICATION, /**< set context reset notification. See SDL_GLContextResetNotification; defaults to NO_NOTIFICATION. */
SDL_GL_CONTEXT_NO_ERROR,
SDL_GL_FLOATBUFFERS,
SDL_GL_EGL_PLATFORM
} SDL_GLAttr;
π DESCRIPTION π
So here's the tea, bestie. You can set most OpenGL attributes whenever you want, no big deal β but the ones listed above are special. They have to be known before SDL creates the window that's gonna be used with the OpenGL context. Before. Not after. The window is the main character and these attributes are its backstory. π
You set them and read them with SDL_GL_SetAttribute() and SDL_GL_GetAttribute(). That's the whole flow. Iconic.
Now, the part that lowkey trips everyone up: in some cases these attributes are minimum requests. GL does not promise to hand you exactly what you asked for. It's giving "sure, whatever" energy. For example, you can ask for a 16-bit depth buffer and just... get a 24-bit one instead. Or ask for no stencil buffer and still end up with one available. Rude? Maybe. Real? Absolutely.
Context creation should fail if the GL can't provide your requested attributes at a minimum β but you should still check and see exactly what you actually got. Don't assume, bestie. Verify. π
fr fr: ask for the minimum, then go look at what you received. The GL is not contractually obligated to match your vision board.
π AVAILABILITY π
This enum is available since SDL 3.2.0. So if you're on anything older, this is not the vibe you're getting. π
π¦ THE VIBE CHECK (aka the enum, one by one) π¦
SDL_GL_RED_SIZEβ the minimum number of bits for the red channel of the color buffer; defaults to8.SDL_GL_GREEN_SIZEβ the minimum number of bits for the green channel of the color buffer; defaults to8.SDL_GL_BLUE_SIZEβ the minimum number of bits for the blue channel of the color buffer; defaults to8.SDL_GL_ALPHA_SIZEβ the minimum number of bits for the alpha channel of the color buffer; defaults to8.SDL_GL_BUFFER_SIZEβ the minimum number of bits for frame buffer size; defaults to0.SDL_GL_DOUBLEBUFFERβ whether the output is single or double buffered; defaults to double buffering on.SDL_GL_DEPTH_SIZEβ the minimum number of bits in the depth buffer; defaults to16.SDL_GL_STENCIL_SIZEβ the minimum number of bits in the stencil buffer; defaults to0.SDL_GL_ACCUM_RED_SIZEβ the minimum number of bits for the red channel of the accumulation buffer; defaults to0.SDL_GL_ACCUM_GREEN_SIZEβ the minimum number of bits for the green channel of the accumulation buffer; defaults to0.SDL_GL_ACCUM_BLUE_SIZEβ the minimum number of bits for the blue channel of the accumulation buffer; defaults to0.SDL_GL_ACCUM_ALPHA_SIZEβ the minimum number of bits for the alpha channel of the accumulation buffer; defaults to0.SDL_GL_STEREOβ whether the output is stereo 3D; defaults to off.SDL_GL_MULTISAMPLEBUFFERSβ the number of buffers used for multisample anti-aliasing; defaults to0.SDL_GL_MULTISAMPLESAMPLESβ the number of samples used around the current pixel used for multisample anti-aliasing.SDL_GL_ACCELERATED_VISUALβ set to1to require hardware acceleration, set to0to force software rendering; defaults to allow either.SDL_GL_RETAINED_BACKINGβ not used (deprecated).SDL_GL_CONTEXT_MAJOR_VERSIONβ OpenGL context major version.SDL_GL_CONTEXT_MINOR_VERSIONβ OpenGL context minor version.SDL_GL_CONTEXT_FLAGSβ some combination of0or more of elements of theSDL_GLContextFlagenumeration; defaults to0.SDL_GL_CONTEXT_PROFILE_MASKβ type of GL context (Core, Compatibility, ES). SeeSDL_GLProfile; default value depends on platform.SDL_GL_SHARE_WITH_CURRENT_CONTEXTβ OpenGL context sharing; defaults to0.SDL_GL_FRAMEBUFFER_SRGB_CAPABLEβ requests sRGB-capable visual if1. Defaults to-1("don't care"). This is a request; GL drivers might not comply!SDL_GL_CONTEXT_RELEASE_BEHAVIORβ sets context the release behavior. SeeSDL_GLContextReleaseFlag; defaults toFLUSH.SDL_GL_CONTEXT_RESET_NOTIFICATIONβ set context reset notification. SeeSDL_GLContextResetNotification; defaults toNO_NOTIFICATION.SDL_GL_CONTEXT_NO_ERRORβ no lil note on this one in the source, bestie. It's just here, existing, slaying silently. πSDL_GL_FLOATBUFFERSβ also no comment in the original. Present. Accounted for. β¨SDL_GL_EGL_PLATFORMβ same deal, no note in the source. It's in the enum, that's what we know. π¦
β οΈ heads up: SDL_GL_RETAINED_BACKING is explicitly marked not used (deprecated). Don't build your whole personality around it.
and that's the page, periodt π
This one comes to you from Simple Directmedia Layer, version SDL 3.4.18, filed under SDL_GLAttr(3type). Go make something cute render. π«ΆπΈ
π¦ 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