"Yet Another Android Resolution / Scaling Thread"

Previous topic - Next topic

Crivens

The 3D entity system. I would have thought the ideal way to make 2D objects in 3D would be to alter the 3D entity system code so that you can flag an object as 2D with 2D coords, and then in the function which re-draws everything do the correct screen2world movement calculations. I just don't know exactly how to implement the final bit as there is a fair bit going on with lighting, shadows etc that looks pretty complicated to mess with.

Or is it more a matter of using the 3D entity system, and then using separate x_make2d and X_camera and screen2world commands outside of it? Sorry, not been using 3D for long.

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

Kitty Hello

I can make such a function for the ES. No big deal.

Crivens

Excellent :) I know it's cheeky but any chance of while you are at it checking the lighting code for iOS (because of that weird brightness I was getting only on iOS)? I'll promise to shut up then for a while. :x Maybe...

Did you get the TP in the end? I'm really quite enjoying it now and really will only be swayed by an iPad if they really do come out with a retina version next year.

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

Falstaff

I have been trying to work on implementing the scaling code ampos has so graciously provided, and seem to have it working under windows. For some reason it won't work when I try to test the app out on my tablet :/ It's almost as if it's an issue with the USESCREEN command maybe? It looks like the sprite I'm drawing to with USESCREEN 1 doesn't have anything when I draw it to the back buffer using USESCREEN -1. I basically just get a black screen. I can for example print text to screen -1 (the backbuffer) and it shows up fine.

I have included a simple demo project that tries to scale a screen of 320x480 to your android's resolution. It simply tries to draw a rectangle for the screen size to show the screen border, which then gets scaled up to whatever size the app's resolution is run in.

Again, this seems to work fine under windows (which in the sample project scales up to a window sized 480 x 720), but not on my asus eeepad transformer. Anyone able to test this on another device? Any ideas what could be going on here?

[attachment deleted by admin]

ampos

My current Showscreen function:
Code (glbasic) Select

getscreensize xres,yres

FUNCTION sc:
LOCAL x,y,xz,yz,z

VIEWPORT 0,0,0,0
USESCREEN -1

xz=xres/1024;yz=yres/640    //scales with aspect ratio
z=MIN(xz,yz)

INC alfa,dalfa                          //autofade! Just set alfa&dalfa as global
IF alfa>-0.01                           //alfa=-0.01 dalfa=-0.01 for fade IN
alfa=-0.01;dalfa=0         //alfa=-1 dalfa=0.01 for fade OUT
ENDIF                                     // dalfa is the speed

IF alfa<-1
alfa=-1;dalfa=0
ENDIF

ALPHAMODE alfa

x=(xres-(1024*z))/2
y=(yres-(640*z))/2

// STRETCHSPRITE 100,x,y,1024*z,640*z    //it didnt work on my Android tablet

STARTPOLY 100,0                                     //and they said this is faster!
POLYVECTOR x,y,0,0,RGB(255,255,255)
POLYVECTOR x,y+(640*z),0,640,RGB(255,255,255)
POLYVECTOR x+(1024*z),y+(640*z),1024,640,RGB(255,255,255)
POLYVECTOR x+(1024*z),y,1024,0,RGB(255,255,255)
ENDPOLY

IF MOUSEAXIS(4)=1 THEN ShowZones()
IF KEY(31)                                     //press S for a screenshoot
SAVEBMP RND(9999)+".png"
END
ENDIF

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)
VIEWPORT 0,0,0,0

ENDFUNCTION
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

ampos

Code (glbasic) Select
IF KEY(1)
END
ENDIF


you dont need that, just put

Code (glbasic) Select
ALLOWSCAPE TRUE

and ESC key will quit


And your program... it should work. Perhaps is the same error I got with stretchsprite, fixed when I changed to polyvector.

Also try to define at hand screen values. Instead of getscreensize x,y just x=320 y=480

also I got sometime ago a someking of bug using GENSPRITE and just do it the other way: spscreen=1

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

Falstaff

Hm.. well I've gotten your code working again under windows, but it won't work on my device..!  :noggin:

After reviewing the glbasic docs for CREATESCREEN I see this note:
QuoteGLBasic uses the OpenGL extension GL_EXT_framebuffer_object for real OpenGL implementations. This extension can cause trouble on some (generally rather old) systems. In this instance, GLBasic will still provide the CREATESCREEN functionality however it may become slow and the screen size might be limited to the physical window size.

