### Author Topic: DRAWRECT using POLYVECTOR from a Image  (Read 6688 times)

#### spacefractal

• Community Developer
• Prof. Inline
• Posts: 3971
##### DRAWRECT using POLYVECTOR from a Image
« on: 2017-Aug-30 »
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.
« Last Edit: 2017-Aug-30 by spacefractal »
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

#### MrPlow

• Prof. Inline
• Posts: 1810
##### Re: DRAWRECT using POLYVECTOR from a Image
« Reply #1 on: 2017-Aug-30 »
Hi Sf,

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

#### MrPlow

• Prof. Inline
• Posts: 1810
##### Re: DRAWRECT using POLYVECTOR from a Image
« Reply #2 on: 2017-Aug-30 »
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

• Community Developer
• Prof. Inline
• Posts: 3971
##### Re: DRAWRECT using POLYVECTOR from a Image
« Reply #3 on: 2017-Aug-30 »
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 and The beagle Jam.

#### Kitty Hello

• code monkey
• Prof. Inline
• Posts: 10829
• here on my island the sea says 'hello'
##### Re: DRAWRECT using POLYVECTOR from a Image
« Reply #4 on: 2017-Nov-25 »
Another option is to use mem2sprite and do a 1x1 pixel sprite. Use smoothshading false!

#### Qedo

• Dr. Type
• Posts: 362
• to program what I have do how should programming?
##### Re: DRAWRECT using POLYVECTOR from a Image
« Reply #5 on: 2017-Dec-03 »
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

• Community Developer
• Prof. Inline
• Posts: 3971
##### Re: DRAWRECT using POLYVECTOR from a Image
« Reply #6 on: 2018-Jan-01 »
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 and The beagle Jam.

#### MrPlow

• Prof. Inline
• Posts: 1810
##### Re: DRAWRECT using POLYVECTOR from a Image
« Reply #7 on: 2018-Feb-20 »
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
« Last Edit: 2018-Feb-20 by MrPlow »
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

#### Slydog

• Prof. Inline
• Posts: 932
• KodeSource
##### Re: DRAWRECT using POLYVECTOR from a Image
« Reply #8 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
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

#### MrPlow

• Prof. Inline
• Posts: 1810
##### Re: DRAWRECT using POLYVECTOR from a Image
« Reply #9 on: 2018-Mar-13 »
Thanks for this!

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