Author Topic: "Yet Another Android Resolution / Scaling Thread"  (Read 8865 times)

Offline Falstaff

  • Mr. Polyvector
  • ***
  • Posts: 148
    • View Profile
Hello!

So I am still happily working away on my first glbasic game with an artist friend of mine. Although we're targeting iOS and Android, I've only just picked up an android device (tablet!) to test with. We've been testing on windows so far.

We are currently using 32x32 sprites for our main puzzle pieces, and have been testing under windows with the project settings set to the resolution 320x480. My tablet has a resolution of 1280x800. When I try to run my app on my tablet, this results in it taking up a tiny 320x480 part of the screen. I've attached a pic to show what I mean ;p

Anyway, I was sort of under the impression that somehow things would scale up on the device. I get the feeling I may have to do that myself? I am new to android development but I know there's an AndroidManifest.xml that seems to hold certain relevant settings for the project in terms of scaling. As far as I can tell though GLBasic generates all those platform-specific files for me while doing the build->multiplatform process. I'm not really sure how to change that file and have GLBasic pick up the new changes.

Does anyone have suggestions?

Thanks in advance..!

[attachment deleted by admin]
« Last Edit: 2011-Sep-06 by Falstaff »

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 915
    • View Profile
you'll find some more useful information here:

http://developer.android.com/guide/practices/screens_support.html

on my HTC device I changed the settings in AndroidManifest.xml as follows:
Code: GLBasic [Select]
<supports-screens android:resizeable="true"
          android:smallScreens="true"
          android:normalScreens="true"
          android:largeScreens="true"
          android:anyDensity="true" />
 

somewhere in the forum I've read, that some of those settings are obsolete, but don't remember which one.
Problem with this settings: Always the highest available resolution is used independet of your procject settings.



Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Quote
Always the highest available resolution is used independet of your procject settings
Depends on the device. Using 320x480 in iOS scales up on a 640x960 (ie. Retina) device automatically.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
As far as I did check it, the screens will not auto-scale on Android since OS id 3 (1.2 perhaps?).

I have made a solution using a sprite and scaling it.

I make my game for a target resolution of 1024x640, and scale down to device resolution, so I have the highest quality posible (it is better to scale down than scale up). It also draws the image centered on screen.

I choose 1024x640 because:
-It is 16:10, as many PCs had.
-It is native iPad resolution (1024x768)
-It is the biggest texture size for some devices (iphone 3G is 1024x1024)

Code: GLBasic [Select]
createscreen 1,100,1024,640
usescreen 1  //just add this at the start of your program



FUNCTION sc:  //call sc() instead of showscreen
        LOCAL x,y,xz,yz,z

        VIEWPORT 0,0,0,0
        USESCREEN -1;ALPHAMODE -1

        GETSCREENSIZE x,y
        xz=x/1024;yz=y/640
        z=MIN(xz,yz)
        if z>1 then z=1 //this line dont scale up. Remove if want to scale up.
        STRETCHSPRITE 100,(x-(1024*z))/2,(y-(640*z))/2,1024*z,640*z

        IF MOUSEAXIS(4)=1 THEN ShowZones()
        SHOWSCREEN
        VIEWPORT 0,0,0,0
        ALPHAMODE -1
        USESCREEN 1
        SETTRANSPARENCY RGB(0,0,0)
        DRAWRECT 0,0,1024,640,RGB(0,0,0) // will draw black colour _AND_ transparent alpha
        SETTRANSPARENCY RGB(255,128,0)
ENDFUNCTION
 
« Last Edit: 2011-Sep-06 by ampos »
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Search the forum for my generic resolution code. It resizes all images and saves them in another directory. If you don't update a graphics version file then the next time it loads it will just load the resized versions immediately, saving time and memory. Plus it uses the sprite memory commands so retains all different levels of transparency (ie. if you have images with more than one alpha colour)

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
Crivens method had his adventages and disaventages:

PLUS
-Memory usage (less)
-Fastest drawing speed

MINUS
-Will not work on some Android devices (mem2sprite, grabsprite,... dont work)
-Harder to program, as you have to code with relative (to real screen size) coordinates.
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Don't forget the multiple levels of transparency ;) Ah, ang on, didn't really read your code fully. Yeah, can really do the same then right?

Also I've tried it on my Android tablet and it worked fine. It uses mem2sprite not grabsprite (my old routine used grabsprite but obviously you can't get the different levels of transparency). Note that createscreen/usescreen didn't work (at least v8 didn't) on my older laptop. Ok is a few years old but still has Vista on it and could run Doom3 *just* about ok at 1920x1200 resolution. Just totally refused to do those commands for some reason. No big deal for mobiles but might be an issue if want to work on PCs.