Use PLATFORMINFO$("GLEXT:glBindFramebufferEXT") to check whether your card supports the fast version - it will return 1 if it is supported.

When I check that platforminfo command, I see that my windows laptop returns TRUE, but my tablet returns FALSE :(
"it might be slow and limited to the physical window size"
[edit]
Just tried it out again with a CREATESCREEN command set to the physical window size, still won't show anything on my tablet.. seems like CREATESCREEN doesn't work at all..! bah
[/edit]
well then.... not too sure what I should do.. this is a brand new tablet sporting the latest version of the OS and everything, why would this extension be unsupported?

Are there any alternatives to scaling that don't use CREATESCREEN? I guess my only option is to actually scale all of the individual drawing commands I do, and keep drawing to the backbuffer.. hrm.. sounds like a pain but I guess not sure what else I can do.. I wonder if this is the norm for anyone else?

Kitty Hello

ignore that extension check. It's not an extension for mobile devices anymore.
Android, right? CREATESCREEN should really work. Just use it without the check.

Falstaff

Oh ok so the extension thing is irrelevant, well then I'm really not sure why this won't work on my device.

I attached my current example code I'm playing around with. It basically calls CREATESCREEN 1 and USESCREEN 1 to work with a virtual screen buffer, and draws a rectangle the size of the original resolution (320x480) to this buffer, and then uses POLYVECTOR to draw this virtual buffer to the back buffer.

I even tried doing a DRAWSPRITE after, which of course simply draws the un-scaled rectangle. Then did a PRINT and a RECT for good measure.

On my laptop it works fine, you see the scaled source rectangle filling the whole window, along with the DRAWSPRITE'd smaller rectangle on top, and finally the word "TESTING" printed in the corner, along with a little rectangle I draw with RECT.

On my android device, all I see are the PRINT and the RECT. Trying to draw the sprite I created with CREATESCREEN seems to not really be doing anything.

Is there anything I'm doing wrong in the code? It's basically what ampos provided, updated with some globals instead of hard-coded numbers.

[attachment deleted by admin]

Crivens

QuoteAre there any alternatives to scaling that don't use CREATESCREEN?
Yes. I mentioned scaling routine code I posted a while back earlier in this thread (http://www.glbasic.com/forum/index.php?topic=6415.0). But it's not as hard as you believe. The routine automatically scales all pngs if a graphic versions flag has changed and the screen size is different to the intended. It uses sprite2mem so you retain all the different levels of transparency (unlike grabsprite which will only get one really). My latest version ignores 3D images (prefix with 3D) as these don't really need to be resized, and has a progress bar. Once it loads the graphics the first time then as long as the graphics version flag doesn't change it will use the resized graphics from then on. No slowdown with scaling methods like createscreen as you are just drawing sprites like you normally would. When it comes to the mouse just change the routine like I show in the example so that X and Y are correct to the target resolution. Then whenever you draw a sprite (and if you have a routine like the 3D ES system then can all be done for you) just remember to multiple by the ratio. So 100*x,100*y instead of 100,100. That's about it really. Couple of things to look out for but is pretty simple. Plus it has another advantage of using up a lot less memory because the images are resized.

Saying all that, if I could get the new 3D code Gernot put into the ES system to work to allow 3D objects on the screen in a 2D position, then I could replace 2D images with 3D ones (ie. make a plain rather than a cube), but it doesn't seem to work for me. Plus it would really need to be able to allow an object to be not effected by lights. Would totally work then and no resizing would be required unless you wanted to save memory really. Gernot?

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

ampos

Made some changes and now it works fine on my Android (800x480)

Code (glbasic) Select
GLOBAL ScreenWidth = 320, ScreenHeight = 480 // Our "standard" resolution we are scaling up from
GLOBAL xres, yres
GETSCREENSIZE xres,yres
GLOBAL spScreen = 100

//CREATESCREEN 1, spScreen, ScreenWidth, ScreenHeight

ALLOWESCAPE TRUE
CREATESCREEN 1, spScreen, xres, yres
USESCREEN 1

WHILE TRUE

GOSUB Render

WEND

SUB Render:

DRAWRECT 0,0,320,480,RGB(255,0,0)
PRINT "BIG TEXT",50,50

// DRAWRECT 0, 0, ScreenWidth, ScreenHeight, RGB(255, 0, 0)
// DRAWRECT 1, 1, ScreenWidth - 2, ScreenHeight - 2, RGB(0, 0, 255)

sc()

ENDSUB


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



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

xz=xres/ScreenWidth;yz=yres/ScreenHeight // defined elsewhere as GLOBAL ScreenWidth = 320, ScreenHeight = 480
z=MIN(xz,yz)
x=(xres-(ScreenWidth*z))/2
y=(yres-(ScreenHeight*z))/2

STARTPOLY 100,0                                     //and they said this is faster!
POLYVECTOR x,y,0,0,RGB(255,255,255)
POLYVECTOR x,y+(ScreenHeight*z),0,ScreenHeight,RGB(255,255,255)
POLYVECTOR x+(ScreenWidth*z),y+(ScreenHeight*z),ScreenWidth,ScreenHeight,RGB(255,255,255)
POLYVECTOR x+(ScreenWidth*z),y,ScreenWidth,0,RGB(255,255,255)
ENDPOLY

PRINT "SMALL TEXT",0,0
//PRINT PLATFORMINFO$("GLEXT:glBindFramebufferEXT"), 100, 100

SHOWSCREEN
VIEWPORT 0,0,0,0
ALPHAMODE -1
USESCREEN 1
SETTRANSPARENCY RGB(0,0,0)
DRAWRECT 0,0,ScreenWidth,ScreenHeight,RGB(0,0,0) // will draw black colour _AND_ transparent alpha
SETTRANSPARENCY RGB(255,128,0)

ENDFUNCTION
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

Falstaff

Crivens, do you have a link to the routine you are referring to? I just did a search for posts by your username and couldn't find it..

ampos, yeah that code works fine on my computer as well, but still doesn't show anything on my android :/ just the "SMALL TEXT" PRINT output to the backbuffer, nothing to the virtual screen shows up. Not sure why, pretty frustrating though..!

This tablet seems to be kinda buggy though, maybe it's something to do with the new TEGRA 2 processor it has, or the drivers for it or something.. For example the little time trial nag thing that shows up only shows a white rectangle with a little time bar under it, no actual log inside the rectangle.. some apps I've downloaded just crash, etc.. I may end up returning it and trying with another one.. Ideally my game code would work on all android devices though of course..!

ampos

This code I sent you works on my tablet Coby Kyros 7024 2.2 as in Windows.

I changed the project settings Android screen size from your 9999x9999 to 2000x2000. Try setting up your real device resolution...
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

Crivens

Quotedo you have a link to the routine you are referring to
Look at my last post again. I modified it: http://www.glbasic.com/forum/index.php?topic=6415.0I do have a newer version (avoids 3D graphics and has a progress bar) but I'm away for a week in Dubai so can't post yet.

Quotebut still doesn't show anything on my android
I had problems with my Android 800x480 tablet until I upgraded to 2.3. Works much better then. Saying that I have had createscreen problems on certain devices. Mainly older ones. My main development laptop (bleeding edge back about 5 years ago and still not bad) just doesn't do it at all for example (old ATI 9600 Turbo Pro card). It's the main reason I went with alternative routines.

QuoteIdeally my game code would work on all android devices though of course
Yeah, don't take that to the grave or anything. I've found Android devices are a bit of a mixed bag. They are the most similar to PCs really. In a bad way. There are so many different types that you just can't get something working on everything. Anything before 2.2 for example and you are stuffed. My wife's Wildfire just shows everything in white. My Android tablet shows everything upside down...

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

Falstaff

Quote from: ampos on 2011-Sep-15
This code I sent you works on my tablet Coby Kyros 7024 2.2 as in Windows.

I changed the project settings Android screen size from your 9999x9999 to 2000x2000. Try setting up your real device resolution...

Yeah everything is working fine in windows.. but unfortunately not on this asus transformer tablet :/ I tried changing the project resolution to 800x1280, but it does the same thing.. I think the resolution is being set up fine, as I can see the drawing commands I'm doing to the backbuffer and they seem to be in native (tiny) resolution. It's just the CREATESCREEN part that I think isn't working on this particular device.

It's running Android 3.2, which AFAIK is the latest version of android.

Crivens thanks for the link! I'll start setting up some sort of demo project to see if I can get this implementation working I guess.. I'd be interested in seeing your newer code if you get a chance to post it when you return from your trip.

Thanks again everyone, this is proving frustrating but your suggestions are all very appreciated!