iOS Embedding Ogre in a subview

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
Post Reply
pptech
Kobold
Posts: 37
Joined: Mon May 09, 2011 6:14 pm
x 1

iOS Embedding Ogre in a subview

Post 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.

Thanks
pptech
Kobold
Posts: 37
Joined: Mon May 09, 2011 6:14 pm
x 1

Re: iOS Embedding Ogre in a subview

Post 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");
    
    m_StaticPluginLoader.load();
    
    m_pRoot->showConfigDialog();
   	m_pRoot->initialise(false);
    
    // 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_pRenderWnd->windowMovedOrResized();
    
	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_pCamera->setNearClipDistance(0.1f);
    m_pCamera->setFarClipDistance(200.0f);

	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...
Image

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.

Thanks.
User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126
Contact:

Re: iOS Embedding Ogre in a subview

Post 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.
User avatar
nedelman
Gnome
Posts: 315
Joined: Wed Feb 21, 2007 6:03 am
Location: San Francisco, California
x 6
Contact:

Re: iOS Embedding Ogre in a subview

Post 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.
http://www.ogremax.com - Ogre3D Scene Exporter for 3DS Max, Maya, and Softimage
http://www.linkedin.com/in/dereknedelman - My LinkedIn Profile
pptech
Kobold
Posts: 37
Joined: Mon May 09, 2011 6:14 pm
x 1

Re: iOS Embedding Ogre in a subview

Post 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.

https://www.hightail.com/download/OGhjW ... d2ZFdzhUQw

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

Thanks for your help and encouragement.
Post Reply