Screen resolution differences due to orientation

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

Screen resolution differences due to orientation

Postby seed » Fri Apr 02, 2010 2:29 pm

Hey guys,

New to droid. Working on a super cool 3D OpenGl game.

I get a different screen resolution depending upon the orientation of the G1. I cant remember exactly, but it is something like 840x480 when horizontal and 359x580 when vertical. Is this right? Or, is there something I can do to get the high resolution when vertical?

Some code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class LavaBall extends Activity implements SensorListener{
  2.  
  3.        
  4.  
  5.            
  6.  
  7.     /** Called when the activity is first created. */
  8.  
  9.     @Override
  10.  
  11.     public void onCreate(Bundle savedInstanceState) {
  12.  
  13.         super.onCreate(savedInstanceState);
  14.  
  15.         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  16.  
  17.                 WindowManager.LayoutParams.FLAG_FULLSCREEN);
  18.  
  19.         this.requestWindowFeature(getWindow().FEATURE_NO_TITLE);
  20.  
  21.                 mView = new OpenGLRenderer(this);
  22.  
  23.         setContentView(mView);    
  24.  
  25.     }
  26.  
  27. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


... and

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class OpenGLRenderer extends GLSurfaceView implements Renderer {
  2.  
  3.         private Context context;
  4.  
  5.         private int swidth;
  6.  
  7.         private int sheight;
  8.  
  9.        
  10.  
  11.         public OpenGLRenderer (Context context)
  12.  
  13.         {
  14.  
  15.                 super(context);
  16.  
  17.                
  18.  
  19.                 //Set this as Renderer
  20.  
  21.                 this.setRenderer(this);
  22.  
  23.        
  24.  
  25.                 this.context = context;
  26.  
  27.         }
  28.  
  29.  
  30.  
  31.         public void onSurfaceCreated(GL10 gl, EGLConfig config)
  32.  
  33.         {
  34.  
  35.                
  36.  
  37.                 // Load up the textures we will use in this project
  38.  
  39.                 loadTextures(gl);
  40.  
  41.                
  42.  
  43.                 // Create the lights
  44.  
  45.                 createLights(gl);
  46.  
  47.                
  48.  
  49.                 // Do the one time gl initialization stuff
  50.  
  51.                 glInit(gl);
  52.  
  53.                
  54.  
  55.                 // Initialize all game objects
  56.  
  57.                 loadObjects(gl);               
  58.  
  59.         }
  60.  
  61.        
  62.  
  63.         public void onSurfaceChanged(GL10 gl, int width, int height)
  64.  
  65.         {
  66.  
  67.                 swidth = width;
  68.  
  69.                 sheight = height;
  70.  
  71.                
  72.  
  73.                 // Setup the projection matrix
  74.  
  75.                 setStandardProjection2(gl);
  76.  
  77.         }
  78.  
  79.        
  80.  
  81.         public void glInit(GL10 gl)    
  82.  
  83.         {
  84.  
  85.                 // Set the background color to black ( rgba ).
  86.  
  87.                 gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
  88.  
  89.                 // Enable Smooth Shading, default not really needed.
  90.  
  91.                 gl.glShadeModel(GL10.GL_SMOOTH);
  92.  
  93.                 // Depth buffer setup.
  94.  
  95.                 gl.glClearDepthf(1.0f);
  96.  
  97.                 // Enables depth testing.
  98.  
  99.                 gl.glEnable(GL10.GL_DEPTH_TEST);
  100.  
  101.                 // The type of depth testing to do.
  102.  
  103.                 gl.glDepthFunc(GL10.GL_LEQUAL);
  104.  
  105.                 // Really nice perspective calculations.
  106.  
  107.                 gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
  108.  
  109.         }
  110.  
  111.        
  112.  
  113.         public void setStandardProjection2(GL10 gl)
  114.  
  115.         {
  116.  
  117.                 // Sets the current view port to the new size.
  118.  
  119.                 gl.glViewport(0, 0, swidth, sheight);
  120.  
  121.                
  122.  
  123.                 // Select the projection matrix
  124.  
  125.                 gl.glMatrixMode(GL10.GL_PROJECTION);
  126.  
  127.  
  128.  
  129.                 // Reset the projection matrix
  130.  
  131.                 gl.glLoadIdentity();
  132.  
  133.                
  134.  
  135.                 float gheight = 2;
  136.  
  137.                 float z=16;
  138.  
  139.                 float near=4;
  140.  
  141.                 float far=z+z-near;
  142.  
  143.                 float height = (gheight*near)/z;
  144.  
  145.                 //float height = (gheight*near)/(2*((z-near)/2+near));
  146.  
  147.                 float ratio = (float)swidth/(float)sheight;
  148.  
  149.                 float width = height*ratio;
  150.  
  151.                
  152.  
  153.                 // Create the frustum view
  154.  
  155.                 gl.glFrustumf(-width, width, -height, height, near, far);
  156.  
  157.                
  158.  
  159.                 // Look at the origin
  160.  
  161.                 GLU.gluLookAt(gl, 0, 0, 16, 0, 0, 0, 0, 1, 0);         
  162.  
  163.         }
  164.  
  165. }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


