Page 1 of 1

iOS Embedding Ogre in a subview

Posted: Sat Nov 23, 2013 5:47 am
by pptech
Hi, There seem to be mixed messages about whether this is working or not. Looking in the source code it makes reference to using a class "EAGL2View" when externalViewHandle is passed into createRenderWindow(). If it is working, is there a definitive example of how this is used or some documentation describing how to implement this? I have searched high and low with lo luck; sorry if I have overlooked an existing answer.


Re: iOS Embedding Ogre in a subview

Posted: Fri Nov 29, 2013 11:13 am
by pptech
Hi, So having had no confirmation one way or the other I decided to go ahead and try it anyway.
Piecing together bits of information from here and there I settled on creating a view hierarchy where the view controller was a sub class of EAGL2ViewController and the sub view for the Ogre window is a sub class of EAGL2View.

The initialisation code looks like this...

Code: Select all

    m_pRoot = new Ogre::Root(pluginsPath, Ogre::macBundlePath() + "/ogre.cfg");
    // initialise ogre window with external view handle provided
    Ogre::NameValuePairList parameters;
    parameters["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned int)window);
    parameters["externalViewHandle"] = Ogre::StringConverter::toString((unsigned int)view);
    parameters["externalViewControllerHandle"] = Ogre::StringConverter::toString((unsigned int)viewController);
    parameters["contentScalingFactor"] = Ogre::StringConverter::toString((unsigned long)1.0);
    CGRect rect = [view frame];
    m_pRenderWnd = m_pRoot->createRenderWindow("OgreWindow", rect.size.width, rect.size.height, false, &parameters);
	m_pSceneMgr = m_pRoot->createSceneManager(Ogre::ST_GENERIC, "SceneManager");
	m_pSceneMgr->setAmbientLight(Ogre::ColourValue(0.7f, 0.7f, 0.7f));
	m_pCamera = m_pSceneMgr->createCamera("Camera");
	m_pCamera->setPosition(Ogre::Vector3(0, 0, 150));
	m_pCamera->lookAt(Ogre::Vector3(0, 0, 0));

	m_pViewport = m_pRenderWnd->addViewport(m_pCamera);
	m_pViewport->setBackgroundColour(Ogre::ColourValue(0.8f, 0.0f, 0.0f, 1.0f));
    m_pCamera->setAspectRatio(Ogre::Real(m_pViewport->getActualWidth()) / Ogre::Real(m_pViewport->getActualHeight()));
I then proceed to load the Ogre head mesh and add the the scene. The camera is positioned so that it is in front of the head looking directly at it but what I actually see is this...

The UIView I am trying to get Ogre to render into is in the centre of the screen so the red rectangle is the Ogre output as expected but seems clipped somehow. I have tried the same set up in a full screen example and the Ogre's head appears correctly so I'm confident the camera/scene setup is correct.

The log output contains the following slightly confusing message...

Code: Select all

GLES2RenderSystem::_createRenderWindow "OgreWindow", 533x300 windowed  miscParams: contentScalingFactor=1 externalViewControllerHandle=257332176 externalViewHandle=257328160 externalWindowHandle=257333648 
iOS: Using an external window handle
iOS: Using an external view handle
iOS: Using an external view controller handle
iOS: Window created 768 x 1024 with backing store size 533 x 300 using content scaling factor 2.0
So, is the window size or the content scaling factor causing the incorrect render.

I feel like I am so close with this one, I would be grateful for any suggestions.


Re: iOS Embedding Ogre in a subview

Posted: Sun Dec 01, 2013 10:18 am
by masterfalcon
I've heard of people getting it to work but I've never tried it myself.

Would you be able to provide a small sample project to test it with? Sounds like you may have something already.

Re: iOS Embedding Ogre in a subview

Posted: Sun Dec 01, 2013 9:07 pm
by nedelman
I also ran into this exact problem and never managed to figure out a solution.

My workaround was to let Ogre3D create the UIView and then set the created view into the view controller.

Re: iOS Embedding Ogre in a subview

Posted: Mon Dec 02, 2013 3:44 pm
by pptech
Hold on...I think it might actually be working.
The final step seems to have been getting the content scaling factor right which it looks like can only be done through the config file, and that needs entries for the OpenGL ES 2.x Rendering Subsystem. I would be good to get an explanation of what this is doing and to be able to pass it with the other Misc params in code thanks.

Here is a link to download a simple project which seems to work for me (OS10.9 and XCode5). If anyone could verify this is working for them I would be most grateful. ... d2ZFdzhUQw

This example references the OgreSDK via an environment variable that you will need to have set up.

Thanks for your help and encouragement.