简体   繁体   English

Android OpenGL的显示尺寸不正确

[英]Incorrect display dimensions for Android OpenGL

I am using the DisplayMetrics to get the display dimensions of the Android phone as follow: 我正在使用DisplayMetrics来获取Android手机的显示尺寸,如下所示:

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;

Results give me height=854, width=480 . 结果给我height=854, width=480

When I want the viewport to cover the whole screen as below, the viewport does not cover the complete display. 当我希望视口覆盖如下所示的整个屏幕时,视口不会覆盖整个显示。

GLES20.glViewport(0,0,480,854);

截图

Any explanations? 有什么解释吗?

It is probably a better idea to get screen width and height from onSurfaceChanged since it takes orientation under account (and is called when it changes). onSurfaceChanged获取屏幕宽度和高度可能是一个更好的主意,因为它考虑了方向(并在更改时被调用)。 What does it mean does not cover the whole display? 这是什么意思不覆盖整个显示器? If it is the status bar and navigation bar that "take" screen space then you can hide them. 如果状态栏和导航栏“占用”了屏幕空间,则可以隐藏它们。

    View decorView = getWindow().getDecorView();
    int uiOptions = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
                    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                    View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);

It looks like the quad does not cover the whole screen. 看起来四边形无法覆盖整个屏幕。 OpenGL screen coordinates range from -1 to 1 on both axis. OpenGL屏幕坐标在两个轴上的范围从-1到1。 Make sure the quad has a width and height of 2 if your not using a projection matrix. 如果不使用投影矩阵,请确保四边形的宽度和高度为2。 If you are using a projection matrix adjust the projection matrix parameters to project the quad on the entire screen or scale the quad to fit the the screen with current projection matrix. 如果使用投影矩阵,请调整投影矩阵参数以将四边形投影到整个屏幕上,或缩放四边形以使屏幕适合当前的投影矩阵。

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

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