All those different screen sizes

Problems with Canvas, OpenGL, etc...

All those different screen sizes

Postby afail » Fri Dec 17, 2010 4:39 pm

Having in mind that there are many different screen ratios today, when developing a game in openGL Es for Android, what is the right approach to create a general solution that would consider using all those sizes of the screens? I understand that If I put something like

Code: Select all
float size = .01f * (float) Math.tan(Math.toRadians(-45.0) / 2);
float ratio = (float) w / h;
gl.glFrustumf(-size, size, -size / ratio, size / ratio, 0.01f, 10.0f);


I can map my opengl world in those borders (defined in glFrustumf), but then, how can I map the user clicks on the screen and convert the screen coordinates into opengl coordinates for as many device screen sizes as possible? What I am doing now, is trying to use the MatrixStack & MatrixTrackingGL wrappers from Google API Demos (Sprite Text example), but it just doesn't work on all devices. By using those classes I get the current matrix mode:

Code: Select all
float[] pos = new float[4];

      
float[] mModelView = new float[16];
float[] mProjection = new float[16];
int view[] = {0, 0, (int)width, (int)height};
y  = view[3] - y;

getMatrix(mGl, GL10.GL_MODELVIEW, mModelView);
getMatrix(mGl, GL10.GL_PROJECTION, mProjection);
GLU.gluUnProject(x, y, 0, mModelView, 0, mProjection, 0, view, 0, pos, 0);



Hoping that pos[0] would be transformed x and pos[1] would be transformed y (also pos[2] transformed z). But it isn't. :/

What is the right approach to do this? What do game developers do in this situations?
afail
Developer
Developer
 
Posts: 31
Joined: Sat Oct 02, 2010 8:43 pm

Top

Re: All those different screen sizes

Postby mark@project8games.com » Fri Dec 17, 2010 6:27 pm

My approach has been to avoid programmatic scaling (whether it be via android's built in asset scaling or using OpenGL to scale). Its a bit more work, but I have prescaled assets in both mdpi and hdpi. This approach isn't great, but allows me to more or less use the same worldspace coordinates, but I still do have magic numbers for the different resolutions.
User avatar
mark@project8games.com
Developer
Developer
 
Posts: 41
Joined: Tue Mar 02, 2010 8:33 pm

Top

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

Who is online

Users browsing this forum: No registered users and 6 guests