SDL provides the SDL_CreateWindowFrom function to wrap an existing ‘foreign’ window created outside SDL and use it as a target for rendering. The problem is that support for enabling OpenGL rendering on this foreign window is nonexistent outside one very narrow use case (on a Windows OS with at least one other SDL-controlled window that shares a pixel format with the foreign window).
SDL rightly takes a hands off approach to manipulating foreign windows, making as few assumptions as possible since they are necessarily created and managed outside the scope of SDL. If the window has been previously set up for use with OpenGL, however, there should be a way to indicate this when calling SDL_CreateWindowFrom. That way, the SDL_WINDOW_OPENGL flag can be set on the resulting SDL_Window, allowing render contexts to be created.
There’s been some past discussion about this issue in the forum archives with various suggestions for fixes, but most end up with simple custom code patches that never make it into the codebase. Here is a typical example from 2015.
The best proposals in my opinion are the least invasive: something like an additional argument to CreateWindowFrom or another hint to indicate that it’s ok to attempt to create a render context on foreign windows. I’d love for this to become a standard part of SDL.