SDL_GL_SetAttribute() and SDL_CreateWindow()

I just found out the hard way that any SDL_GL_SetAttribute() calls that affect the OS pixel-format, e.g. frame buffer, depth buffer, stencil buffer, etc., must be made before the call to SDL_CreateWindow(), because the OS pixel-format is only evaluated once, at that time, and not during SDL_GL_CreateContext().

The samples I’ve based my code on (here, here, and here) either don’t do this consistently, or don’t set any OpenGL attributes that affect the pixel format.

Was this documented somewhere? I had to incorporate SDL2 as a sub-project of my CMake solution, and put breakpoints in the code that set up the OS pixel format, to figure this out. (But at least my stenciling now works in MS Windows and Linux.)

Yes, on the wiki page for SDL_GL_SetAttribute() it specifically says:

This function sets the OpenGL attribute attr to value. The requested attributes should be set before creating an OpenGL window. You should use SDL_GL_GetAttribute() to check the values after creating the OpenGL context, since the values obtained can differ from the requested ones.

(emphasis mine)

Ah, so it’s documented in the documentation.
Sorry for the dumb question.