March 05, 2021, 07:55:44 AM

Author Topic: [bb] Fade by skidracer [ 1+ years ago ]  (Read 418 times)

Offline BlitzBot

[bb] Fade by skidracer [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : Fade
Author : skidracer
Posted : 1+ years ago

Description : Not exactly fast, but probably the most optimal way to fade the screen in blitz currently.

Code :
Code: BlitzBasic
  1. ; fade.bb
  2. ; by simon@acid.co.nz
  3.  
  4. ; as readpixel is slow this fade routine copies the graphics buffer to a bank
  5. ; and uses the bank as a pixel source for subsequent calls to fade
  6.  
  7. Graphics 640,480,32
  8.  
  9. While Not MouseHit(1)
  10.         Color Rnd(255),Rnd(255),Rnd(255)
  11.         Line Rnd(640),Rnd(480),Rnd(640),Rnd(480)
  12. Wend
  13. gfxbank=GrabBank()
  14.  
  15. ; use double buffering for clean fade
  16.  
  17. SetBuffer BackBuffer()
  18. For i=1 To 32
  19.         Fade(gfxbank)
  20.         Flip
  21. Next
  22. FreeBank gfxbank
  23.  
  24. MouseWait
  25. End    
  26.  
  27. Function GrabBank()
  28.         w=GraphicsWidth()
  29.         h=GraphicsHeight()
  30.         bank=CreateBank(w*h*4) 
  31.         gbuffer=GraphicsBuffer()
  32.         LockBuffer gbuffer
  33.         For y=0 To h-1
  34.                 For x=0 To w-1
  35.                         PokeInt bank,o,ReadPixelFast(x,y)
  36.                         o=o+4
  37.                 Next
  38.         Next
  39.         UnlockBuffer gbuffer   
  40.         Return bank
  41. End Function
  42.  
  43. Function Fade(bank)
  44.         w=GraphicsWidth()-1
  45.         h=GraphicsHeight()-1
  46.         gbuffer=GraphicsBuffer()
  47.         LockBuffer gbuffer
  48.         For y=0 To h
  49.                 For x=0 To w
  50.                         rgb=PeekInt(bank,o)
  51.                         d=(rgb Shr 3) And $1f1f1f
  52.                         If d=0 d=rgb
  53.                         rgb=rgb-d
  54.                         WritePixelFast x,y,rgb
  55.                         PokeInt(bank,o,rgb)
  56.                         o=o+4
  57.                 Next
  58.         Next
  59.         UnlockBuffer gbuffer   
  60. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal