views:

542

answers:

4

I am doing a little experiment with OpenGL ES on Nexus One. Got a problem about the full screen resolution. It seems like I can never get the real full resolution of Nexus One, which is 480*800. I am using an orthogonal projection and just want to draw a simple triangle with identity model view matrix:

@Override
 public void sizeChanged(GL10 gl, int width, int height) {
      /*
       * Set our projection matrix. This doesn't have to be done
       * each time we draw, but usually a new projection needs to
       * be set when the viewport is resized.
       */         
      gl.glViewport( 0, 0, width, height);

      gl.glMatrixMode(GL10.GL_PROJECTION);
      gl.glLoadIdentity();          
      GLU.gluOrtho2D(gl, 0, width, 0, height);                         
 } 

The coordinates for the triangle are:

float[] coords = {
            // X, Y, Z
            0.0f, 0.0f, 0,
            200.0f, 200.0f, 0,
            100.0f, 0.0f, 0,
    }; 

And I get the result below:

alt text

This result is same on emulator (480*800 res) and Nexus 1. Obviously I didn’t get the full resolution (because the top vertex of the triangle is already close to the right edge, if width is real 480, this should be on the left of the half width). Another strangeness is that in sizeChanged (I am using GLSurfaceView, this is the override method in the renderer required by GLSurfaceView), I always get width = 480 and height = 800 no matter whether I start the app in full screen mode. I was expecting that with app title bar and status bar, the size passed to sizeChanged should be smaller right? I mean if the size passed to this method isn’t the real size I am getting, then how can I setup a correct viewport?

I also did a quick implementation using GLUT on Windows with the same setup and draw the exact same triangle. I get the result below, which is the expected result. Anyone can help me figure out how to get this same result on the phone?

alt text

I have already put

<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>

tag in AndroidManifest.xml. In particular, I found that it seems like only android:anyDensity="true"|”false” matters, as this does change the rendered result. Others don’t change the result at all. Also my project is on SDK 1.6, which is recommended for developing apps that support larger phone screen.

The original question is also asked here: http://www.anddev.org/viewtopic.php?p=34832#34832

A: 

i know there was an OpenGL thread covering differences between 16., 2.0 etc with details form those dev games etc you will have to Google it on main google page as the dev list google search sucks

I would also check the bug db as everyone that finds OpenGl bugs tedns to put work aorudns in theri bug reports including me

Other places to check bug db of the alien3d project at googlecode its 3d android game engine maybe they ran into it?

Fred Grott
+1  A: 

Hello.

When running with SDK version 3, your app will run in "compatibility mode"

It will use a standard 320x480 | 480x320 res

Here is how i get some Display information :

// we get some display information 
    display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    scrPixelFormat = display.getPixelFormat();
    scrWidth = display.getWidth(); 
    scrHeight = display.getHeight();
    scrRefreshRate = display.getRefreshRate();

To make my app use the phone full native res, i didn't found anything so had to switch to use sdk version 6.

Dullahx
A: 

One thing to check is to make sure that the android:minSdkVersion attribute of the uses-sdk element in your manifest is 4 or greater. Having an android:targetSdkVersion attribute on that element with 4 or greater will work as well.

Your question does say that your project is Android 1.6, which is API level 4. It is possible to have the build target be Android 1.6, however, but to still have older API levels specified in the uses-sdk element. This often happens when someone starts out with an Android 1.5 project and changes the build target. Eclipse does not update the manifest when changing the build target.

Lance Nanek
+2  A: 

Hi All,

Thanks for all your answers, they helped me a lot. I found myself extremely embarrassing to tell you the real cause of this problem, which I solved just now. The triangle class that I copied from one of the samples actually scale on the coordinates that you define in the position array by the factor of two! I just modified the coordinates in the array and I didn’t notice when they are loaded into the vertex buffer, they get scaled!

I am guilty… But let’s just be careful with something copied over as you trust it does something in the way you expected, but it doesn’t, this is the triangle class I copied the code from http://code.google.com/p/apps-for-android/source/browse/trunk/Samples/OpenGLES/Triangle/src/com/google/android/opengles/triangle/TriangleRenderer.java, and notice that on line number 215, the positions get scaled by 2! Really evil as a sample…

Also, when using GLSurfaceView, use android.opengl.GLSurfaceView instead of the GLSurfaceView.java in your sample folder sdk_root\platforms\android-1.1\samples\ApiDemos\src\com\example\android\apis\graphics. As the latter one is an early version and has some strange behaviors.

Echo Lu