BASIC

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

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3288
    • View Profile
    • Space Fractal
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 »
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1132
    • View Profile
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

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1132
    • View Profile
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

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3288
    • View Profile
    • Space Fractal
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.....
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.