Managing different resulution phones with openGL ES
I am learning openGL ES 2.0 to make a game for android.
I was wondering how different resulution screens would affect my program?
I have made a sample program of a spinning triangle and noticed that when I turn my device sideways the triangle gets smaller and is at a different dista开发者_Go百科nce form the the edges.
How does this work and how am I supposed to make a game which works nicely on different devices?
The screen's coordinates go from -1.0f
to 1.0f
for each axis with the origin (0|0) in the center of the screen.
Considering a triangle with
A(-1|-1), B(+1|-1), C(0|+1)
which is displayed correctly in portrait orientation, will be stretched horizontally and compressed vertically in landscape orientation. That is because the positioning is relative to the screen:
A(bottom left), B(bottom right), C(top center).
So, the scaling is unproportional. When doing proportional scaling, you have to work with the aspect ratio of the screen and transform the vertices appropriate in a vertex shader.
精彩评论