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 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 β€” 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