creating lightsources

BlitzMax Forums/BlitzMax Programming/creating lightsources

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

Your pretty much limited on the number of lights you can have (8 usualy)

Remember that's a minimum of 8 lights per vertex. You can move lights during the draw cycle, switch them on or off etc.

That's a lovely article on gamedev. If you look at the author's web site it's got a few good screenshots: http://www.orangytang.net/VScript/stypeScreenshotThumbs.php
It's only good for dynamic lighting with shadows though. Light maps would be better for static lighting with shadows.

[EDIT] Here's a little demo I knocked up that uses some basic OpenGL lighting.
Strict

Graphics 640,480,0

Local img:TImage = LoadImage("ball.png")

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#[] = [1.0,1.0,1.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.001
glLightf GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0001 


' Let's set up another light
glEnable GL_LIGHT1
Local l1_diffuse#[] = [0.7,0.0,0.8,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

	For Local x=0 To GraphicsWidth() Step 64
		For Local y=0 To GraphicsHeight() Step 64
			DrawImage img,x,y
		Next
	Next

	Flip
	FlushMem
Wend