Anaglyph test

BlitzMax Forums/BlitzMax Programming/Anaglyph test

Hmmm...just found this, which is almost something I was gonna do next...in fact it will be! However, I've added proper cyan/red color and decent settings, so now it works great for all those with cyan/red anaglyph glasses:


SuperStrict
Global eye_shift:Int

Type TEntity
	Global list:TList = CreateList()
	
	Function update_all()
		For Local e:TEntity = EachIn list
			e.update
		Next
	EndFunction
	
	Function draw_all()
		list.sort
		eye_shift = 10
		glColorMask( False, True,True,True )
		For Local e:TEntity = EachIn list
			e.pre_draw
			e.draw
		Next
		glColorMask( True, False,False,True )
		eye_shift = 5
		For Local e:TEntity = EachIn list
			e.pre_draw
			e.draw
		Next
		glCOlorMask( True,True,True,True )
	EndFunction

	Field x:Int,y:Int,z:Float, nz:Float

	Method New()
		list.addlast(Self)
		x = 0
		y = 0
		z = 0.0
	EndMethod
	
	Method compare:Int( o:Object )
		Local oe:TEntity = TENtity(o)
		If Not oe Then Return -1
		If Abs(oe.z - z) < 0.001 Then Return 0
		If oe.z > z Then Return 1
		Return -1
	EndMethod

	Method pre_draw()
		z = Max(Min(z,1), -1)
		nz = z*eye_shift
	EndMethod

	Method draw()
		SetColor 255,255,255
		DrawRect x-25+nz,y-25, 50,50 	
	EndMethod

	Method update()	
	EndMethod

	Method move( xo:Int,yo:Int,zo:Float )
		x :+ xo
		y :+ yo
		z :+ zo
	EndMethod
EndType

Type TBall Extends TEntity
	Field angle:Float
	Method draw()
		SetBlend lightblend
		SetColor 0,255,255
		DrawOval x-50+nz,y-50, 100,100
		SetColor 255,0,0
		DrawOval x-50,y-50, 100,100
	EndMethod
	Method update()
		x = 320+Cos(angle) * 200
		y = 240+Sin(angle) * 75
		z = Cos(angle+90)
		angle:+1
	EndMethod
EndType


Graphics 640,480,0

Local e:TEntity = New TEntity
e.x = 320
e.y = 240

For Local b:Int = 0 Until 10
	Local t:TBall = New TBall
	t.angle = b*36
Next

While Not KeyHit( KEY_ESCAPE )
	TEntity.draw_all

	SetColor 255,255,255
	DrawText "Move square with arrow keys", 0,0
	DrawText "Move it in or out of the screen with A/Z", 0,12
	Flip	
	Cls
	
	TEntity.update_all
	If KeyDown( KEY_A ) Then e.move(0,0,-0.1)
	If KeyDown( KEY_Z ) Then e.move(0,0,+0.1)
	If KeyDown( KEY_LEFT ) e.move(-1,0,0)
	If KeyDown( KEY_RIGHT ) e.move( 1,0,0)
	If KeyDown( KEY_UP ) e.move( 0,-1,0)
	If KeyDown( KEY_DOWN ) e.move( 0,1,0)
Wend