Pergunta

This is all in OpenGL ES 2.0...

I'm trying to mix a 3D perspective projection with a 2D orthographic projection so I can have a HUD sat on top of the 3D scene in my game.

The game runs with a landscape orientation, and I'm getting really confused how to handle device orientations.

I am rendering the 3D stuff with a suitable projection matrix, and am rotating the modelView matrix and my lighting by 90 degrees so the 3D scene is the right way up. This bit all works fine.

My problem is I can't work out how to set up the 2D projection matrix properly so the origin is in the upper left corner when the device is in landscape with the home button on the left.

How do I correctly construct the orthographic matrix so this happens? I am currently using this

// OrthoMatrix does the same as the old GLOrthof function (left, right, bottom, top, near, far);
projectionMatrix2D = mat4::OrthoMatrix(0, screenWidth, screenHeight , 0, -1.0, 1.0);

However this just puts the origin in the top left if the device is in portrait with the home button at the bottom, and rotating the device in my hand means everything is on its side.

Should I be trying to alter the 2D projection matrix or is there something else I need to be doing?

Foi útil?

Solução

I asked this on Gamedev, but in a more general way and received a helpful answer.

How can I create an orthographic display that handles different screen dimensions?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top