views:

991

answers:

1

Looking for clues about orienting an OpenGL ES app in landscape, most information I found dates back from 2008, most of it refering to the early versions of the SDK. Apparently, back in the days, in the case of GL it was recommended to not rotate the view, but instead to apply the rotation as a GL transformation. Is it still the case with the current SDKs? It would be so much simpler to simply rotate the window: all the touch events would be in sync with the rotation.

In other words: how to set up an OpenGL view in landscape mode?

+3  A: 

(I'll answer my own question with the solution I found. I'll be happy to consider other answers though.)

In the CAEAGLLayer docs, Apple states (a bit clumsily) that you should make the rotation within GL itself: "When drawing landscape content on a portrait display, you should rotate the content yourself rather than using the CAEAGLLayer transform to rotate it." They don't explain why, but I've read in multiple places about a noticeable drop in performance.

Luckily I solved it with the addition of just a few lines. This is for landscape orientation right, where the home button is on the right.

glPushMatrix();
  glRotatef(90, 0.0, 0.0, 1.0);
  glTranslatef(0.0f, -320.0f, 0.0f );

  // *** ALL RENDERING GOES HERE ***

glPopMatrix();

If you're targeting the iPad, replace -320 by -768.

I also convert the coordinates from the incoming UITouches:

int touchx = touch.y;
int touchy = viewWidth - touch.x;
Steph Thirion