This code has been declared by its author to be Public Domain code.
Download source code |
A bit quicker than this but poorer quality. An image is scaled down, grabbed and then drawn scaled up which blurs the image plus a bit extra with lightblend to produce a 'bloom' effect which is a bit jaggedy but pretty quick. |
SuperStrict
Graphics 640,480
SeedRnd MilliSecs()
Const scaledown:Float = 8.0
AutoMidHandle True
Local IMAGE:TIMAGE = LoadImage("MAX_alpha.PNG")
Local blur:Int = 1
Local image1:timage=Null
While Not KeyHit(KEY_ESCAPE)
Local t1:Int=MilliSecs()
Cls
If MouseHit(1) image1=createbloom(image)
SetScale 1.0 , 1.0
SetAlpha 1.0
SetBlend maskblend
DrawImage image , MouseX() , MouseY()
If image1
SetScale scaledown + (scaledown / 10.0) , scaledown + (scaledown / 10.0)
SetBlend lightblend
SetAlpha 0.8 ' try changing alpha value for bigger/smaller blooms.
DrawImage image1 , MouseX() , MouseY()
EndIf
Flip 0
Local t2:Int=MilliSecs()
' Print t2 - t1
Wend
Function createbloom:timage(image:timage)
Local st:Int=MilliSecs()
SetAlpha 1.0
SetScale 1.0/scaledown,1.0/scaledown
DrawImage image , (ImageWidth(image)/scaledown)/2 , (ImageHeight(image)/scaledown)/2
Local mypixmap:tpixmap = GrabPixmap(0,0,ImageWidth(image)/scaledown,ImageHeight(image)/scaledown)
Local et:Int = MilliSecs()
Print (et-st)
Return LoadImage(mypixmap)
End Function |
Comments |
"consts must be initialized"
|
|
"consts must be initialized"
This is BlitzMax code, not Blitz3D. It simply won't compile in Blitz3D.
|
|
This is great! A really simple (read: genius) way of adding a bit extra graphics wise to my game, thanks :)
|
|
awesome! Now i would wonder how you can GRAB a buffer area todo this.
|
|
I wonder, would this have been the result? looks like it:
|
|
Doesn't work.
In what way Ked?
|
|
It doesn't produce the "bloom" effect.
|
|
Is anybody else having trouble with this when creating the bloom effect by pressing the left mouse button? As some people have got it working what is your machine spec?
|
|
The theory is exactly how "bloom" is created on PS2, PSX, XBox, GameCube. We take the backbuffer, shrink it down (often to a 256x256), blow it back up (to 640x480) and run a simple blur filter on it or in some cases, the hardware takes care of it.
The best blooms have thresholds, so you only bloom the brightest stuff, otherwise you end up with that vasoline look, like Prince of Persia and Oblivion.
When I get home, I'll have to check out this code and see if it works.
|
|
Goldstar: yup that's the result of it!
I cheat a little bit, but for the level bloom I use tony's code :D
edit: and I just realised I didn't add tony to the credits, so sorry about that
|
|
@Raz, no need for credits but glad it was useful. @Ked, please can you provide more information on what you are doing and the machine spec.
|
|
WinXP | AMD Athalon XP-M 1700+ 1.47GHz | 512 MB RAM | ATI Radeon 9250
I am copying and pasting the above code into my BlitzMax IDE. I get the BlitzMax logo (a PNG with alpha) and rename it to whatever it should be and run the code. All I see is the BlitzMax logo at the MouseX() and MouseY() location.
BTW: I have had problems with GrabPixmap in the past.
|
|
did you hit your left mouse key?
...
If MouseHit(1) image1=createbloom(image)
...
|
|
Oh goodness! I must have happened to totally somehow definitely miss that!
Yes, I hit the left mouse button, genius.
|
|
Hmmmm... difficult to detect sarcasm in writing so can you clarify whether pressing the LMB does anything? If it doesn't then what is your machine spec?
|
|
Nice snippet tonyg, really cool and works like a charm here.
|
|
lol @Plash, Ked & tonyg. just to be sure, how are you holding that mouse?
|
|
Well, since there is no bloom effect, I'm going to have to say no the LMB doesn't do a single thing. I already gave you my machine spec.
|
|
It doesn't work until I click the left mouse button.
|
Code Archives Forum