Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: rdc on November 12, 2006
-
I came across this http://www.gamedev.net/reference/articles/article874.asp on lens flare (which I was thinking of using) but I discovered a section on alpha blending. Since the FB alpha parm only works with PUT I converted the C code to FB so I could use it with PSET (or buffer). Here is the code:
'Based on article: http://www.gamedev.net/reference/articles/article874.asp
option explicit
const sw = 640
const sh = 490
const centerx = 640/2
const centery = 480/2
dim as integer alpha, invalpha, x, y
dim as integer sr, sg, sb, cr, cg, cb, r, g, b
screenres sw, sh, 32
'Alpha and Inverse alpha
alpha = 100
invalpha = 255 - alpha
'background color
sr = 255
sg = 0
sb = 0
'Overlay color
cr = 255
cg = 255
cb = 0
'Draw a box
line (centerx - 120, centery - 120)- (centerx + 120, centery + 120), RGB(sr, sg, sb), BF
'Overlay a yellow box on red box
for x = centerx - 100 to centerx + 100
for y = centery - 100 to centery + 100
'calc the alpha values
r = ((cr * alpha) + (sr * invalpha)) shr 8
g = ((cg * alpha) + (sg * invalpha)) shr 8
b = ((cb * alpha) + (sb * invalpha)) shr 8
pset(x, y), RGB(r, g, b)
next
next
sleep
While it is not particularly speedy, it does seem to work.
-
Thanks for sharing it Rick :)
-
No problem, it is quite a nice article. I am going to try and give that lens flare example a try. I think if someone new some asm, you could probably speed up the calculations for this quite a bit, although it may be acceptable using a ptc buffer rather than pset, which is quite slow. Ar any rate, I am going to try and use it for my demo and see how it works out.
-
It would definately work quite well using ptc :) I've used alpha myself in quite a few things and been pleased with the results.