GLBasic forum

Main forum => GLBasic - en => Topic started by: Kitty Hello on 2010-Dec-08

Title: How to deal with Retina
Post by: Kitty Hello on 2010-Dec-08
Hi,

now, the iPhone can have 320x480 or 640x960 resolution. How do you want to handle that?

My idea: You get a command GETDESKTOPSIZE sx%, sy% - if that's 2x the 320x480, you have to render to a frame buffer and scale that to the screen (or you use glScalef before you draw).

Other ideas: You set the screen size in hte project to 640x960 and if it's supported GETSCREENSIZE will tell you. Otherwise the screen will be limited to 320x480 and you have to deal with that.

I think method 1 is the best.
Title: Re: How to deal with Retina
Post by: Hark0 on 2010-Dec-08
Another idea:

iScale n

n=1 for 100% screen resolution.
n=2 for 2X Scale

or

SETSCREEN width#, height#, fullscreen#, SCALE#

;)
Title: Re: How to deal with Retina
Post by: Kitty Hello on 2010-Dec-08
no. You want that for all platforms then. :D
Title: Re: How to deal with Retina
Post by: Hark0 on 2010-Dec-09
Ops!
Title: Re: How to deal with Retina
Post by: ampos on 2010-Dec-09
I don't understand method 1... Wouldn't we have a doubled (retina) resolution but with doubled pixels (as currently the iPhone does)?
Title: Re: How to deal with Retina
Post by: jaywat on 2010-Dec-09
Quote from: ampos on 2010-Dec-09
I don't understand method 1... Wouldn't we have a doubled (retina) resolution but with doubled pixels (as currently the iPhone does)?

That's how I read it too, and it seems pointless even supporting the resolution if you're just going to pixel-double it. That's what happens right now automatically if you run a 320x480 project on a retina display. The point of supporting the resolution at all is surely for us to be able to take advantage of the higher resolution screen capability?

Why don't you just give us the resolution as a project option like any other and let us decide what to do with it, rather than try and implement some special case? It's pretty trivial to supply higher res graphics and scale them down if a lower res screen. Or to even use a different media directory depending on supported resolution.

Obviously yes, we would need a reliable way to detect the actual screen supported resolution.

edit: Oh wait. I see why you're trying to figure out a workaround type method... because SETSCREEN doesn't work on an iDevice. ONLY the project option makes any difference. So if we did a retina resolution project and it was actually a low res screen, you'd see the top left corner of the project. Right? Well, in that case, the only logical answer is that SETSCREEN really NEEDS to work to override project settings so that we can write a 'universal' version.

If you don't, then we would have the utterly ludicrous situation where you'd have to deploy an iPad version, an iPhone (Retina) version, and an iPhone (Standard) version. Frankly I don't even think Apple would let you.

But in that case, my point still stands... if we can't actually use and react to SETSCREEN... why bother supporting a retina device at all? It automatically pixel-doubles from 320x480. Which appears to be what you're proposing anyway.

Assuming that you can't get SETSCREEN to actually work, which would be by far the best situation all round, then your described method 2, 'fall back from Retina to standard', would be best, because at least we can take advantage of that higher resolution.
Title: Re: How to deal with Retina
Post by: ampos on 2010-Dec-09
If SETSCREEN does (and will not) work, then we can/could make IPad resolution proyects, and check real resolution, as (maybe) iOS will fall back to closest resolution (iPad -> Retina -> Std, 1024->960->480).
Title: Re: How to deal with Retina
Post by: Kitty Hello on 2010-Dec-09
Currently you have a back buffer on Retina of 640x960. If you don't support that resolution, the program internally scales up the graphics x2 to that framebuffer. (That's what GLBasic does right now).

My idea is: on a retina you get GETDESKTOPSIZE with 640x960 and 3G gives 320x480. Then you can decide "what" you draw on that screen. So, if your game is 320x480 on a retine, it would only fit 1/4 of the screen now. You would have to take care manually to scale it up to 640x960 or really use that resolution.

The background is, once we port to Android, you _will_ get in the situation where every device has a different resolution and you have to adjust your program to cope with it. So the idea was to introduce that "GETDESKTOPSIZE" to get the idea what size you have. And on handheld devices you always make fullscreen apps, so you have to take care about filling the unwanted space.

