Blur on-the-fly with some Sprite3D

Share your advanced PureBasic knowledge/code with the community.
jamirokwai
Enthusiast
Enthusiast
Posts: 798
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Blur on-the-fly with some Sprite3D

Post by jamirokwai »

Dear Board,

while fiddling around with the need of some blurry-test-code, I came up
with this... Just a fake blur which transparency and multiple Sprite3D.
Possibly you need to change the screen accordingly, and give it a
"hintergrund.png" with the same size.

Function keys F1/F2 change the disorder in steps of 1 until it reaches +/- 4.
Function keys F3/F4 change the transparency between 32 and 192.
Space switches between

Comments are highly welcome :) Maybe there is a better or faster way
to accomplish some blur... (just checked blur in the forum... Here is a tutorial
about it in C: http://nehe.gamedev.net/data/lessons/le ... ?lesson=36)

Works on my MacBook using PB 4.20 PPC (good) AND PB 4.30A1 X86 (great)

Code: Select all

If InitSprite() = 0         : MessageRequester("Error", "Can't initilalize OpenGL", 0)      : End : EndIf
If InitKeyboard() = 0       : MessageRequester("Error", "Can't initilalize Keyboard", 0)    : End : EndIf
If UsePNGImageDecoder() = 0 : MessageRequester("Error", "Can't initilalize PNG-Decoder", 0) : End : EndIf
If InitSprite3D() = 0       : MessageRequester("Error", "Can't initilalize OpenGL-3D", 0)   : End : EndIf

; change to fit your screen
If OpenScreen(1280, 800, 32, "Blurtest")

LoadSprite(1, "hintergrund.png",#PB_Sprite_Texture)
DisplaySprite(1,0,0)

; change to fit your screen
GrabSprite(2,0,0,1280,400,#PB_Sprite_Texture)        : CreateSprite3D(1,2)
GrabSprite(3,0,400,1280,400,#PB_Sprite_Texture)        : CreateSprite3D(2,3)

Sprite3DQuality(1)
  
  x            = 0
  blurx        = 2
  maxblur      = 4
  trans        = 32
  mintrans     = 32
  maxtrans     = 192
  
  Repeat
  
   If Start3D()

    DisplaySprite3D(1, x + blurx, blurx, trans)
    DisplaySprite3D(1, x - blurx, -blurx, trans)
    DisplaySprite3D(1, x + blurx, -blurx,trans)
    DisplaySprite3D(1, x - blurx, blurx, trans)
    DisplaySprite3D(1, x, 0, 128)
    
    DisplaySprite3D(2, x, 400)
    
    Stop3D()
   EndIf
   
   ExamineKeyboard()
   
   If KeyboardReleased(#PB_Key_Space)
    If blurx = 0 : blurx = maxblur : Else : blurx = 0 : EndIf
   EndIf
   
   If KeyboardReleased(#PB_Key_F1) : blurx = blurx + 1 : If blurx >  maxblur  : blurx =  maxblur : EndIf : EndIf
   If KeyboardReleased(#PB_Key_F2) : blurx = blurx - 1 : If blurx < -maxblur  : blurx = -maxblur : EndIf : EndIf
   If KeyboardPushed(#PB_Key_F3) : trans = trans + 2 : If trans >  maxtrans : trans =  maxtrans : EndIf : EndIf
   If KeyboardPushed(#PB_Key_F4) : trans = trans - 2 : If trans <  mintrans : trans =  mintrans : EndIf : EndIf
    
   FlipBuffers(#PB_Screen_SmartSynchronization)  

Until KeyboardPushed(#PB_Key_Escape)

EndIf

End
Regards,
JamiroKwai
dige
Addict
Addict
Posts: 1410
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

The mentioned Lesson 36 show's an amazing radial blur & rendering to a texture effect. It looks realy great! Is that possible with pb?
jamirokwai
Enthusiast
Enthusiast
Posts: 798
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Post by jamirokwai »

dige wrote:The mentioned Lesson 36 show's an amazing radial blur & rendering to a texture effect. It looks realy great! Is that possible with pb?
Should be possible. But I managed to deny learning C for 20 years now... :shock:
(started with Pascal and Basic, then some Asm, PHP, and finally PB...)

Edit.: I only need some fast and good-looking blur-routines for a game with maybe 7 to 9 layers. The main character should be able to walk on the different layers, and the frontmost and backmost layers should blur out, when not walked on.
Regards,
JamiroKwai
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

Ok here comes a OpenGL version for PB.

OpenGL.pb
http://skybeat-online.de/pb/nehe36/OpenGL.pb

Nehe lesson 36 for PB 4.20
http://skybeat-online.de/pb/nehe36/lesson36.pb

Sorry bud it is to much code for a direct post in the forum.

Hope it is what you want and you like it.
if you dont want the color change take a look to line 199 in the lesson36.pb

regards,
Nico
dige
Addict
Addict
Posts: 1410
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

WOWWOWWOW!!!! Thats great!!! :shock:

Thank you the much Nicolaus!!! :D
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

dige wrote:WOWWOWWOW!!!! Thats great!!! :shock:

Thank you the much Nicolaus!!! :D
thanks, if you read a little bit about OpenGL it is easy.
The only Problem is das PB since years don't update the OpenGL functions and constantes. Since 4.10 or so we have the typ var but PB imports the OpenGL functions at this time for high / low vars.

So if you use my OpenGL.pb you can work with the normal OpenGL functions and double as well.
Post Reply