How do I reconfigure my GLES frame buffer after a rotation?

Posted by Panda Pajama on Game Development See other posts from Game Development or by Panda Pajama
Published on 2014-06-01T18:02:23Z Indexed on 2014/06/01 22:00 UTC
Read the original article Hit count: 356

Filed under:
|
|
|

I am implementing interface rotation for my GLES based game for iOS, written in Xamarin.iOS with OpenTK.

I am detecting the rotation by overriding WillRotate, in my UIViewController, and I correctly re-setup all of my projection matrices.

However, when drawing a sprite, the image looks a bit blurrier on the landscape version compared to the portrait version, as you can see in the following closeups magnified 10x.

Portrait (before rotating)

Portrait

Landscape (after rotating)

Landscape

In both cases, I'm using the same texture with the same sampler, the same shader, and the same GL state. I just changed the order of the parameters in the projection matrix, so the resulting sizes should be exactly the same pixelwise.

Since this could be thought of as a window resize, I suppose that the framebuffer has to be recreated to the new size. When working on desktop apps on Direct3D11 (SharpDX), I would have to call swapChain.ResizeBuffers() to do this.

I have tried setting AutoResize = true in my iPhoneOSGameView, but then the framebuffer gets clipped as I rotate the interface, and then everything disappears when rotating the interface again.

I'm not doing anything strange, my framebuffer initialization is pretty vanilla:

int scaling = (int)UIScreen.MainScreen.Scale;
DeviceWidth = (int)UIScreen.MainScreen.Bounds.Width * scaling;
DeviceHeight = (int)UIScreen.MainScreen.Bounds.Height * scaling;
Size = new System.Drawing.Size((int)(DeviceWidth), (int)(DeviceHeight));
Bounds = new System.Drawing.RectangleF(0, 0, DeviceWidth, DeviceHeight);
Frame = new System.Drawing.RectangleF(0, 0, DeviceWidth, DeviceHeight);
ContextRenderingApi = EAGLRenderingAPI.OpenGLES2;
AutoResize = true;
LayerRetainsBacking = true;
LayerColorFormat = EAGLColorFormat.RGBA8;

I get inconsistent results when changing Size, Bounds and Frame on my CreateFrameBuffer override, but since the documentation is so incomplete (it has nothing on Bounds and Frame), I have resorted to randomly changing stuff here and there without really knowing what is going on.

There is a similar question which has no answers. However, I don't know if they're experiencing the same problem as I am.

Is my supposition that recreating the framebuffer is necessary, correct? If so, does anybody know how to do it correctly in OpenTK for Xamarin.iOS?

© Game Development or respective owner

Related posts about ios

Related posts about opengl-es2