Good idea?
Title: Re: How to deal with Retina
Post by: Moebius on 2010-Dec-09
So could we have GETDESKTOPSIZE on all platforms?  It would be a useful addition.  Also on handheld devices with varying resolutions, if the program doesn't SETSCREEN to the correct fullscreen resolution, will it automatically be scaled?  This would be useful on Android if one can't be bothered to adapt to different resolutions  :whistle:
Anyway, supporting retina resolution sounds great, not to mention the mention of Android  =D
Title: Re: How to deal with Retina
Post by: Leginus on 2010-Dec-09
Android   :enc:  glbasic strikes again.
Title: Re: How to deal with Retina
Post by: XanthorXIII on 2010-Dec-09
@Kitty - Just proving to me each day GLBasic was the best purchase I have made in a long time.

Title: Re: How to deal with Retina
Post by: Ian Price on 2010-Dec-09
GLBasic supporting Android and AppUp? Christmas has come early :D
Title: Re: How to deal with Retina
Post by: matchy on 2010-Dec-09
Huh? :blink: Wha?  O_O Android?!  :noggin: No?  :zzz: Really?  :noggin:
Title: Re: How to deal with Retina
Post by: Ian Price on 2010-Dec-09
Quote from: matchy on 2010-Dec-09
Huh? :blink: Wha?  O_O Android?!  :noggin: No?  :zzz: Really?  :noggin:

