DRAWRECT using POLYVECTOR from a Image

Previous topic - Next topic

spacefractal

On Android we cant use DRAWRECT and other commands. Its might fails on some devices and this will NOT been fixed at all. Its impossible.

But we can use POLYVECTOR, which works fine on Android. Here is a possible work around:

Code (glbasic) Select

GLOBAL IS24BIT=FALSE // FALSE ON ANDROID, TRUE ON OTHER PLATFORMS).

FUNCTION PaintColorRectRGB_START: imageID
IF IS24BIT=TRUE THEN RETURN
LOCAL ww, hh
GETSPRITESIZE imageID, ww, hh
IF ww=0 THEN RETURN

STARTPOLY imageID, 2;
ENDFUNCTION

FUNCTION PaintColorRectRGB: x, y, w, h, rr%, gg%, bb%, id=0
//IF x>ScreenWidth THEN RETURN
//IF y>ScreenHeight THEN RETURN

IF IS24BIT=FALSE
rr=INTEGER(rr/16)
gg=INTEGER(gg/16)
bb=INTEGER(bb/16)

LOCAL xx%=rr*64+gg*4
LOCAL yy%=bb*4

IF xx>512
xx=xx-512
yy=yy+64
ENDIF
xx=xx*2+1
yy=yy*2+1
IF xx>512
xx=xx-512
yy=yy+256
ENDIF
POLYVECTOR x, y, xx+1, yy
POLYVECTOR x, y+h, xx+1, yy+1
POLYVECTOR x+w, y, xx+1, yy
POLYVECTOR x+w, y+h, xx+1, yy+1
POLYNEWSTRIP
ELSE
DRAWRECT x, y, w, h, RGB(rr, gg, bb)
ENDIF
ENDFUNCTION

FUNCTION PaintColorRectRGB_END:
IF IS24BIT=TRUE THEN RETURN
ENDPOLY
ENDFUNCTION


This code can been little bit slower, but better alternative.

This code was used in CatchOut to avoid DRAWRECT on Android, which can fails on some devices and even crash out.

The limit here is you can only use a palette from 4096 colors.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

MrPlow

Hi Sf,

For PC use is this faster than regular Drawrect or more intensive?
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

MrPlow

tried to use it with loop of drawrects to replace but cant seem to figure out if I am missing something

I run the start part then

Loop
    Run the regular paint image
endloop
Do I need to close it off?
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

spacefractal

You need to start, then draw and then close it'd off. This is how polyester works. You can draw more than one in a batch. However drawrect is faster. This was a safe operation on Android. Hence the ekstra variable for other systems.....
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

Kitty Hello

Another option is to use mem2sprite and do a 1x1 pixel sprite. Use smoothshading false!

Qedo

sorry but two things I did not understand:
1) @spacefractal: there is a limit of 4096 colors for android?
2) @Kitty Hello: What do you mean by "option is to use mem2sprite and do a 1x1 pixel sprite" about DRAWRECT?
ciao

spacefractal

no android is 16bit color, rgb656. Its just me that wanted to do a 4096 color limit to avoid clutter to many colors on the image. you can do the image bigger with more colors.

Im just used here with 4096, which was nice for CatchOut game, where im used it.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

MrPlow

#7
Here are my DRAWRECT replacements, is there an ideal way to to DRAWLINE using Polyvector?
I assume DRAWLINE is also broken on Android??


Code (glbasic) Select


FUNCTION NewStar: x#,y#,w,h,col
        // polyvector way of doing it:
       STARTPOLY -1
        POLYVECTOR x+(w/2), y, 0,0,col
        POLYVECTOR x, y+(h/2), 0,0,col
        POLYVECTOR x+(w/2), y+h, 0,0,col
        POLYVECTOR x+w, y+(h/2), 0,0,col
ENDPOLY

ENDFUNCTION

FUNCTION NewRect: x#,y#,w,h,col
        // polyvector way of doing it:
       STARTPOLY -1
        POLYVECTOR x, y, 0,0,col
        POLYVECTOR x, y+h, 0,0,col
        POLYVECTOR x+w, y+h, 0,0,col
        POLYVECTOR x+w, y, 0,0,col
ENDPOLY


ENDFUNCTION
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

Slydog

For a DRAWLINE replacement, I found some old code for drawing a line using POLYVECTORs.
You specify the start and end point, the line thickness, and the line colour.

http://www.glbasic.com/forum/index.php?topic=8796.msg74810#msg74810
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

MrPlow

Thanks for this!

Quote from: Slydog on 2018-Feb-27
For a DRAWLINE replacement, I found some old code for drawing a line using POLYVECTORs.
You specify the start and end point, the line thickness, and the line colour.

http://www.glbasic.com/forum/index.php?topic=8796.msg74810#msg74810
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs