SDL_CreateWindowFrom and SDL_GL_CreateContext |
SDL_CreateWindowFrom and SDL_GL_CreateContext |
Sam Lantinga
|
We can either always set the OPENGL flag for foreign windows, allowing you to try to create a context and let it fail if it's not compatible, or we can add a new API, something like SDL_CreateOpenGLWindowFrom()
Thoughts? On Thu, Oct 3, 2013 at 11:32 PM, Stefanos A. wrote:
|
|||||||||||||
|
SDL_CreateWindowFrom and SDL_GL_CreateContext |
Stefanos A.
Guest
|
Hm, this is trickier than it looks. If we always set the OPENGL flag, then someone is going to complain in the future that he cannot initialize DirectX instead. While that would solve my use-case it might not be the optimal approach.
What about a new API such as SDL_SetForeignWindowFlags(), which works only on FOREIGN windows (fails otherwise) and acts as a promise that these flags have been correctly set by the user (if they haven't, then context creation will simply fail.) I'm not 100% happy with this either, let me pore over the source code and see if I can come up with anything better. Smoothing over the different init sequence in various platforms is always tricky... 2013/10/4 Sam Lantinga
|
|||||||||||||||
|
SDL_CreateWindowFrom and SDL_GL_CreateContext |
Stefanos A.
Guest
|
I've managed to patch SDL2 to enable this behavior on Windows. I've also tried on Mac OS X, but I only have a Carbon application to test with, and SDL2 is using Cocoa (obvious crash).
I tried a few different approaches, but what worked in the end was the following: 1. hardcode the OPENGL flag in SDL_CreateWindowFrom, 2. call SDL_GL_LoadLibrary on the foreign application (otherwise SDL crashes internally in wglCreateContext etc), 3. add a call to WIN_GL_SetupWindow if both FOREIGN & OPENGL is set inside WIN_CreateWindowFrom. (This will fail if a PFD is already set on this HDC, but this is not a problem - if a PFD is set we can freely call wglCreateContext/wglCreateContextAttribsARB.) Does anyone know if any other plaftorms require anything similar to WIN_GL_SetupWindow? IIRC, neither X11 nor Carbon require anything like SetPixelFormat, but I have no experience on Cocoa / iOS / Android. I can rework this into a proper patch if there is interest. 2013/10/4 Stefanos A.
|
|||||||||||||||||
|
SDL_CreateWindowFrom and SDL_GL_CreateContext |
Sam Lantinga
|
Yes please!
You can probably adapt the testnative example in the test directory to do OpenGL after it creates a window. Thanks! On Fri, Oct 4, 2013 at 6:07 AM, Stefanos A. wrote:
|
|||||||||||||||||||
|
tehcloud
|
I really need this functionality as well. I'd be happy to be able to CreateOpenGLWindowFrom() or SetForeignWindowFlags(), doesn't matter as long as I can easily embed OpenGL output in a GUI.
|
|||||||||||
|