PDA

View Full Version : Rendering issues with iOS orientation



tehJP
08-12-2012, 08:43 PM
Running in the iPhone 4.3 simulator it starts in portrait but my irrlicht code is rendering as if it's landscape, whilst the proton hi stuff renders as it should.

My game only renders in a landscape fashion, is there a way to make proton render my stuff correctly instead of at effectively 90 degrees to how it renders on windows?

Seth
08-13-2012, 01:50 AM
It is a little strange that Proton use Portrait mode for Landscape rendering (only on iOS), this is done for legacy reasons (It is 25% faster on older iOS devices) - it does send UI tips so keyboard/notifications pop up landscape though, so to the user there is generally no difference.

I probably should remove it or at least add a setting to disable this mode to make porting GL code easier.

For now, to add screen rotation support to existing GL code, you need to add this anywhere you recreate/setup the projection matrix:

RotateGLIfNeeded(); (for example, a single one of those is used in Irrlicht\source\Irrlicht\COGLESDriver.cpp, and that was all it took for all of Irrlicht to work right with it)

That will handle it. You may also need to use GetPrimaryGLX() and GetPrimaryGLY() to get that actual portrait sizes for certain low level gl code, instead of using GetScreenSizeX() etc which return the landscape size.

Also, if you setup the emulation profile to "iPhone" instead of "iPhone Landscape", it will perfectly emulate the rotation stuff under MSVC, so it's easier to debug. (You can also use Ctrl-U to flip the screen upside down along with other hotkeys.

Edit: You can use Option-Right arrow to flip the emulator screen so it looks right btw, yeah it's annoying.

tehJP
08-13-2012, 08:00 AM
I'm not doing any GL coding myself, I'm just using Irrlicht to draw a load of 2D stuff and that's what's being rendered at the wrong orientation.

Seth
08-13-2012, 08:37 AM
I'm not doing any GL coding myself, I'm just using Irrlicht to draw a load of 2D stuff and that's what's being rendered at the wrong orientation.

Hmm, I think I missed a spot in Irrlicht where I need to add the rotation.

In void COGLES1Driver::setRenderStates2DMode, add RotateGLIfNeeded();

right after:



glMatrixMode(GL_PROJECTION);

const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
core::matrix4 m;
m.buildProjectionMatrixOrthoLH(f32(renderTargetSiz e.Width), f32(-(s32)(renderTargetSize.Height)), -1.0, 1.0);
m.setTranslation(core::vector3df(-1,1,0));
glLoadMatrixf(m.pointer());


Unfortunately I don't have a on-hand test case to see if this is right, my tank game uses the GUI a bit but renders it in 3d (over the tank meshes) so it doesn't use the 2d blit stuff the same way.

tehJP
08-13-2012, 08:50 AM
Hopefully that'll work, will try it out this evening!

tehJP
08-14-2012, 07:49 AM
Yep, managed to get it working. The stock RotateGLIfNeeded() didn't work quite right, needed some tweaking for 2D space:



void RotateGL2DIfNeeded()
{
if( GetbaseApp()->GetManualRotationMode() )
{
float degrees = -OrientationToDegrees( GetOrientation() ); // note the negation on the function call
glRotatef( degrees, 0.0f, 0.0f, 1.0f );

if( g_extraScreenRotation != 0 )
{
glRotatef( g_extraScreenRotation, 0.0f, 0.0f, 1.0f ); // untested, not sure what this is used for, also negated from stock version
}

glTranslatef( 0.0f, -320.0f, 0.0f ); // the rotation takes it offscreen and this brings it back on so the origin is in the right place
}
}


Whoops, just noticed I'm not using the actual dimension of the screen for the translation!