OpenGL Surface Scaling for Different DPI

I have a device with a resolution of 800x480. When I create a GLSurfaceView, I get an onSurfaceChanged call with 533x320 (apparently using 1.5 HDPI modifier) ​​and the surface is scaled. Therefore, when I draw 1 pixel thickness, the line looks very bad, and I cannot achieve perfect pixel rendering.

I want to have a built-in resolution surface (800x480).

The view is created this way (for example, in the OpenGL NDK samples), in 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 do not use any layouts, etc.

+8
android android-ndk opengl-es scaling hdpi
source share
2 answers

I found a solution: when I add

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

in AndroidManifest.xml, I get the correct permission. To be honest, Android is a very strange platform for me in a few years with iOS ...

Solution found here: MonoDroid applications do not use the correct density drawings

+4
source share

The root of the problem seems to lie with the onSurfaceChanged command, which skips the (supposedly modified) width and height.

There is nothing wrong with the code that creates the view, but we want to make sure that it is constructed with the actual resolution of the device. Perhaps by calling setLayout (int width, int height) explicitly with the desired width and height, you can get a better mileage ...

Obviously, you will need to determine the actual size of the physical screen before you do this. And your best choice for getting actual physical pixels is widthPixels and heightPixels from DisplayMetrics: http://developer.android.com/reference/android/util/DisplayMetrics.html

If this does not work, perhaps trying your code on another device may produce the correct result. In this case, it may be a device-specific problem ...

0
source share

All Articles