Embedded window

Hi guys.

I am trying to create something like minigames, using wxwidgets for GUI and OpenGL with SDL for games. I want to embed SDL window to WXWIDGETS window.

I already made wxwidgets GUI, but problem is with allowing OpenGL. You can use additional flags(SDL_WINDOW_OPENGL) just with SDL_CreateWindow(), but not with SDL_CreateWindowFrom().

I am also open to use GLFW instead of SDL, but i havent found any solution in neither one.

[Is there] any good soul who has experience with this kind of stuff? Thank you very much.

Scanning the SDL list archives, this is something folks have hit before. Sounds like a possible limitation in the SDL plumbing w.r.t. t this API call. Some workarounds/fixes are included in the discussions. A few links to those:

Also note this on the SDL_CreateWindowFrom() man page:

More docs on that:

1 Like

Can you use wxGLCanvas to get an OpenGL surface?

More generally (and I don’t know about the specific combination of wxWidgets and SDL), in my experience using multiple “application frameworks” tends to be bit tricky because both of them want to be in charge of running the native event loop that receives input/window system events. So, if you can get all features with just one of them it would likely simplify things for you.

Yeah i considered it as well, but there is no support for audio in opengl and wxwidgets, which i will be using a lot. It is possible to make it work, but its really complicated, you have to load audio files into the collection of bytes and iam not really into it. So i want a library like SDL, to be able using audio easily. Also i already made a pattern in which i would like to software look like, and it has absolutely no issues using SDL and WXWidgets. Unfortunately i have ran into limits rendering just using SDL, so i need to switch from SDL rendering to OGL rendering. But thanks for the answer anyway.

Ok. AFAIK the SDL_WINDOW_OPENGL flag mostly ensures that a OpenGL compatible pixel format is chosen for the window - which also would explain why it’s not supported with SDL_CreateWindowFrom, if the window already exists it is too late to limit the pixel format, it has already been selected.

Have you tried combining wxGLCanvas with SDL_CreateWindowFrom? The wxGLCanvas window should have a valid pixel format.

1 Like

I figured it out, i looked at the source code of the SDL_video.c, and there is the hint u have to set on TRUE. I broswed like hundreds of pages and it was never been mentioned. Crazy. Ok, whoever read this, just do SDL_SetHint(SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL, "1") before initilizing SDL. After that GLContext should be set correctly. I suppose this hint came with latest updates of SDL.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.