I don't find it too hard to program. You just have to remember to use *x and *y for anything drawn to the screen. Placing /x and /y into the mouse routines means you don't have to worry about that as any touching of the screen works out to the correct position on the target resolution. True, there are one or two confusing things at times but works pretty well.

My biggest problem with it is all I do it pick out the pixels at the correct points to scale the image. While this works for upscaling and downscaling it could have a better algorithm for picking the colours when downscaling. For example I used a single pixel black edge for fonts and this could get lost on downscaling. Of course using double pixel edges works fine but it would be nice if a better algorithm could be used to be cleverer. The other problem is the built in font system. I've found single letters on a scaled font will be fine normally, but if a whole sentence is used then leakage from one letter gets into another. Not a biggie (I just use my own routines) but is a little annoying. Probably a slight mistake in my code, I dunno, but annoying.

On the other side of the coin since mucking around with 3D I think I would just do everything in 3D in future. Even the 2D bits. It all scales nicely without any resizing of graphics (ok, so uses up more memory, but if you zoom in on a 3D object then should be even better close up). Only problem is I cannot get that 2D to 3D world command working properly. Then could just say exactly where you want a button, text etc and use it to plonk the 3D in the correct place for a 2D view. Only thing I haven't tried is if alphmode -1 works on 3D objects. If not then will stick to 2D for buttons/fonts as the icon program I use is brilliant for using multiple alpha channels to give a smooth icon. My old single alpha icons in Rotaslider look like crap in comparison.

Cheers
« Last Edit: 2011-Sep-06 by Crivens »
Current fave quote: Cause you like musicians and I like people with boobs.

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
My Android tablet 2.3 fails miserably on grabsprite/mem2sprite, and Gernot says it is a driver issue...

On my previous (unfinished) game I have made/scaled manually all the graphics on photoshop, and use

getscreensize x,y
mediapath$="Media/"+x+"/"

and have in /media dir 3 extra dirs:

media/480
media/960
media/1024

and the game is completly coded with X,Y coordinates multiplied by "zoom" (480=1, 960=2, 1024=2.13). Yes, it works, but is is a real pain in the ass to keep it aligned.
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10715
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Only problem is I cannot get that 2D to 3D world command working properly.
That's easy. X_MAKE3D, then X_CAMERA. Now use X_SCREEN2WORLD with an estimated "z" value (into-screen value) and place the 3D object there. For clicking some object you can use X_SCREEN2WORLD twice to get a "ray direction" for the pixel under the mouse and can use X_COLLISIONRAY to check if it clicked.

Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Quote
That's easy
Ok I will try it out sometime. Is there some example code/project around? Out of interest how would 3D objects work with textures that have multiple alpha channels? I have, for example, some nice multi-alpha icons that use the alpha channels to give a smooth edge, which look brilliant with 2D sprites in alphamode -1. If I create a 3D plain object and just texture it with the same graphic as the sprite then would it retain the multiple alpha channels or not?

Quote
My Android tablet 2.3 fails miserably on grabsprite/mem2sprite, and Gernot says it is a driver issue...
It might be your device. Mine works on 2.3 (think is 2.3.1 to be precise) but my wife's Wildfire fails on 2.2 (only does white for sprites).

Cheers

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10715
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
alphamode for 3D is fine. Problem might be drawing order for real 3D models. (no z-sorting performed).

Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Hmm, got the alphamode working but not exactly sure how to integrate the screen2world with the 3D entity system. Ideally I'd like to be able to set 2D flags onto each object, then in the 3D entity system it will know to deal with these differently and place them in the 3D world at the 2D X/Y/Z coords setup against the object, but I'm getting a bit lost on the actual drawing of the 3D objects. Think I'll leave for now and get on with the main game functionality as I'm really close to finishing it.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10715
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
something like this:
Code: GLBasic [Select]
MOUSESTATE mx, my, b1, b2

x_make3d
x_camera
if b1
   x_screen2world mx, my, -1,    wx1,wy1,wz1
   x_screen2world mx,my,   1,    wx2, wy2,wz2
   x_movement; x_rotation; ...
   // x_drawobj id,
   IF x_collisionray(id,0,   wx1,wy1,wz1,  wx2, wy2, wz2) <> 0.0 THEN hit()


endif


 

Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Isn't all the x_make3d, x_camera stuff inside the 3D entity system?

Preferably it would be nice to integrate it into that. Could the positioning code then be made in the drawall 3D entity function for objects that are flagged as 2D? It's a bit confusing as the function is called several times (I assume 2D flagged objects would only need to use screen2world on the 1st pass if we ignore things such as lighting and shadows for them) but would it be too late at this point to use the entity positioning functions?

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10715
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
entity system??? There's the "EntityPickLine" command.