The widths and heights I get are not the same resolutions for the two orientations. I don't get it. Any ideas?

Thanks
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Top

Postby MichaelEGR » Fri Apr 02, 2010 2:49 pm

Greets... Make sure that you look over the capabilities of AndroidManifest.xml carefully. You can set a lot of parameters in AndroidManifest.xml. The lower screen dimension sounds like compatibility mode is kicking in.. Why it would do that with a switch in orientation I'm not sure. It also sounds like on the switch in orientation that the Activity is also restarting; you can prevent that with a flag in AndroidManifest.xml too.

Add this to prevent compatibility mode... I do believe you just need the "anyDensity" entry if your app supports all screen sizes.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.    <supports-screens
  2.      android:largeScreens="true"
  3.      android:normalScreens="true"
  4.      android:smallScreens="true"
  5.      android:anyDensity="true" />
  6.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.       <activity android:name=".cube.CubeActivity"
  2.         android:configChanges="keyboardHidden|orientation"
  3.         android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>
  4.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


You can further customize the "theme" parameter, but this one will setup no title bar and make it full screen. You don't need to manually set this in the onCreate method. The configChanges parameter will prevent a change in orientation from restarting the Activity.

Good luck and "spawneth" super cool 3D OpenGL games!

I'm releasing a comprehensive 3D middleware framework rather soon; more into at:
http://www.typhon4android.org
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Postby seed » Fri Apr 02, 2010 6:57 pm

Wow, great response. Thanks for the time. I will try this out tonight.

My first game will be a wicked cool 3D implementation of an already popular handheld game theme. I have a hook (not talking) that makes it look amazing. Hopefully, this gets me started well, because my next game is even more ambitious and even more wicked cool:)

I don't know Java. I don't know OpenGl. I am re-remembering my 3D graphics skills. But, I do have a history in gaming, having created a very popular mod for the quake series, so hopefully this goes alright. I have basically finished my technology stuff for the game, can display stuff the way I want, and am now just starting to turn it into a game. Since I have a design for my game structure complete, this means understanding more about compatibility etc.

Thankfully, I still have my day job if I fall on my face;)
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Postby seed » Tue Apr 06, 2010 2:03 pm

Worked great. Thanks. Studying the manifest documentation helped with other stuff too. Again, thanks.
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Postby MichaelEGR » Tue Apr 06, 2010 2:20 pm

Awesome.

You might be interested that I'm releasing a Java based Quake3 class rendering engine called Auriga3D as a prime example of the real time app & game dev middleware that I'll be putting out soon. You mention working on a Quake mod in a previous post in the thread, so this may be of interest. It's just the level renderer and at that not fully complete, but a good way to learn OpenGL w/ Java on Android. Send a message to the contact email found on the http://www.typhon4android.org page if you want to receive an update when it is released.

Cheers...
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Postby seed » Tue Apr 06, 2010 5:36 pm

Sounds like a challenge. The spline stuff should be interesting coding if you are taking it on. BSPs always confused me too. I get the concepts, but the implementation is a bitch. Oh yeah, and the shaders. Wow, lot's of work ahead of you.

As for my game, I don't think I will need anything as sophisticated as you are developing. My engine code is basically done and supports my simple game just fine. But, thanks for the info and I will keep track of your progress.

Good luck.
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Top

Re: Screen resolution differences due to orientation

Postby Sagar jacky » Thu Dec 06, 2012 12:12 pm

I got a different resolution of 380*456 while using this G1 orientation resolution and I was thinking to make a high resolution when I use the vertical angle. I hope the pointers you have mentioned in the posting was much helpful for me. http://www.gripgophone.com"
Sagar jacky
Junior Developer
Junior Developer
 
Posts: 19
Joined: Wed Nov 21, 2012 6:03 am

Re: Screen resolution differences due to orientation

Postby dipzee » Wed Jul 17, 2013 12:53 pm

I would like to know whether there will be any change in the screen resolution as we change the orientation of the screen G1. In different orientation the value of the resolution changes. Do I need to get this fixed?
windowslivehelpnow.com
dipzee
Freshman
Freshman
 
Posts: 7
Joined: Wed Jul 17, 2013 7:18 am

Re: Screen resolution differences due to orientation

Postby dipzee » Fri Jul 26, 2013 12:25 pm

great
dipzee
Freshman
Freshman
 
Posts: 7
Joined: Wed Jul 17, 2013 7:18 am

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests