How to draw a glowing "energy beam" ?

BlitzMax Forums/BlitzMax Programming/How to draw a glowing "energy beam" ?

Captain Darius(Posted 2005) [#1]
Im really hoping someone can help me with this...

What is need is to be able to "draw" an "energy beam" or "laser beam" kinda effect. Of course I would like this to look much better than just a red or blue line on the screen. I want some sort of "glow" or "plasma" effect if you guys get my drift.

I don't know enough about what types of effects are available to me (like lighting and shading and such) to even begin to try this.

I'm looking for ideas and/or sample code.

Any help would be greatly appreciated!


rod54(Posted 2005) [#2]
wondering why no one in the know has even bothered answering this.... should this be moved to the beginners forum so he can get an answer.


Bot Builder(Posted 2005) [#3]
Best way is probably a streched sprite... err i forgot which mode, but the mode that makes sprite roll towards you. Load the sprite as a png with alpha.


Genexi2(Posted 2005) [#4]
I believe setting the blend mode of the sprite to multiply (dunno how that's done in BMAX) will add to the effect Bot described.


Xip(Posted 2005) [#5]
[Edit] Never mind... [/Edit]


tonyg(Posted 2005) [#6]
Have a look at the samples where, under Birdie/misc, there's a glblur and a lighting example.
You could create your laser image, colour it then use lightblend.


Robert(Posted 2005) [#7]
Maybe this will help:

Edit: SetLineWidth only works with the OpenGL implementation of Max2D at the moment.

SetGraphicsDriver GLMax2DDriver()

Local lastTime:Float=MilliSecs()
Local timeNow:Float=lastTime
Local timeConstant:Float

Local powerTime:Float
Local alphaTime:Float

Graphics 640,480,0

SetBlend ALPHABLEND


While Not KeyHit(KEY_ESCAPE)
	
	'Calculate a time constant so program runs at equal speed on all PCs
	timeNow=MilliSecs()
	timeConstant=(timeNow-lastTime)/100
	lastTime=timeNow
	
	'Depending on how much we add to powerTime and alphaTime, the speed at which the laser changes strength will vary
	'The laser's "power" is how quickly it changes from coloured (at the edge) to white (in the middle).
	'By using SetAlpha before calling drawLaser, we can make the width of the beam appear to change over time, since
	'the edge of the beam becomes transparent at a lower alpha level than the centre of the beam.
	powerTime :+ timeConstant*20
	alphaTime :+ timeConstant*40
	
	SetColor 20,200,20
	SetAlpha 0.1+Abs(Sin(alphaTime)*0.35)
	drawLaser(10,10,300,300,20,0.25+Abs(Sin(powerTime)*0.75))

		
	Flip
	Cls
	PollSystem
	
Wend

'Creates a laser effect by drawing a whole series of lines, starting at the specified width and working down
'towards a line only a pixel wide.  Each time it draws a line it brightens the colour, which makes the centre 
'appear hotter.
Function drawLaser(x1,y1,x2,y2,width:Float,power:Float)

	Local initialWidth:Float=width
	

	While (width > 0)
		SetLineWidth width
		
		
		DrawLine x1,y1,x2,y2,False
	
		
		Local r,g,b
		GetColor(r,g,b)
		
		SetColor(Min(r+(20*power),255),Min(g+(20*power),255),Min(b+(20*power),255))
		
		width :- 1
	End While

End Function




rod54(Posted 2005) [#8]
The SetLineWidth function does not appear to work.

Added a SetLineWidth command in the DrawLine help code and it does not appear to work there either

Found link in bugs reported on this and SetLineWidth only appears to work with openGL


Cruis.In(Posted 2006) [#9]
very nice code!
but how would you check for a collision with this?


ImaginaryHuman(Posted 2006) [#10]
Note also that setlinewidth is not always supported correctly on all implementations of OpenGL. On one computer I get the proper width and on another I get no increase.


tonyg(Posted 2006) [#11]
I would stretch a 'glowing beam' texture over an increasing poly/surface using Indiepaths TexturedPoly or the SetUV method.