I have been able to successfully allow my UI to extend over edges of my game on higher resolutions by using the Android Guide and by implementing this code on the GL10 object:

gl.glTranslatef(GTEngine.get_SCREEN_RATIO(), 0f, 0f);

Where the first parameter is the ratio calculated by dividing the width by the height.

My confusion arises in the ability to use :

gl.glScalef(n,n, 1f);

... to scale the image by using the same screen ratio in order to account for the "growth" or "shrinkage" that comes with different resolutions. Does anyone have a solution for this n variable? I cannot seem to make up some mathematically solution that works, and am worried that I may be forced to build a case by case logic (>.>)

  • \$\begingroup\$ What's the end result you're looking for with the scaling? Can you give an example? \$\endgroup\$
    – House
    Jul 30, 2013 at 18:12
  • \$\begingroup\$ I am looking for a solution that results in an a Density Independent GL10 Object. \$\endgroup\$
    – Justin
    Jul 30, 2013 at 18:16
  • \$\begingroup\$ 'if(densityRatio > 1.666f){ gl.glScalef(n,n, 1f)}' \$\endgroup\$
    – Justin
    Jul 30, 2013 at 18:19

1 Answer 1


If I'm understanding you correctly you want an object to scale and appear the same size /ratio (relative) on whichever device you are using? (i.e., so it doesn't appear stretched in either the X or Y direction)?

If so, the way I worked around this was to decide the size I wanted my object to appear on my development device, so on my Nexus 10 which has a res of 2560 x 1504 (Ratio of 1.7) , my sprites are 102 x 100 in size.

Therefore, I said:

102/2560 = 0.03984375f

100/1504 = 0.0664893617021277f

And then, in my code just just did:

(pseudo code follows)

sprite width = (0.03984375 * current Viewport Width)
sprite height =(0.0664893617021277 * current Viewport Height)

I'm not using GLScalef to scale my objects though, I'm manipulating the vertices directly. But this results in objects of the same relative size and ratio on all screens which (I think) is what you're after?

  • \$\begingroup\$ Why are manipulating the vertices directly? \$\endgroup\$
    – Justin
    Aug 9, 2013 at 15:14
  • \$\begingroup\$ It was just the way I did things @Justin, no specific reason, I researched the different ways to scale and move my sprites and just decided on that way of doing things :-) \$\endgroup\$ Aug 9, 2013 at 17:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .