Alphablend + Alpha 0.01 + Rect = wtf?

BlitzMax Forums/BlitzMax Programming/Alphablend + Alpha 0.01 + Rect = wtf?

DocFritz(Posted 2005) [#1]
Hi there

I'm trying to do some nice Movement-Blur with easily replacing the Cls-Command with an alpha-blended, black Drawrect. Well it sounds easier than it is because of a nasty Bug, I can't explain. The Background doesn't really fade away, there always will be a grey area where the image was. Look at my Example-Fading-program:


Graphics 800,600,0,60

SetColor 255,255,255
DrawRect 100,100,100,100

WaitKey

While Not KeyHit(KEY_ESCAPE)
SetColor 0,0,0
SetAlpha 0.01
SetBlend ALPHABLEND
DrawRect 100,100,100,100

Flip
Wend


Why the hell doesn't the white rect disappear? If you set Alpha to 0.1, it's not that hard but still visible and it disturbs the whole effect. If you set Alpha to 0.001, the white Rect keeps completely white.

It's just strange. Hope, you can help me.


tonyg(Posted 2005) [#2]
<edit> Ooops, understand now...
'SetGraphicsDriver GLMax2DDriver()
Graphics 800,600,0,60

SetColor 255,255,255
DrawRect 100,100,100,100

WaitKey

While Not KeyHit(KEY_ESCAPE)
SetColor 255,0,0
SetAlpha 0.01
SetBlend ALPHABLEND
DrawRect 100,100,100,100
Flip
Wend

If you still see a white rectangle then uncomment the setgraphicsdriver command and run it again.


fredborg(Posted 2005) [#3]
Hi,

I'm guessing it's because you're running in 16bit mode. If you are you will encounter stuff like this. Try this version it should work in both 16 and 32 bit:
Graphics 800,600,0,60

SetColor 255,255,255
DrawRect 100,100,100,100

WaitKey

While Not KeyHit(KEY_ESCAPE)
SetColor 240,240,240
SetBlend SHADEBLEND
DrawRect 100,100,100,100

Flip
Wend



DocFritz(Posted 2005) [#4]
Nope, neither tonyg's nor fredborgs's program runs like it should. I see a grey non-fading rect in both examples. :/

And, I'm running with 32 Bit. The error still occurs, if i set 32 Bit in the Graphics-Command.


Difference(Posted 2005) [#5]
You are counting on the contens of the backbuffer to be unchanged after a flip.
As far as I know you shouldn't. After a flip the contens of the backbuffer is undefined and you should draw everything again.

In your case draw it and then cover it by a gradually more and more opaque black retangle.


tonyg(Posted 2005) [#6]
On my 9800Pro machine they both work as expected unless I set 0.001 then they stay white.
On my laptop (S3) the image turns 'grey' as if the first alpha change was applied but then stays the same.
Basically, on my laptop I get the same problem, on my desktop it's OK.
It has to be a driver issue.... doesn't it?


Hotcakes(Posted 2005) [#7]
Or the card itself can't handle something simple like alpha properly... maybe... what's your tech specs? And DocFritz, what are yours?


tonyg(Posted 2005) [#8]
Possible, if I change the alpha to 0.1 it works as mentioned above.


DocFritz(Posted 2005) [#9]
I've got a Geforce 6800 GT, I don't think that a new card has Problems with simple Alpha-Stuff *g*
I count on OpenGL. Or on Max2D. On of them must have an error or something.

By the way: Where do I get the new Nvidia OpenGL-Drivers? I don't find them anywhere?


Difference(Posted 2005) [#10]
I'll repeat:

"After a flip the contens of the backbuffer is undefined and you should draw everything again."

Have you tried that?


SoggyP(Posted 2005) [#11]
Hello.

@Peter: Try shouting :o)

Goodbye.


tonyg(Posted 2005) [#12]

I'll repeat:

"After a flip the contens of the backbuffer is undefined and you should draw everything again."

Have you tried that?


Hmmm.. so why does 0.1 work as expected (but too fast) while 0.01 stop before the rect is faded completely?
Interestingly, if you use other values (e.g. 0.05) the
effect gets further but then still stops.


DocFritz(Posted 2005) [#13]
@Peter
No, I haven't tried. But it would mean, that I'd have to draw EVERYTHING about 15 times to get a nice Motionblur. And I donÄt want the FPS to fall down just for a little Effect...

@tonyg
Yeah, it's weird, but there is a system in this anomaly.