BBC BASIC for Windows
« GLib (compact sprite library) »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:07pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1 2 3  Notify Send Topic Print
 veryhotthread  Author  Topic: GLib (compact sprite library)  (Read 455 times)
DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: GLib (compact sprite library)
« Reply #21 on: Sep 26th, 2016, 2:18pm »

Hi David,

Ooh, that's an intriguing throw-away! How are you using it for collision detection?

D
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GLib (compact sprite library)
« Reply #22 on: Sep 26th, 2016, 3:54pm »

on Sep 26th, 2016, 2:18pm, DDRM wrote:
Ooh, that's an intriguing throw-away! How are you using it for collision detection?


The 'alien' sprites are plotted using the routine PlotSetAlpha which, apart from merely plotting a sprite, also sets the 'invisible' and normally redundant alpha byte of all overwritten background pixels to a specified value in the range 0 to 255. This value is different for each individual alien, and is in fact the alien's index in the alien{()} structure array. Actually, the indices run from 1 up to the maximum number of aliens that may be plotted (which can't exceed 255) because writing alpha values of zero isn't terribly useful in this scheme. So once we've plotted all the aliens, and the initially-clean alpha channel of the background/surface bitmap has been scribbled all over, when it comes to plotting our missiles/plasma bolts, those are plotted using PlotGetAlphaBits. This routine plots the missile sprites but also reads the background alpha bytes (of all pixels overwritten by the missile sprite) and returns the cumulative alpha value which, if there is no collision, should be zero. If it's nonzero, then a collision of the missile with one of the aliens has taken place. But which alien? The nonzero alpha value will be the actual index of the alien we've just collided with.

I'm pretty sure that I used this collision detection method with my game 'Alien Eliminator':

https://www.youtube.com/watch?v=lgPWQKjLaaw


And with other games, too.

