Render window resize problem on iOS

Problems building or running the engine, queries about how to use features etc.
Post Reply
magengyu
Kobold
Posts: 35
Joined: Sat Jul 28, 2012 7:54 am
x 1

Render window resize problem on iOS

Post by magengyu »

I followed this thread to use Ogre in a UIView on iOS system.
http://www.ogre3d.org/forums/viewtopic.php?f=2&t=69427

At first the result is ok. but when I tried to resize the UIView. the rendering result is wrong.
pic1 is the correct result without resize. pic2 is after resize.
correct before resize
correct before resize
pic1.png (134.66 KiB) Viewed 2253 times
wrong after resize
wrong after resize
pic2.png (113.4 KiB) Viewed 2253 times
The environment is, Xcode 4.3, Ogre 1.8 pre-build

what I did is:
1. Create a single view application from Xcode template.
2. add the 4 files from ogre template to the singleview application.
3. move go() and renderOneFrame() function from appdelegate.h in the ogre template to the ViewController class.
4. resize UIView in the didRotateFromInterfaceOrientation() function.

the init code is

Code: Select all

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    // start ogre
    [self go];
    
    UIWindow *mUIWindow = nil;
    Ogre::RenderWindow *mWindow = Ogre::Root::getSingleton().getAutoCreatedWindow();
    mWindow->getCustomAttribute("WINDOW", &mUIWindow);
    ogreView = mUIWindow.rootViewController.view;
    CGRect rect = CGRectMake(10, 10, 300, 350);
    [ogreView setFrame:rect];
    [self.view addSubview:ogreView];
}
the resize code is

Code: Select all

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    CGRect rect;
    if (self.interfaceOrientation==UIDeviceOrientationPortrait || self.interfaceOrientation==UIDeviceOrientationPortraitUpsideDown)
        rect = CGRectMake(10, 10, 300, 350);
    else
        rect = CGRectMake(10, 10, 300, 280);
    [ogreView setFrame:rect];
}
I found that, if I resize the view from [200,300] to [300,200], the result is correct.
and after view resize, the first frame rendered sometimes is correct, then the content in the view shrink.
and I checked ogre render window size by m_pRenderWnd->getWidth() in the OgreFramework class. the dimension equals to rect.size in the init function, later resize operations does not change the window size at all. I also tried m_pRenderWnd->Resize(), still not working.

the entire project is also in the attachment. due to size limitation, I delete the media directory which is the same with the ogre template.
Attachments
SingleView 2.zip
singleview project
(65.22 KiB) Downloaded 172 times
Post Reply