And Caanoo too, judging by THIS (http://www.gp32x.com/board/index.php?/topic/57822-universal-binary-for-wiz-and-canoo/page__pid__929650__st__0&#entry929650) post on GP32x...
Title: Re: How to deal with Retina
Post by: ampos on 2010-Dec-09
Quote from: Ian Price on 2010-Dec-09
GLBasic supporting Android and AppUp? Christmas has come early :D

Do you know that Fool's day in Spain is Dec 28th?

:enc:
Title: Re: How to deal with Retina
Post by: doimus on 2010-Dec-09
GETDESKTOPSIZE would be the most useful command on all platforms that have multiple resolutions. I'm all for it.
For example, on "big" platforms, screen resolutions go from 1024x600 (netbooks) up to 2560x1600 or whatever.
Running an 640x480 window on 1920x1080 15" laptop screen is rather crappy experience. Same as running 1280x1024 window on a netbook.

If you want to have decent windowed game, you really need different window sizes for different screens.
Title: Re: How to deal with Retina
Post by: Kitty Hello on 2010-Dec-11
OK, got it working. The downside is, you can't really switch between highres and lowres.

So far, if you set the project options to 320x480 or vice versa, you get this resolution for safe.
If you set that setting to 640x960 or v.v. you get either that, _or_ 320x480 if it's not supported. You check with GETSCREENSIZE.

I will have to do some tests on the old iPod and iPad before I release an update, but it's looking promising so far. Can't get the device now - kid has it almost under the pillow...
Title: Re: How to deal with Retina
Post by: blackway on 2010-Dec-13
Hi Gernot,
Can we set the resolution to 1024 x 768 or vice versa (IPAD) and GlBasic scale down to 960x640 or 480x320 if it's not supported? (search for the better resolution that is supported for the device). If you can do that we can build universal binary apps!
What do you think??
Cheers!

Title: Re: How to deal with Retina
Post by: Kitty Hello on 2010-Dec-13
You can make a universal binary. I'll make an test example and post it.
You have to do the scaling yourself. You can, however, just render to a CREATESCREEN and scale that with STRETCHSPRITE.
Title: Re: How to deal with Retina
Post by: blackway on 2010-Dec-13
That's great! :good:
Thanks
Title: Re: How to deal with Retina
Post by: ampos on 2010-Dec-13
Instead of scaling, we (or at elast me) would like to get the highest resolution avaiable, never over the project settings.

So if I set the project settings at 1024x768, with GETSCREENSIZE I want to get the higher, 1024 -> 960 -> 480 to know the real resolution.

If I set it to 480, I always get 480x320...
Title: Re: How to deal with Retina
Post by: blackway on 2010-Dec-17
Hi to all....
I'm thinking about this topic and I don't understand  what's the Gernot's solution!!  :'(
If in project options I set the resolution to 960x640 and the apps run in a older device without Retina Display I will know that using getscreensize? If it's a older device I have to scale the graphics to fit 480x320? If I scale the graphics manually How I handle, for example, mouse coords or touch coords? I must check coords divide by two ? (you know, when you have to check if the player is touching x=700 and y=600 in a device with retina display I have to check if is touching x=350 and y=300 in a older device)
Umm...Hope you understand what I trying to say....


Title: Re: How to deal with Retina
Post by: Slydog on 2010-Dec-17
Ya, I'm not following it either.

What's the issue of either letting us set the screen size in code (after we determine what device we're running on), or have GLBasic detect it for us and set the screen size automatically to the highest res? 
(But maybe we want the option of not setting the screen to the highest resolution if we find it runs slow on the newer devices, so giving us the freedom to choose would be the best I think, or we don't want to have dynamic code to resize our game layout).

Is it an OpenGL problem?  An internal GLBasic problem?

And like blackway mentioned, with the current solution, how does the mouse (ha finger I guess) coordinates get scaled too?
Title: Re: How to deal with Retina
Post by: Kitty Hello on 2010-Dec-20
The problem is: Maybe you don't _WANT_ to use the full retina for your game. My games usually don't. So, I think there must be a way to define exactly what you want and where.
I'll do a tutorial when I finished testing the iPad. I had a lot to do until this weekend, so that's the reason for the delay.
Title: Re: How to deal with Retina
Post by: ampos on 2010-Dec-20
Quote from: Kitty Hello on 2010-Dec-20
The problem is: Maybe you don't _WANT_ to use the full retina for your game. My games usually don't. So, I think there must be a way to define exactly what you want and where.
I'll do a tutorial when I finished testing the iPad. I had a lot to do until this weekend, so that's the reason for the delay.

The app should open the biggest screen it can, never bigger than the project screen settings.

Examples:
1.- I am making a Universal App: settings:1024x768. On iPad it would open 1024, on 4G 960 and in 3G/S 480.
2.- I am making a Retina (4G) app: settings at 960x640: on iPad 960 (can it be?), 4G 960 and 3G/S 480.
3.- I am making a "old" app: settings at 480x320. On all idevices it will open a 480 screen.

The programmer has to check at the start of his app the real screen size with GETSCREENSIZE, and load different graphics on resolution or scale them
Title: Re: How to deal with Retina
Post by: Kitty Hello on 2010-Dec-20
Right, that's what I'll do.
Title: Re: How to deal with Retina
Post by: djtoon on 2010-Dec-21
just updated to the new version

so if i set my app for 640x960 il lget retina and in the old phones ill get 320x480 ?
and with getscreensize ill get the size and load sprites to fit it?

is that right?
Title: Re: How to deal with Retina
Post by: Kitty Hello on 2010-Dec-21
absolutely.
Title: Re: How to deal with Retina
Post by: blackway on 2010-Dec-21
And what about mouse input?
If I set in project options 960x640 I need to check if the player touch in x=500, y=500 in retina display and x=250, y=250 in old devices or Glbasic handle that automatically?
Thanks Gernot!
Cheers
Title: Re: How to deal with Retina
Post by: Slydog on 2010-Dec-21
I would hope GLBasic DOESN'T handle the mouse conversion automatically!

If I have to manually position my objects (ie. buttons) depending of the device (which I do prefer, to have full control), my objects know their location and size, so I use those in my Button_IsClick() event handler.  I'm expecting the mouse functions to return the actual mouse pixel coordinates.

Just create a TYPE like this:
Code (glbasic) Select

TYPE TRect
  x%
  y%
  w%
  h%

  FUNCTION Set%: x%, y%, w%, h%
    self.x = x
    self.y = y
    self.w = w
    self.h = h
  ENDFUNCTION

  FUNCTION IsClick%:
     ... handle checking mouse coordinates to see if they are within self.x, self.y, self.w, self.h, RETURN TRUE or FALSE
  ENDFUNCTION

ENDTYPE


Then, you don't need an actual object (or whatever), just declare regions for clicking such as:

Code (glbasic) Select
LOCAL button_fire AS TRect
IF screen_width = 480
  button_fire.Set(10, 10, 50, 50)
ELSEIF screen_width = 960
  button_fire.Set(20, 20, 100, 100)
ENDIF

//Then check if the 'button' area is clicked by:
IF button_fire.IsClick() THEN . . .


Just typed the above by hand, nothing tested of course.
Title: Re: How to deal with Retina
Post by: Leginus on 2010-Dec-21
Now why didn't i think of that.  :noggin:
Nice one!
Title: Re: How to deal with Retina
Post by: ampos on 2010-Dec-21
Even easier...

Code (glbasic) Select

If screen=480 then ratio=1   //just once at the start of the program
if screen=960 then ratio=2
if screen=1024 then ratio=2.1333

button n,x*ratio,y*ratio,witdh*ratio,height*ratio


That's how I programmed my game KRAKOUT, that support all resolutions, 320x240, 480x320, 640x480, 960x480 & 1024,768

Title: Re: How to deal with Retina
Post by: Slydog on 2010-Dec-21
The iPad's X-Ratio is 2.1333 (1024 / 480), but the iPad's Y-Ratio is 2.4 (768 / 320).
So, you would need two ratios, one for x, and one for y.

The iPad has a different aspect ratio so using my method allows you to customize the layout for that display.

But, ya, that should work fine, if you want the objects displayed in exact proportion and position on each device, your way would sure make things simpler!
Title: Re: How to deal with Retina
Post by: Leginus on 2010-Dec-21
Or even easier.....

BumbleBomber 59p
BumbleBomber HD 59p
BumbleBomber for Ipad  59p
:D
Title: Re: How to deal with Retina
Post by: Slydog on 2010-Dec-21
Ha, took me a second to realize what 59p was (I was thinking 59 frames a second, progressive!).
That would be currency right?!  (I'm from Canada!  We use 'b' for beaver pelts!  :whistle:)

But ya, 3 separate apps, then you can control pricing and features, but for development you could use the same GLBasic project and just use the following in an 'Initializing' module (and comment / uncomment the appropriate ?DEFINE for the platform you are compiling for):
Code (glbasic) Select
?DEFINE TARGET_IPHONE
//?DEFINE TARGET_IPHONE4
//?DEFINE TARGET_IPAD

?IFDEF TARGET_IPHONE
... IPhone specific code, layout, etc
?ENDIF

?IFDEF TARGET_IPHONE4
... IPhone 4 (retina) specific code, layout, etc
?ENDIF

?IFDEF TARGET_IPAD
... IPad specific code, layout, etc
?ENDIF
Title: Re: How to deal with Retina
Post by: Kitty Hello on 2011-Jan-10
So sorry - I really try to fix that bug quickly.
Title: Re: How to deal with Retina
Post by: pinete on 2011-Feb-15
God! deal with mouse coordinates on iphone is a nightmare! Is it really as harder as it seems handle this issue in a global way? I mean, doing GLbasic the 'automatic coordinates traslation process?
There is a matter I still don't understand at all: What it is supposed to be the default Glbasic coordinates? I guess it is something to be known as it is a need in order to apply ratios to reach each screen? right?
Someone can help me a little with this issue? I'm lost since I've compiled my game in xcode and the coordinates detection is absolutely weird!
regards!
Title: Re: How to deal with Retina
Post by: ampos on 2011-Feb-16
On my (horizontal) iPhone game I have this:

Code (glbasic) Select
SETACTIVEMOUSE 0
MOUSESTATE mx1,my1,b11,b21

?IFDEF IPHONE
SETACTIVEMOUSE 1
MOUSESTATE mx2,my2,b12,b22
SETACTIVEMOUSE 0
IF retina=true
my2=(my2-320)*2
mx2=mx2*2
my1=(my1-320)*2
mx1=mx1*2
ENDIF
?ENDIF


I have not tested if it is fixed in GLB 9...
Title: Re: How to deal with Retina
Post by: Kitty Hello on 2011-Feb-16
I'll have to check that out. Weekend, OK?
Title: Re: How to deal with Retina
Post by: pinete on 2011-Feb-16

Ampos: Thanks a lot for sharing ;) mil gracias por la info! I'll check it out and let you know..

Kitty Hello: Thanks a lot as well, I hope don't bother you but I'm pretty sure the whole GLbasic community will be very pleased if there exist an update to fix this strange x,y mouse/touch conversion as it is very uncomfortable. Thanks a lot in advance, honestly.

best,
Title: Re: How to deal with Retina
Post by: ampos on 2011-Mar-08
Don't know when, but now it is fixed the iPhone 4 mouse/coordinates thing