Android Graphics problem

Previous topic - Next topic

UBERmonkeybot

Hi,
I am a total NOOB at GLB,i have created a prog to bounce a ball round the  screen as a test,it runs fine in windows but when i compile it to Android i just get a block moving around inplace of the ball.
Does anyone have any ideas,I have read loads of stuff on the forum but still cant work out what is going on.



Code (glbasic) Select
// --------------------------------- //
// Project: bounce your balls
// Start: Saturday, June 20, 2015
// IDE Version: 12.312


// FREE-VERSION:
// Need Premium for Features:
// 3D Graphics
// Network Commands
// INLINE C/C+++ code

// SETCURRENTDIR("Media") // go to media files

TYPE tgame
sx
sy
ENDTYPE

GLOBAL game AS tgame

TYPE tc
x=100
y=200
xv#=1
yv#=1
ENDTYPE
GLOBAL c AS tc


GETSCREENSIZE game.sx,game.sy

GLOBAL progC=1
circle (20,20,20,10,0xff,0,0,0,1,0xff)
GLOBAL circSpr=1
GRABSPRITE circSpr,0,0,40,40

SETLOOPSUB  "MainLoop"


DEBUG "debug code"


FUNCTION logoscreen:
PRINT 200,200,"Bouncy balls"
SHOWSCREEN
ENDFUNCTION

FUNCTION Gameloop:
LOCAL x=200//RND(game.sx)
LOCAL y=200//RND(game.sy)
LOCAL rad=50//RND(50)
DRAWSPRITE circSpr,c.x,c.y
c.x#=c.x#+c.xv#
c.y#=c.y#+c.yv#
IF c.x#>game.sx-40 THEN c.xv#=-RND(10)
IF c.x#<0  THEN c.xv#=10
IF c.y#>game.sy-40 THEN c.yv#=-RND(10)
IF c.y#<0  THEN c.yv#=10
SHOWSCREEN
ENDFUNCTION


FUNCTION circle: xs,ys,r,s,c1,c2,c3,thickness,fill,fillCol

LOCAL a,cox#,coy#,cx#,cy#
cx#=COS(a)*r
cy#=SIN(a)*r
cox#=cx#
coy#=cy#
// DRAWLINE xs,ys,xs+10,ys,0xff0000
FOR rd#=r  TO r+thickness STEP 0.5
FOR a=0 TO 360 STEP s
cx#=COS(a)*rd#
cy#=SIN(a)*rd#
DRAWLINE xs+cx#,ys+cy#,xs+cox#,ys+coy#,RGB(c1,c2,c3)
cox=cx
coy=cy
NEXT
NEXT

//IF fill THEN FloodFill (xs,ys,fillCol)//,xs-(10),ys-(10),xs+(10),ys+(10),0)


ENDFUNCTION // CIRCLE



SUB MainLoop:
IF progC=0 THEN logoscreen ()
IF progC=1 THEN Gameloop()
ENDSUB





FUNCTION FloodFill: Pix_Num_X,Pix_Num_Y,fillcol%,screenx%=-1,screeny%=-1,width%=-1,height%=-1,Preview%=FALSE
//
// Pix_Num_X, Pix_Num_Y This the starting point to flood within the captured area of screen.
//                      These numbers are in relation to the sprite of the captured area, not the location of the pixel on the screen itself.
//
// fillcol              This is the fill color Floodfill will use to flood. The fill covers all pixels within the captured area which share the original color of
//                      the starting pix_num, and is limited by the edges of the captured area contained in the sprite, and will not cover other colors
//                      or jump lines across the captured area which have some other color.
//
// screenx,screeny      This is the optional starting x,y for the screen area capture. If no x,y is given, the default is (0,0), the upper left corner of the screen.
//
// width, height        This is the optional width and length of the screen capture. If no width or height is given, the ending screensize values are used, which is the lower right corner of the screen.
//
// Preview         When the optional Preview parameter is set for TRUE, the captured screen area is displayed against a grid background;
//                      and the selected starting pixel is set to black, unless the background is already black in which case it is set to white.
//                      As a single pixel is very small and hard to see, so you will have to look very closely to spot it.
//                       (Note: If Preview mode is used, ALL optional parameters must be used.)
//                      This mode is intended for programer use to check his or her screen capture area.
// ---------------------------------------------------------------------------------------------------------------------------------------
LOCAL id% = GENSPRITE()
LOCAL sw,sh
GETSCREENSIZE sw,sh
//Preview%=TRUE