With BB4W, drawing the background/surface bitmap using *MDISPLAY is relatively fast irrespective of the state of the bitmap's alpha channel (whether it is completely clear, or contains nonzero alpha values), because it doesn't attempt to do any alpha blending. But with BBCSDL and *MDISPLAY, the bitmap is 'automatically' scanned for nonzero alpha values prior to rendering. If the alpha channel is clear then the bitmap is drawn fast-ish (not as fast as with BB4W), but if there is so much as one nonzero alpha value, then SDL will alpha blend the entire bitmap (or at least I think that's the case; it certainly seems to be). This is why I clear the alpha channel (when run under BBCSDL) before calling *MDISPLAY. I don't know how SDL is doing the (here unwanted) alpha channel pre-scanning, but I hope it's not using the CPU to do it!


David.
--
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: GLib (compact sprite library)
« Reply #23 on: Sep 27th, 2016, 12:55pm »

Hi David,

OK, that's a cute and clever idea, but now I'm struggling a bit... So all the bits where you encode the string $S% as hex to (spaces defined by) variables like PlotGetAlphaBits are essentially pre-assembled functions, which you can then call using SYS, as if they were system commands? Sneaky, if opaque! wink So that's kind of like Michael's BMPtoCode idea? wink

With regard to the use of alpha channel values, Richard posted something on the cross-platform forum in another context that suggests that this is a "feature" of SDL rather than BB4SDL:

"What SDL does is to scan all the alpha bytes; if any of them are non-zero it (sensibly) assumes that you are using the alpha channel and applies it throughout. If none of the alpha bytes are non-zero it ignores the alpha channel entirely."

... so I wouldn't hold your breath for a version which doesn't behave that way...

Best wishes,

D
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GLib (compact sprite library)
« Reply #24 on: Sep 27th, 2016, 1:52pm »

on Sep 27th, 2016, 12:55pm, DDRM wrote:
OK, that's a cute and clever idea, but now I'm struggling a bit... So all the bits where you encode the string $S% as hex to (spaces defined by) variables like PlotGetAlphaBits are essentially pre-assembled functions, which you can then call using SYS, as if they were system commands? Sneaky, if opaque! wink


The intention behind GLib is that it be compact enough to be usable with the pre-v6 trial version of BB4W. So, yes, instead of memory-consuming assembly language, I use strings of pre-assembled machine code to save some space (although each byte of machine code requires 2 bytes for its ASCII representation). I suppose I could've used DATA statements instead which might have saved yet more space, but using strings seemed more convenient to me. I know that it was possible to circumvent (perhaps to a limited extent) the 8K (or was it 12K?) limit of the pre-v6 trial version of BB4W, but I'm not clever enough to figure out how to do it!

Incidentally, the more extensive GLib2 library is DLL-based (uses even less memory than GLib). I wrote it while I was learning C. I found that I was able to write graphics functions sometimes in a matter of minutes (literally!) rather than hours. I know that compiled C can be slower than hand-coded assembler code, but not always, and it depends on the competence of the programmer. Since a C compiler understands the CPU architecture better than most human programmers, and knows how to schedule sequences of instructions for efficient execution, compiled C can be faster. Some of my C-based graphics routines are faster than their largely equivalent assembly language versions, even though they're based on the same algorithms, and this is likely due to the C compiler sequencing (pipelining) the instructions in a more efficient way than I ever possibly could.


Quote:
So that's kind of like Michael's BMPtoCode idea? wink


Hmm.. perhaps, in a sense? Just to be sure, those machine code routines don't encode any image/sprite information.


Quote:
With regard to the use of alpha channel values, Richard posted something on the cross-platform forum in another context that suggests that this is a "feature" of SDL rather than BB4SDL:


I was aware of this, but if there is a way the 'pre-scanning' could be suppressed then it could save some (or rather a lot!) of CPU cycles. For a while, I did wonder why large (e.g. 640x4800 32bpp) BMP images took so long to render via *MDISPLAY (under BBCSDL). SDL was pre-scanning over 3 million pixels, even though for my particular application it wasn't necessary as no alpha blending was taking place.

I won't be able to develop one myself, but an SDL-based graphics library (which uses accelerated SDL graphics surfaces and rendering operations) is highly desirable. (GLib and GfxLib is mostly all CPU-intensive software-based rendering.) Such a library would ideally include an image loader (with appropriate conversion where necessary), and a function for synchronising graphics rendering with screen/monitor's refresh. I gather, from a brief Google search, that VBlank synchronisation is difficult or impossible with SDL in 'windowed mode'.


David.
--
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GLib (compact sprite library)
« Reply #25 on: Sep 27th, 2016, 7:35pm »

Just another experiment with frame rate-independent animation. I'm probably doing this wrong!

Use the Up/Down arrow keys to increase/decrease the number of sprites displayed. The frame rate will drop as the number of sprites increases, but the speed of the sprites should be roughly constant. The frame rate and number of objects are displayed in the window's title bar.

Works with BB4W and BBCSDL:

Code:
      *ESC OFF

      NumSprTypes% = 20
      MaxObjs% = 2000

      M% = 3
      HIMEM = LOMEM + M%*&100000
      HIMEM = (HIMEM + 3) AND -4

      BB4W% = (INKEY(-256) == &57)

      IF BB4W% THEN
        GetTicks$ = "GetTickCount"
        SetWindowText$ = "SetWindowText"
      ELSE
        GetTicks$ = "SDL_GetTicks"
        SetWindowText$ = "SDL_SetWindowTitle"
      ENDIF

      ScrW% = 640
      ScrH% = 480
      VDU 23,22,ScrW%;ScrH%;8,16,16,0 : OFF

      TmpBMPBuf% = FNmalloc(4*128*128)

      REM Create a 640x480 32bpp 'surface' bitmap:
      DIM bmp{a%,w%,h%}
      bmp.w%=ScrW%
      bmp.h%=ScrH%
      bmp.a%=FNcreateBMP32(bmp.w%,bmp.h%)

      PROCInitGLIB(g{},bmp.w%,bmp.h%)
      g.a%=bmp.a%+54

      DIM spr{(NumSprTypes%-1) a%, sz%}
      DIM obj{(MaxObjs%-1) type%, x, y, dx, dy}

      *REFRESH OFF

      GCOL 15
      FOR I%=0 TO NumSprTypes%-1
        spr{(I%)}.sz% = 4*(8+RND(10))
        CLS
        col1% = RND(64)+&100*RND(64)+&10000*RND(64)
        col2% = (32+RND(255-32))+&100*(32+RND(255-32))+&10000*(32+RND(255-32))
        FOR r%=spr{(I%)}.sz%/2-1 TO 1 STEP -1
          f=1-r%/(spr{(I%)}.sz%/2-1)
          PROClerpRGB(col1%,col2%,f,R%,G%,B%)
          COLOUR 15,R%,G%,B%
          CIRCLE FILL spr{(I%)}.sz%, spr{(I%)}.sz%, 2*r%
        NEXT r%
        file$ =  @tmp$ + "spr" + STR$I%
        OSCLI "GSAVE """+file$+""" "+STR$0+","+STR$0+","+STR$(2*spr{(I%)}.sz%)+","+STR$(2*spr{(I%)}.sz%)
      NEXT I%

      CLS : OSCLI "REFRESH" : OSCLI "REFRESH ON"

      FOR I%=0 TO NumSprTypes%-1
        PRINT I%
        file$ =  @tmp$ + "spr" + STR$I% + ".BMP"
        spr{(I%)}.a% = FNLoadBMP(file$,TmpBMPBuf%,4*128*128)
      NEXT I%

      FOR I%=0 TO MaxObjs%-1
        obj{(I%)}.type% = RND(NumSprTypes%)-1
        obj{(I%)}.x = 32+RND(ScrW%-64)
        obj{(I%)}.y = 32+RND(ScrH%-64)
        obj{(I%)}.dx = 0.05 * SGN(RND(1)-0.5) * (0.25 + 3.75*RND(1))
        obj{(I%)}.dy = 0.05 * SGN(RND(1)-0.5) * (0.25 + 3.75*RND(1))
      NEXT I%

      G% = g{}

      NumObjs% = 1

      flushKbBuf% = 0
      frames% = 0
      frameRate% = 0
      SYS GetTicks$ TO time0%

      REPEAT
  
        SYS GetTicks$ TO t1%
  
        SYS Clr,g{},&A0D0
  
        P% = PlotShadow
        FOR I%=0 TO NumObjs%-1
          t%=obj{(I%)}.type%
          a%=spr{(t%)}.a%
          sz%=spr{(t%)}.sz%
          SYS P%,G%,a%,sz%,sz%,obj{(I%)}.x-16,obj{(I%)}.y-16
        NEXT
  
        P% = Plot
        FOR I%=0 TO NumObjs%-1
          t%=obj{(I%)}.type%
          a%=spr{(t%)}.a%
          sz%=spr{(t%)}.sz%
          SYS P%,G%,a%,sz%,sz%,obj{(I%)}.x,obj{(I%)}.y
        NEXT
  
        OSCLI "MDISPLAY "+STR$~bmp.a%
        WAIT 1
  
        SYS GetTicks$ TO t2%
  
        dt%=t2%-t1%
  
        FOR I%=0 TO NumObjs%-1
          obj{(I%)}.x+=dt%*obj{(I%)}.dx
          obj{(I%)}.y+=dt%*obj{(I%)}.dy
          IF obj{(I%)}.x<-32 THEN
            obj{(I%)}.dx*=-1
            obj{(I%)}.x+=obj{(I%)}.dx
          ENDIF
          IF obj{(I%)}.x>ScrW%-32 THEN
            obj{(I%)}.dx*=-1
            obj{(I%)}.x+=obj{(I%)}.dx
          ENDIF
          IF obj{(I%)}.y<-32 THEN
            obj{(I%)}.dy*=-1
            obj{(I%)}.y+=obj{(I%)}.dy
          ENDIF
          IF obj{(I%)}.y>ScrH%-32 THEN
            obj{(I%)}.dy*=-1
            obj{(I%)}.y+=obj{(I%)}.dy
          ENDIF
        NEXT
  
        IF INKEY-58 THEN
          NumObjs%+=1
          IF NumObjs%=MaxObjs% NumObjs%=MaxObjs%
        ENDIF
  
        IF INKEY-42 THEN
          NumObjs%-=1
          IF NumObjs%<1 NumObjs%=1
        ENDIF
  
        frames% += 1
        SYS GetTicks$ TO time1%
        IF time1%-time0% >= 1000 THEN
          frameRate% = frames%
          frames% = 0
          SYS SetWindowText$, @hwnd%, STR$frameRate% + " fps | "+STR$NumObjs%+" objects"
          SYS GetTicks$ TO time0%
        ENDIF
  
        IF flushKbBuf% > 0 THEN
          flushKbBuf% -= 1
        ELSE
          *FX 21, 0
          flushKbBuf% = 250
        ENDIF
  
      UNTIL FALSE
      END

      DEF PROClerpRGB( rgb1%, rgb2%, f, RETURN r%, RETURN g%, RETURN b% )
      LOCAL r1%, g1%, b1%, r2%, g2%, b2%
      r1% = (rgb1% AND &FF0000) >> 16
      g1% = (rgb1% AND &FF00) >> 8
      b1% = rgb1% AND &FF
      r2% = (rgb2% AND &FF0000) >> 16
      g2% = (rgb2% AND &FF00) >> 8
      b2% = rgb2% AND &FF
      r% = r1% + f*(r2%-r1%)
      g% = g1% + f*(g2%-g1%)
      b% = b1% + f*(b2%-b1%)
      ENDPROC

      DEF FNcreateBMP32( W%, H% )
      LOCAL A%, S%
      S% = 54 + 4*W%*H% + 6
      DIM A% S%-1
      A% = ((A% + 3) AND -4) + 2
      A%?0 = ASC"B"
      A%?1 = ASC"M"
      A%!2 = 54 + 4*W%*H%
      A%!6 = 0
      A%!10 = 54
      A%!14 = 40
      A%!18 = W%
      A%!22 = H%
      A%?26 = 1
      A%?28 = 32
      A%!30 = 0
      A%!34 = 4*W%*H%
      A%!38 = 0
      A%!42 = 0
      A%!46 = 0
      A%!50 = 0
      = A%

      DEF FNLoadBMP( file$, buf%, bufSz% )
      LOCAL A%, B%, F%, W%, H%, I%, S%
      F% = OPENIN( file$ )
      IF F% = 0 THEN ERROR 0, "Can't find file " + file$
      S% = EXT#F%
      CLOSE#F%
      OSCLI "LOAD """ + file$ + """ " + STR$~buf%
      IF buf%?0<>ASC"B" OR buf%?1<>ASC"M" THEN
        ERROR 0, file$ + " isn't a BMP file"
      ENDIF
      IF buf%?28 <> 24 AND buf%?28 <> 32 THEN
        ERROR 0, "BMP file has invalid colour depth (must be 24 or 32)"
      ENDIF
      W% = buf%!18
      IF (W% AND 3) <> 0 THEN ERROR 0, "BMP image width must be a multiple of 4"
      H% = buf%!22
      REM if H% is negative then sprite is "upside down" !
      S% = 4 * W%*ABS(H%)
      DIM B% S%+7
      B% = (B% + 7) AND -8
      A% = buf% + buf%!10

      IF SGN(H%) = 1 THEN
        IF buf%?28 = 24 THEN
          FOR I% = B% TO B%+S%-1 STEP 4
            !I% = ?A% OR &100*A%?1 OR &10000*A%?2
            A% += 3
          NEXT
        ENDIF
      ENDIF

      IF SGN(H%)=-1 THEN
        H%=ABS(H%)
        IF buf%?28=24 THEN
          A%+=3*W%*(H%-1)
          FOR Y%=0 TO H%-1
            Z%=A%
            FOR I%=B%+4*W%*Y% TO B%+4*(W%*Y% +(W%-1))-1 STEP 4
              !I%=?Z% OR &100*Z%?1 OR &10000*Z%?2
              Z%+=3
            NEXT
            A%-=3*W%
          NEXT
        ENDIF
      ENDIF
      = B%

      REM ============================================================================
      DEFPROCInitGLIB(RETURN v{},W%,H%):LOCALS%,Z%:DIMv{a%,w%,h%}
      v.w%=W%
      v.h%=H%
      Z%=FNmalloc(4096)
      S%=FNmalloc(2048)
      $S%="608B5C2424C703FFFFFFFF8B7C24383B7C24280F8DC70000008B74243C3B74242C0F8DB9"
      $S%+="0000008B4C24308B54243483F9007D03F7D99083FA007D03F7DA90F7D93BF90F8E970000"
      $S%+="00F7DA3BF20F8E8D000000F7D9F7DAC70300000000C7430400000000C7430800000000C7"
      $S%+="430C00000000894B10895314897B1889731C8BEF03E93B6C24287E0E2B6C2428296B10C7"
      $S%+="4304FFFFFFFF83FF007D14297B0C017B10C7431800000000C74304FFFFFFFF8BEE03EA3B"
      $S%+="6C242C7E0E2B6C242C296B14C74304FFFFFFFF83FE007D14297308017314C7431C000000"
      $S%+="00C74304FFFFFFFF61C21C0060":gClip=FN`m(S%,0)
      $S%="608B6C24248B4424288B7D008B4D040FAF4D08FCF3AB61C2080000":Clr=FN`m(S%,0)
      $S%="608BEC81EC800000008B75248BC4FF7538FF7534FF7530FF752CFF7608FF760450E8F6FE"
      $S%+="FFFFF70424FFFFFFFF0F855A0000008B552C89542434C1642434020FAF5424080354240C"
      $S%+="C1E2020355288B7E04897C2438C1642438020FAF7C241C037C2418C1E702033E8B5C2410"
      $S%+="33C98B048A85C0740389048F83C1013BCB7CEF03542434037C2438FF4C241475DF81C480"
      $S%+="00000061C2180060":Plot=FN`m(S%,33)
      $S%="608BEC81EC800000008B75248BC4FF7538FF7534FF7530FF752CFF7608FF760450E85FFE"
      $S%+="FFFFF70424FFFFFFFF0F85610000008B552C89542434C1642434020FAF5424080354240C"
      $S%+="C1E2020355288B7E04897C2438C1642438020FAF7C241C037C2418C1E702033E8B5C2410"
      $S%+="33C98B048A85C0740AD12C8F81248F7F7F7F7F83C1013BCB7CE803542434037C2438FF4C"
      $S%+="241475D881C48000000061C2180060":PlotShadow=FN`m(S%,33)
      Z%=FNmalloc(4096)
      ENDPROC
      DEFFN`m(S%,O%)
      LOCALA%,I%:A%=FNmalloc(LEN$S%):FORI%=0TOLEN$S%DIV2-1
        A%?I%=EVAL("&"+MID$($S%,2*I%+1,2)):NEXT
      IFO%>0PROC`d(A%,O%,gClip)
      =A%
      DEFPROC`d(B%,O%,C%):LOCALD%,P%:D%=C%-B%-O%-5:P%=B%+O%+1:!P%=D%:ENDPROC
      DEFFNmalloc(N%):LOCALA%:DIM A% N%+7:A%=(A%+7) AND -8:=A%
      REM ============================================================================
 
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GLib (compact sprite library)
« Reply #26 on: Nov 23rd, 2016, 04:55am »

Anyone that has seen the latest version of GLib (0.24 beta - used by the 'Snowfall 3' demo) may have noticed that it has grown quite at lot in size, and therefore it can no longer be described as being a 'compact' library! It now stands at around 54 Kb, which I don't believe is excessive given the amount of functionality it provides. There is always the temptation to keep on adding new functions (a mistake I made with GfxLib). I will add several more useful ones, and stop there, I think.

The library incorporates a lot of Richard's work that he had kindly contributed to GfxLib and the Programmer's Reference, and he will be duly credited in the next release. For instance, the 'Snowfall 3' demo uses his MMX-based PlotRotateScaleRTR and BoxBlur routines.


Things to do:

1) Tidy up the library (drastically)
2) Write the documentation
3) Release the stable version

All by the end of this month, hopefully.


David.
--
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GLib (compact sprite library)
« Reply #27 on: Nov 30th, 2016, 11:53pm »

GLIB's documentation is starting to take shape:

http://www.proggies.uk/glib/glibdocs.html


I hope to have it all completed by the end of the weekend (before I run out of enthusiasm and energy!).





User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GLib (compact sprite library)
« Reply #28 on: Dec 1st, 2016, 03:33am »

An old program modified for use with GLib. It downloads the latest version of GLib, and a BMP image, and stuffs them in a Windows temporary folder.

Copy, paste, run...

Code:
      REM "Vector balls 4"
      REM Original GfxLib-based version created 16-Jan-2012
      REM Modified for GLib on 01-Dec-2016
      REM Uses 'PlotRotateScaleRTR' to draw the ball objects

      *ESC OFF
      *FLOAT 64
      PROCurldownload( "http://www.proggies.uk/glib/GLIB.bbc", @tmp$+"glib_bbc.BBC" )
      INSTALL @tmp$ + "glib_bbc"
      PROCglib_FixWindowSize : MODE 8 : OFF
      PROCglib_Init(g{}, glib{})
      ON CLOSE PROCglib_Cleanup : QUIT
      ON ERROR PROCglib_Cleanup : OSCLI "REFRESH ON" : ON : REPORT : PRINT " at line "; ERL : END
      INSTALL @lib$+"SORTLIB" : sort% = FN_sortinit(1,0)
      DIM g2{} = g{}

      ballTypes% = 6 : DIM bmAddrTbl%( ballTypes%-1 )

      REM bmAddrTbl%(0) = FNglib_LoadImg( @dir$+"blueball_128x128x24.BMP", -1 )
      bmAddrTbl%(0) = FNLoadImgFromNet( "http://www.proggies.uk/temp/", "blueball_128x128x24.bmp" )

      g2.w% = 128
      g2.h% = 128
      FOR I% = 1 TO ballTypes%-1
        bmAddrTbl%(I%) = FNglib_CopyBitmap( glib{}, bmAddrTbl%(0), 128, 128, -1 )
        g2.a% = bmAddrTbl%(I%)
        SYS glib.PlotShuffleRGB%, g2{}, bmAddrTbl%(I%), 128, 128, 0, 0, I%
      NEXT I%

      _PREMULTIPLY = &1
      _INVERT = &8
      _3MRPASS = 3<<4
      _2MBBPASS = 2<<6
      ctrl% = _PREMULTIPLY + _INVERT + _3MRPASS + _2MBBPASS
      FOR I% = 0 TO ballTypes%-1
        PROCglib_CreateAlphaMask( g{}, glib{}, bmAddrTbl%(I%), 128, 128, 0, ctrl% )
      NEXT I%

      N% = 50
      DIM bmAddr%( N%-1 ), bmAddr2%( N%-1 )
      DIM x%(N%-1), y%(N%-1), z%(N%-1)
      DIM x2%(N%-1), y2%(N%-1), z2%(N%-1)

      minDist% = 100

      R% = RND(-12345)

      FOR I%=0 TO N%-1
        REPEAT
          valid% = TRUE
          x%=-400+RND(2*400 - 1)
          y%=-400+RND(2*400 - 1)
          z%=-400+RND(2*400 - 1)
          IF I%=0 THEN
            x%(0) = x%
            y%(0) = y%
            z%(0) = z%
          ELSE
            FOR J%=0 TO I%
              d% = SQR( (x%-x%(J%))^2 + (y%-y%(J%))^2 + (z%-z%(J%))^2 )
              IF d% < minDist% THEN
                valid% = FALSE
                J% = I%
              ENDIF
            NEXT J%
          ENDIF
        UNTIL valid%
        x%(I%) = x%
        y%(I%) = y%
        z%(I%) = z%
        bmAddr%(I%) = bmAddrTbl%( RND(ballTypes%)-1 )
      NEXT I%

      a#=0
      b#=0
      c#=0

      *REFRESH OFF

      REPEAT
        T% = TIME
        bgCol% = &10000*INT(255*ABSSINRAD(T%/4.5)) + \
        \ &100*INT(255*ABSSINRAD(T%/6.7)) + \
        \ INT(255*ABSCOSRAD(T%/6.83))
        SYS glib.Clr%, g{}, bgCol%
  
        cosa# = COSa#
        cosb# = COSb#
        cosc# = COSc#
        sina# = SINa#
        sinb# = SINb#
        sinc# = SINc#
        FOR I%=0 TO N%-1
          x# = x%(I%)
          y# = y%(I%)
          z# = z%(I%)
          x1# = x#*cosa# - y#*sina#
          y1# = x#*sina# + y#*cosa#
          z1# = z#
          y2# = y1#*cosb# - z1#*sinb#
          z2# = y1#*sinb# + z1#*cosb#
          x2# = x1#
          z3# = z2#*cosc# - x2#*sinc#
          x3# = z2#*sinc# + x2#*cosc#
          y3# = y2#
          x2%(I%) = x3#
          y2%(I%) = y3#
          z2%(I%) = z3#
        NEXT I%
  
        bmAddr2%() = bmAddr%()
        C%=N% : CALL sort%, z2%(0), x2%(0), y2%(0), bmAddr2%(0)
  
        FOR I%=0 TO N%-1
          d# = 1/(&3E8+z2%(I%))
          x = &140 + &2A8 * x2%(I%) * d#
          y = &100 + &2A8 * y2%(I%) * d#
          scale% = &10000*300/(z2%(I%)+650)
          SYS glib.PlotRotateScaleRTR%, g{}, bmAddr2%(I%), 128, 128, 16*x, 16*y, 0, scale%
        NEXT
  
        a# += 0.019151
        b# += 0.016316
        c# += 0.012194
        IF a# > 2*PI THEN a# -= 2*PI
        IF b# > 2*PI THEN b# -= 2*PI
        IF c# > 2*PI THEN c# -= 2*PI
  
        PROCglib_Display
  
      UNTIL FALSE

      DEFFNLoadImgFromNet(url$,file$):LOCALA%,F%:F%=OPENIN(@tmp$+file$)
      IF F%=0 PROCurldownload(url$+file$,@tmp$+file$)
      CLOSE#F%
      A%=FNglib_LoadImg(@tmp$+file$,0)
      =A%

      DEFPROCurldownload(url$,file$)
      LOCALurlmon%,res%
      SYS"LoadLibrary","urlmon.dll"TOurlmon%
      SYS"GetProcAddress",urlmon%,"URLDownloadToFileA"TO`URLDownloadToFile`
      SYS`URLDownloadToFile`,0,url$,file$,0,0TOres%
      SYS"FreeLibrary",urlmon%
      IFres%ERROR100,"Couldn't download "+url$
      ENDPROC
 
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: GLib (compact sprite library)
« Reply #29 on: Dec 1st, 2016, 07:45am »

Brilliant - that's really encouraging. It's very hard to use someone else's programming tools without a clear understanding of the required format etc.

Thanks!

D
User IP Logged

sveinioslo
Developer

member is offline

Avatar




PM


Posts: 64
xx Re: GLib (compact sprite library)
« Reply #30 on: Dec 1st, 2016, 7:49pm »

Quote:
GLIB's documentation is starting to take shape:

Thank you, been waiting for this.

Svein
User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Re: GLib (compact sprite library)
« Reply #31 on: Dec 3rd, 2016, 12:55am »

WOW! That is an amazing 3D ball animation. Or at least it looks 3D..

User IP Logged

I like making program generators and like reinventing the wheel
David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GLib (compact sprite library)
« Reply #32 on: Dec 20th, 2016, 02:16am »

Added a new routine to GLIB which stretches (scales) a bitmap, with the transparency level of each plotted pixel determined by that pixel's 'brightness' (actually its averaged RGB value). The darker a pixel is, the more transparent it is when plotted. Finally, a global transparency value is applied to each pixel so that the bitmap as a whole can be 'faded' into the background if so desired. This routine is perhaps useful for e.g. fireball/explosion effects.

Here's a quick demo of the new routine (it's nothing exciting of course):

http://www.proggies.uk/temp/test_plotscaleblend2.zip

I recommend that you extract the EXE file from the Zip folder before running it.


David.
--
User IP Logged

Pages: 1 2 3  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls