I don't remember whose code this was but here's an example using an OpenGL lightsource. Just replace the loadimage call with some tile (ideally 32x32) to use as the background
Strict
SetGraphicsDriver GLMax2DDriver()
Graphics 640,480,0
Local img:TImage = LoadImage( your-image-here )
SetBlend(ALPHABLEND)
glEnable GL_LIGHTING ' Switch on lighting. All lights are off now.
' Let's set up a light
glEnable GL_LIGHT0 ' Switch on the light
Local l0_diffuse#[] = [0.6,0.3,0.0,1.0] ' Light colour - R,G,B,i (keep i at 1.0)
glLightfv GL_LIGHT0, GL_DIFFUSE, l0_diffuse
' These control how the light intensity drops off with distance.
' These settings make it work like a spotlight.
glLightf GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.0
glLightf GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.00000
glLightf GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.00001
' Let's set up another light
'glEnable GL_LIGHT1
Local l1_diffuse#[] = [0.5, 0.0,0.5,1.0] ' R,G,B,i (keep i at 1.0)
glLightfv GL_LIGHT1, GL_DIFFUSE, l1_diffuse
glLightf GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.0
glLightf GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.001
glLightf GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.0001
' Lighting looks best if you give it a position out of the 2D plane. x=50.0 looks about right.
Local l0_position#[] = [0.0,0.0,50.0,1.0] ' X,Y,Z,w (keep w at 1.0)
Local l1_position#[] = [0.0,0.0,50.0,1.0]
Local a# = 0.0 ' Angle of the moving light
While Not KeyHit(KEY_ESCAPE)
Cls
l0_position[0] = MouseX()
l0_position[1] = MouseY()
glLightfv GL_LIGHT0, GL_POSITION, l0_position ' actually move the light
' l1_position[0] = 0.5 * (GraphicsWidth() + GraphicsHeight()*Cos(a))
' l1_position[1] = 0.5 * (GraphicsHeight() + GraphicsHeight()*Sin(a))
glLightfv GL_LIGHT1, GL_POSITION, l1_position
a :+ 1.0
glLightf GL_LIGHT0, GL_QUADRATIC_ATTENUATION, Rnd(0.00005, 0.00007)
For Local x=0 To GraphicsWidth() Step 32
For Local y=0 To GraphicsHeight() Step 32
DrawImage img,x,y
Next
Next
Flip
Wend
|