Combining Ogre-Next and SDL3

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


andrecaldas
Halfling
Posts: 54
Joined: Mon May 06, 2024 1:06 am
x 3

Combining Ogre-Next and SDL3

Post by andrecaldas »

Fellow Ogre Friends,

I am writing my first Ogre app. I am trying to use SDL3 with Ogre-Next.

I would love to avoid lots of "#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32" type of things. I believe those tests belong internally to Ogre and SDL. :mrgreen:

In SDL2, there was a SDL_CreateWindowFrom() method that takes a void pointer to the (OS specific) Ogre window handler. This method does not exist anymore in SDL3. :-(

Anyway, I find that seamlessly integrating Ogre-Next and SDL3 would be something great. So I guess it would be nice if Ogre-Next developers could talk to SDL3 developers and figure out what information Ogre needs to provide so that the Ogre window can be used by SDL3. It would be great if this information exchange could be done in a OS agnostic manner (like a void pointer). This way, the library user (me :mrgreen: ) would not have to deal with OS differences.

I have created a topic in SDL's forum:
https://discourse.libsdl.org/t/replacin ... from/53648

Maybe we do not even need a "OgreSDLWindow" specific class if we can successfully implement this. It would be great to be able to use Ogre-Next and SDL3 together witout Ogre or SDL needing to be aware of each other. 8)

I think using those two libraries to handle the same window is a recurrent topic. The solutions I found are either too hackish, too complicated or too OS specific. No solution I found make me very insecure because I cannot be sure things are being done "the proper way (tm)". Even less not that we have options like Vulkan being supported by both libraries.

I suppose that Ogre tweaks the window settings much more and therefore the easiest approach would be to have Ogre create the window and SDL "hijacking" it.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5433
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1341

Re: Combining Ogre-Next and SDL3

Post by dark_sylinc »

I haven't tried SDL3 but has something substantially changed?

Most of our samples use SDL2 for creating & managing a window (including keyboard, mouse & gamepad input) for Windows + macOS + Linux. The samples do not use SDL2 on iOS + Android though (and support is not planned. SDL is quite bad on mobile).
See Samples/2.0/Common/src/GraphicsSystem.cpp and notice they do not use SDL_CreateWindowFrom. They use SDL_CreateWindow and then extract the handles from SDL, using SDL_GetWindowWMInfo, to be injected into OgreNext.

The only samples that don't use SDL2 are the bare-bones projects (e.g. Tutorial00) that teach how to initialize OgreNext with as minimal dependencies as possible (e.g. no SDL2).

Also see our instructions on how to use the Samples' framework to setup your own project.

The only thing I suspect has probably been broken is this bit on Linux:

Code: Select all

params.insert( std::make_pair(
                "SDL2x11", Ogre::StringConverter::toString( (uintptr_t)&wmInfo.info.x11 ) ) );

that makes Vulkan work on Linux with SDL2. However strictly speaking all you need to provide is this:

Code: Select all

        struct
        {
            Display *display;           /**< The X11 display */
            Window window;              /**< The X11 window */
        } x11;

GraphicsSystem has quite bunch of "#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32" kind of macros but those are unavoidable:

  • Android + iOS do not use SDL2, so they need to be handled

  • Grabbing the platform specific handle out of SDL2 and injecting into OgreNext is inherently platform specific

  • Unrelated to SDL or windowing, how to handle resource & config paths is quite OS specific and that code, abstracted or not, needs to be somewhere.

But of course, if you use the EmptyProject template I pointed you too, these nuances are being handled for you.

Edit: On SDL3 it seems you can grab the relevant handles using SDL_GetWindowProperties. Also please notice we don't tell SDL2 to create OpenGL or Vulkan for us.