GLBasic forum

Main forum => GLBasic - en => Topic started by: AndyH on 2008-Mar-27

Title: Glow effects
Post by: AndyH on 2008-Mar-27
Hi all

Is there any way to make glow effects in GLB?

What I'd normally do is use an alpha channel and additive blending.  I don't think GLB can currently load graphics with alpha channels?

I've tried alphamode 0.1 -> 1.0 with a variety of graphics but I'm not able to find anything that works for me.

I also found this (http://www.retroremakes.com/forum2/showthread.php?t=9189&highlight=Glow+effect) (scroll down to Gernot's post) which looks interesting over at RR, but I can't seem to get it to work.

Any suggestions (and code examples)?
Title: Glow effects
Post by: Kitty Hello on 2008-Mar-28
You can load alpha channel PNGs. No Problem.

My vector scramble and the Quantum remake have "glowing" lines. Is that what you need?
Title: Glow effects
Post by: AndyH on 2008-Mar-28
Ah - cool.  I think I must have messed up my alpha channel when I saved my image and just assumed they weren't supported.  This is perfect then thanks.  I remember a post now that I think about it, it's only OpenGL platforms that support the alpha channel so PPC and GP2X will ignore them, is that right?

Yes, I came across that line effect in that linked post which looked cool in the screenshots but I couldn't figure out how to use it as my line didn't look the same.  I'd like to put a small glowing trail on some objects.
Title: Glow effects
Post by: Kitty Hello on 2008-Mar-28
PPC will ignore it. I'll have to fix that one now. Darn.

Do you want a polyline or a single line shaded?
Title: Glow effects
Post by: AndyH on 2008-Mar-28
I'm making a quick game (for the RR project) for Windows, Mac & Linux, so I don't need the alpha channel support for PPC right now.  A nice to have for the future when you've some time to look at it I guess.

I'd like to make a short to medium length trail for an object that doesn't  change direction.  The line will be around 8 pixels width, but could be wider, and I'd like it to fade out at one end.
Title: Glow effects
Post by: AndyH on 2008-Mar-29
Got the glow effect I am after (thanks to getting the alpha channel working right along with the additive alphamode) and I've modified the CoolLine function to draw a glow line in the way that I want (code below).  Thanks for all the help on this :)

Code (glbasic) Select
// to make this more flexible, could work out the sprite (spr) image width and height - I've got it set up for a 32x32 sprite.
FUNCTION CoolLine: spr, x1, y1, x2, y2, w, col, alpha
LOCAL c,s,p, dx, dy, ddx, ddy, ux, uy, lg

// direction of line
ddx = x2-x1
ddy = y2-y1
lg = QSQR(ddx*ddx+ddy*ddy)
IF lg<0.1 THEN RETURN

// short caps
lg=lg+lg
// dir vector
dx=ddx*w/lg
dy=ddy*w/lg
// up vector
ux=dy
uy=-dx

ALPHAMODE alpha/2

STARTPOLY spr
POLYVECTOR x1+ux*2, y1+uy*2, 0.5,  0.5,col
POLYVECTOR x1-ux*2, y1-uy*2, 0.5, 31.5,col
POLYVECTOR x2-ux*2, y2-uy*2, 31.5, 31.5,col
POLYVECTOR x2+ux*2, y2+uy*2, 31.5,  0.5,col
ENDPOLY

ALPHAMODE alpha
// center
STARTPOLY spr
POLYVECTOR x1+ux, y1+uy, 0.5,  0.5,col
POLYVECTOR x1-ux, y1-uy, 0.5, 31.5,col
POLYVECTOR x2-ux, y2-uy, 31.5, 31.5,col
POLYVECTOR x2+ux, y2+uy, 31.5,  0.5,col
ENDPOLY

ALPHAMODE alpha/2
ENDFUNCTION
Here's the image I'm using....

(http://baa.ovine.net/texLaser.png)
Title: Glow effects
Post by: Kitty Hello on 2008-Mar-31
Ah. The image I was using was a circle rather than a bar-shaped image. Then the caps are drawn "rounded". But you removed the caps, too. So, no worries.
Title: Glow effects
Post by: AndyH on 2008-Mar-31
Yes, I need to put the caps in again now (as I'm using connecting lines).  I realised that is what your example should have been doing but I was having some problems with it (it wasn't putting rounded edges on).  It might have been a bug in my code though, as I fixed something in my sprite handler.  I'll post an update to the code I'm using tonight.