针对不同 DPI 的 OpenGL 表面视图缩放
我有一个分辨率为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决方案:当我添加
到 AndroidManifest.xml 时,我得到了正确的分辨率。说实话,在使用 iOS 几年后,Android 对我来说是一个非常奇怪的平台......
在这里找到解决方案: MonoDroid 应用不使用正确的密度可绘制对象
I found the solution: when I add
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
问题的根源似乎在于 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...