// If default values are present, set them based on the screen size.

IF screenx < 2 THEN screenx=0
IF screeny < 2 THEN screeny = 0
IF width < 2 THEN width = sw-screenx
IF height < 2 THEN height = sh-screeny

// Errorcheck to avoid overrunning the limits of the screen
IF screenx+width > sw THEN width = sw-screenx
IF screeny+height > sh THEN height = sh-screeny

GRABSPRITE id%,screenx,screeny,width,height

IF Preview = TRUE

        LOCAL PixHold%

        CLEARSCREEN
        DRW_Grid() // Draws a gridwork on the background so the captured section of screen is easy to recognize.
        ALPHATESTING 1.0
        DRAWSPRITE id,screenx,screeny

        // Now we display the starting pixel in either black or white, depending on the background.

        PixHold = GETPIXEL (screenx+Pix_Num_X,screeny+Pix_Num_Y)
        IF PixHold = RGB(0,0,0)
                SETPIXEL screenx+Pix_Num_X,screeny+Pix_Num_Y, RGB(255,255,255)
        ELSE
                SETPIXEL screenx+Pix_Num_X,screeny+Pix_Num_Y, RGB(1,1,1)
        ENDIF
        SHOWSCREEN;     KEYWAIT
        ALPHATESTING 0.0
        SETPIXEL screenx+Pix_Num_X,screeny+Pix_Num_Y,PixHold // Here we restore the original color of the starting pixel for the flood fill to work on.

ENDIF

TYPE Fillpixel
        x%
        y%
ENDTYPE

GLOBAL pixels%[]


        LOCAL i[]  AS Fillpixel
        LOCAL newi AS Fillpixel
        LOCAL newx%,newy%,dir%
        LOCAL fillover%,fillcolour%
        LOCAL fillmap%[]
        LOCAL red%,green%,blue%,alpha%

        IF Pix_Num_X<0 OR Pix_Num_Y<0 OR Pix_Num_X>=width% OR Pix_Num_Y>=height
                DEBUG "Out of area."
                RETURN
        ENDIF

        SPRITE2MEM (pixels[],id)

        // Convert the fill colour to SPRITEMEM format.
         fillcolour=bOR(fillcol, ASL(255, 24))

        // Get the colour that will be filled over.
        red=bAND(pixels[Pix_Num_X+Pix_Num_Y*width%], 0xff)
        green=bAND(ASR(pixels[Pix_Num_X+Pix_Num_Y*width%],8), 0xff)
        blue=bAND(ASR(pixels[Pix_Num_X+Pix_Num_Y*width%],16), 0xff)
        alpha=bAND(ASR(pixels[Pix_Num_X+Pix_Num_Y*width%],24), 0xff)
        fillover=bOR(RGB(red,green,blue), ASL(alpha, 24))

        // If the fill pixel is same colour as then abort.
        IF fillover=fillcolour THEN RETURN

