简体   繁体   English

Android OpenGL视口在所有设备上的水平和垂直视图相同

[英]Android OpenGL Viewport same view on all devices and both horizontal and vertical

I am looking for the proper way to set up OpenGL so that the same information will be displayed on any screen oriented any way. 我正在寻找设置OpenGL的正确方法,以便相同的信息将以任何方式显示在任何屏幕上。 I do understand that everything will appear squished when rotated, but the same information will appear. 我确实知道,旋转时所有内容都会显示为压缩状态,但是会显示相同的信息。 Is there a way to do that? 有没有办法做到这一点?

For more clarity, imagine a landscape tablet that has a circle in the center of the screen. 为了更清晰,请想象一个景观平板电脑,它在屏幕中央有一个圆圈。 When the user rotates the tablet and the height because the width and visa versa, instead of seeing a circle they will see an elongated oval. 当用户旋转平板电脑和旋转平板电脑的高度(因为宽度和反之亦然)时,他们将看到一个细长的椭圆形,而不是看到一个圆形。

When you initialize OpenGL ES you set a ratio for projection matrix based on screen size. 初始化OpenGL ES时,可以根据屏幕大小设置投影矩阵的比率。 If you set it to 1, it will modify projection matrix the way image will take the same size in portrait and landscape disregarding screen proportions. 如果将其设置为1,则无论屏幕比例如何,纵向和横向图像都将以相同的尺寸修改投影矩阵。 Should be the thing you need. 应该是您需要的东西。

Example: 例:

// correct proportion according width to height ratio
public void onSurfaceChanged(GL10 glUnused, int width, int height) {
    GLES20.glViewport(0, 0, width, height);
    float ratio = (float) width / height;
    Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 2.0f, 250);
} 

// disregard screen width/height ratio
public void onSurfaceChanged(GL10 glUnused, int width, int height) {
    GLES20.glViewport(0, 0, width, height);
    Matrix.frustumM(mProjMatrix, 0, -1, 1, -1, 1, 2.0f, 250);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM