Using Ogre with SDL2

Problems building or running the engine, queries about how to use features etc.
Post Reply
Owl53
Halfling
Posts: 92
Joined: Sat Jul 22, 2017 2:32 pm
x 4

Using Ogre with SDL2

Post by Owl53 »

Ogre Version: 1.11
Operating System: Windows 10
Render System: OpenGL

Hi,

What is the correct way to use Ogre with SDL? I have used Ogre on its own before, but am rather confused with how you are supposed to integrate it with SDL to use it for input. As expected SDL needs to be initialised to be able to detect input, which involves creating an SDL window. As well as this though, obviously Ogre's initialisation requires creating a window too. I have read several bits of documentation on this, but when I try and implement the code, it doesn't seem to explain how the render window situation works? Are you supposed to somehow hide one of the windows, or is there a way to render one into another or something?

Code: Select all

if (SDL_Init(SDL_INIT_VIDEO) != 0)
	Log::write("Unable to initialise SDL");

m_SDLwindow.reset(SDL_CreateWindow("Go-Karting", 25, 25, 800, 600, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL));
	
SDL_SysWMinfo wmInfo;
SDL_GetVersion(&wmInfo.version);

if (!SDL_GetWindowWMInfo(m_SDLwindow.get(), &wmInfo))
{
	Ogre::LogManager::getSingleton().logMessage(Ogre::String("Couldn't get WM info"));
}

Ogre::String winHandle = Ogre::StringConverter::toString((unsigned long)wmInfo.info.win.window);
Ogre::NameValuePairList params;
params["ExternalWindowHandle"] = winHandle;

m_root.reset(new Ogre::Root(m_pluginsFileName, m_resourcesFileName));
m_root->setRenderSystem(m_root->getRenderSystemByName("OpenGL Rendering Subsystem"));
m_root->showConfigDialog(NULL);
m_root->initialise(false);
  
m_window.reset(m_root->createRenderWindow("Go-Karting", 800, 600, false, &params));
Through the documentation I mentioned and also other forum posts, it led me to this stage, but the result of this is obviously the creation of two windows, so I'm not sure what the correct way to go about this is?

Thanks
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5298
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: Using Ogre with SDL2

Post by dark_sylinc »

It seems you did everything right, except that params["ExternalWindowHandle"] should be params["externalWindowHandle"].
This is likely the source of your problem.
Also do not initialize SDL2 with SDL_WINDOW_OPENGL, as Ogre will be doing that (if you do use SDL_WINDOW_OPENGL, you need extra params to pass Ogre the GL context created by SDL, which can cause friction).

If you need a reference, Ogre 2.1 has SDL2 integration within the samples, and this initialization code hasn't actually changed much between 1.11 and 2.1; so it may be of use to you.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1995
Joined: Sun Mar 30, 2014 2:51 pm
x 1075
Contact:

Re: Using Ogre with SDL2

Post by paroj »

OgreBites uses SDL2 by default. You can either use it directly or take inspiration how to do the initialization:
https://github.com/OGRECave/ogre/blob/v ... t.cpp#L363
Owl53
Halfling
Posts: 92
Joined: Sat Jul 22, 2017 2:32 pm
x 4

Re: Using Ogre with SDL2

Post by Owl53 »

dark_sylinc wrote: Sat Sep 29, 2018 7:04 pm It seems you did everything right, except that params["ExternalWindowHandle"] should be params["externalWindowHandle"].
This is likely the source of your problem.
Also do not initialize SDL2 with SDL_WINDOW_OPENGL, as Ogre will be doing that (if you do use SDL_WINDOW_OPENGL, you need extra params to pass Ogre the GL context created by SDL, which can cause friction).

If you need a reference, Ogre 2.1 has SDL2 integration within the samples, and this initialization code hasn't actually changed much between 1.11 and 2.1; so it may be of use to you.
Brilliant, changing to the lower case solved the issue. I didn't realise about the SDL_WINDOW_OPENGL causing an issue, after I resolved the lower case issue another one cropped up, which as you say was fixed by removing the SDL_WINDOW_OPENGL. Thanks for the help! :)
paroj wrote: Sat Sep 29, 2018 7:04 pm OgreBites uses SDL2 by default. You can either use it directly or take inspiration how to do the initialization:
https://github.com/OGRECave/ogre/blob/v ... t.cpp#L363
Thanks, if I have any further issues I will reference this.
Post Reply