//      CLEARSCREEN;PRINT fillover+" "+fillcolour,50,50;SHOWSCREEN;KEYWAIT;END

        // Set the start position.
        newi.x=Pix_Num_X
        newi.y=Pix_Num_Y
        pixels[Pix_Num_X+Pix_Num_Y*width%]=fillcolour
        DIMPUSH i[],newi

        // Reset the fill check map.
        DIM fillmap[width%][height]
        fillmap[Pix_Num_X][Pix_Num_Y]=1

        FOREACH pixel IN i[]

                // New test position based on the direction.
                FOR dir=0 TO 3

                        SELECT dir

                        CASE 0                  // Right
                                newx=pixel.x+1
                                newy=pixel.y
                        CASE 1                  // Down
                                newx=pixel.x
                                newy=pixel.y+1
                        CASE 2                  // Left
                                newx=pixel.x-1
                                newy=pixel.y
                        CASE 3                  // Up
                                newx=pixel.x
                                newy=pixel.y-1
                        ENDSELECT


                        IF newx>=0 AND newy>=0 AND newx<width% AND newy<height  // Make sure the new position is in the boundaries of the screen/sprite.
                                IF fillmap[newx][newy]=0                                                        // If not already checked continue
                                        fillmap[newx][newy]=1                                                   // Flag this pixel as now checked
                                        IF pixels[newx+newy*width%]=fillover                    // Check pixel colour is the correct fill over colour.
                                                pixels[newx+newy*width%]=fillcolour                     // Fill and make a new pixel.
                                                newi.x=newx
                                                newi.y=newy
                                                DIMPUSH i[],newi
                                        ENDIF
                                ENDIF
                        ENDIF
                NEXT
                DELETE pixel                                                                            // Remove pixel from list
        NEXT
//
        MEM2SPRITE (pixels[],id,width%,height)
        DRAWSPRITE id,screenx,screeny//;USEASBMP;SHOWSCREEN;KEYWAIT

        DIM fillmap[0][0]
        RETURN id

ENDFUNCTION
// ------------------------------------------------------------- //
// ---  DRW_Grid  --- // Just Some Interesting Wallpaper.
// ------------------------------------------------------------- //
FUNCTION DRW_Grid:

// Red Grid Lines, for lay out. ///////////
CONSTANT RED% = RGB(255,0,0),GREY% = RGB(100,100,100)
LOCAL sw%,sh%
GETSCREENSIZE sw,sh
LOCAL cnt%,sw_Inc% = sw/32,sh_Inc%=sh/32
FOR cnt = -16 TO 16
        DRAWLINE sw/2-sw_Inc*cnt,0,sw/2-sw_Inc*cnt,sh,GREY
        DRAWLINE 0,sh/2-sh_Inc*cnt,sw,sh/2-sh_Inc*cnt,GREY
NEXT

DRAWLINE sw/2,0,sw/2,sh,RED
DRAWLINE 0,sh/2,sw,sh/2,RED

ENDFUNCTION // DRW_Grid






Paul Smith

#1
Hi monkeybot1968


GRABSPRITE is you problem. try CREATESCREEN  and USESCREEN. but is slow if constantly used.

change this segment in your code

Code (glbasic) Select

GLOBAL circSpr=1
CREATESCREEN 0,circSpr,40,40
USESCREEN 0
circle (20,20,20,10,0xff,0,0,0,1,0xff)
USESCREEN -1
SETLOOPSUB  "MainLoop"


DEBUG "debug code"
Amstrad CPC 6128, ATARI STE.
Acer  SW5-173 & AMD RYZEN 7,RTX 3060TI

UBERmonkeybot

Brilliant!  Thanks that worked.

I assumed that if i drew to the backbuffer and grabbed it it would be the same result.


Darmakwolf

Quote from: monkeybot1968 on 2015-Jun-27
Brilliant!  Thanks that worked.

I assumed that if i drew to the backbuffer and grabbed it it would be the same result.

It'd work on Windows. Android has problems with GRABSPRITE.

UBERmonkeybot

Ahh,is it a bug in Android then?

spacefractal

GRABSPRITE have issues on some platforms and its a known issue for various years ago.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

erico

Yep, Gernot should look into it, it is a very handy command.
But I suspect it may be quite difficult to fix this one.

UBERmonkeybot

Thanks for the info.

kanonet

Im not sure if we can consider this a bug, i more think of it as a limitation on some platforms. Keep it in mind and work around it. Also note, that you lose alpha informations, when you use GRABSCREEN.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64