针对不同 DPI 的 OpenGL 表面视图缩放

发布于 2025-01-03 06:23:44 字数 809 浏览 6 评论 0原文

我有一个分辨率为 800x480 的设备。当我创建 GLSurfaceView 时,我收到一个分辨率为 533x320 的 onSurfaceChanged 调用(显然应用了 1.5 HDPI 修改器),并且表面已放大。因此,当我绘制 1 像素粗线时,看起来非常糟糕,而且我无法进行像素完美的渲染。

我想要的是原始分辨率表面(800x480)。

视图是以这种方式创建的(就像在 NDK OpenGL 示例中一样),在 Activity 的 onCreate 中:

    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    view = new MyGLSurfaceView(this);
    setContentView(view);

我不使用任何布局等。

I have a device with 800x480 res. When I create GLSurfaceView, I get an onSurfaceChanged call with 533x320 (apparently with 1.5 HDPI modifier applied) and surface is upscaled. So when I draw 1 pixel thick line is looks really bad, and I can't have pixel-perfect rendering.

What I want to have is native resolution surface (800x480).

View is created in this manner (like in NDK OpenGL samples), in Activity's onCreate:

    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    view = new MyGLSurfaceView(this);
    setContentView(view);

I don't use any layouts etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぃ弥猫深巷。 2025-01-10 06:23:44

我找到了解决方案:当我添加

<uses-sdk android:targetSdkVersion="8" android:minSdkVersion="8"/>

到 AndroidManifest.xml 时,我得到了正确的分辨率。说实话,在使用 iOS 几年后,Android 对我来说是一个非常奇怪的平台......

在这里找到解决方案: MonoDroid 应用不使用正确的密度可绘制对象

I found the solution: when I add

<uses-sdk android:targetSdkVersion="8" android:minSdkVersion="8"/>

to AndroidManifest.xml, I get proper resolution.To be honest, Android is very strange platform for me after few years with iOS...

Solution found here: MonoDroid apps don't use correct density drawables

思念满溢 2025-01-10 06:23:44

问题的根源似乎在于 onSurfaceChanged 命令传递(可能已更改)宽度和高度。

构造视图的代码可能没有任何问题,但我们希望确保它是按照实际设备分辨率构造的。
也许使用所需的宽度和高度显式调用 setLayout (int width, int height) 可能会给您带来更好的效果...

显然,您必须在这样做之前确定实际的物理屏幕尺寸。获得实际物理像素的最佳选择是使用 DisplayMetrics 中的 widthPixels 和 heightPixels : http ://developer.android.com/reference/android/util/DisplayMetrics.html

如果这不起作用,也许在不同的设备上尝试您的代码可能会产生正确的结果。在这种情况下,这可能是设备相关的问题......

The root of the problem seems to lie with the onSurfaceChanged command passing down the (presumably altered) width and height.

There may be nothing wrong with the code constructing the view, but we want to make sure it's constructed at the actual device resolution.
Perhaps calling setLayout (int width, int height) explicitly with the desired width and height may get you better mileage...

Obviously, you'd have to determine the actual physical screen size before you do so. And your best bet to get the actual physical pixels is with widthPixels and heightPixels from DisplayMetrics : http://developer.android.com/reference/android/util/DisplayMetrics.html

If that doesn't work, perhaps trying your code on a different device may yield a correct result. In which case it may be a device-dependant issue...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文