Author Topic: FB Alpha Blend with PSET  (Read 2410 times)

0 Members and 1 Guest are viewing this topic.

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
FB Alpha Blend with PSET
« 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:

Code: [Select]
'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.
« Last Edit: December 11, 2006 by rdc »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: FB Alpha Blend with PSET
« Reply #1 on: November 12, 2006 »
Thanks for sharing it Rick :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: FB Alpha Blend with PSET
« Reply #2 on: November 12, 2006 »
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.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: FB Alpha Blend with PSET
« Reply #3 on: November 12, 2006 »
It would definately work quite well using ptc :) I've used alpha myself in quite a few things and been pleased with the results.
Shockwave ^ Codigos
Challenge Trophies Won: