0

The OpenGL ES 2.0 rendering context I get for my Android app is in portrait mode (480x800), but I want to render in landscape mode (800x480).

How could I rotate the OpenGL viewport, preferably without modifying the matrices sent to the shaders?

I have a bunch of shaders, some which use identity matrices (like the font renderer). So it looks like I will need to add a rotation component to the matrices in a few places. Is there a way to globally rotate the viewport somehow?

Can I somehow request a landscape rendering context from Android?

Are there any architecture patterns for this problem?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Meh
  • 7,016
  • 10
  • 53
  • 76

2 Answers2

2

Solved problem by adding <activity android:screenOrientation="landscape" .... This makes OpenGL use a landscape orientation.

Meh
  • 7,016
  • 10
  • 53
  • 76
0

I do two things in my apps. Firstly, modify this line to your manifest file:

<activity android:name=".YourActivity" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation">

That stopped it from re-initialising everything on rotation. Secondly, override this function in your GLSurfaceView.Renderer derived class:

public void onSurfaceChanged(GL10 gl10, int width, int height) 
{
    gl10.viewport(0, 0, width, height);

    //setup your matrices here
}

That will set up your view port but you will have to update your matrices in there too to take account of the new screen geometry. You don't really have to add an rotation extra rotation to your matrices, just re-set up the project matrix in the 'onSurfaceChanged' method.

HTH.

Luther
  • 1,786
  • 3
  • 21
  • 38
  • Thanks, I do the first two things already. I don't have a single projection matrix, since I use shaders, so I can't do your third suggestion. – Meh Mar 04 '11 at 00:40
  • You could have a seperate projection matrix though - that's up to you. I'd recommend it as it's useful for keeping world-space and post-projection space maths seperate in shader calculations. – Luther Mar 04 '11 at 09:03
  • @luther You left the key aspect of "rotation on matrices". I think this http://stackoverflow.com/questions/33773770/use-rotatem-of-matrix-to-rotate-matrix-from-surfacetexture-but-corrupt-the-vid may help. – enthusiasticgeek Apr 18 '16 at 04:18