Author Topic: Glow effects  (Read 3701 times)

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
Glow effects
« 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 (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)?

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10816
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Glow effects
« Reply #1 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?

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
Glow effects
« Reply #2 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.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10816
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Glow effects
« Reply #3 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?

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
Glow effects
« Reply #4 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.

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
Glow effects
« Reply #5 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....


Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10816
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Glow effects
« Reply #6 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.

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
Glow effects
« Reply #7 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.