Makpaint.. sloooow

BlitzMax Forums/BlitzMax Beginners Area/Makpaint.. sloooow

I don't know how accurate this is (nor whether it could be more efficient), but I only get 1fps more when drawing directly to the backbuffer (via plot).

Graphics 800,600,0,0

Const ALPHABITS=$FF000000


Type TRGB
	Field Red:Int 'could use byte but int is faster
	Field Green:Int
	Field Blue:Int
	Field Alpha:Int
	
	Method AsInt:Int()
		Return ( Red| (Green Shl 8) | (Blue Shl 16))
	End Method
	
	Method FromInt(col:Int)
		Red = col Shr 16 & $FF
		Green = col Shr 8  & $FF
		Blue = col & $FF
	End Method
	
	Method SetCol()
		SetColor Red, Green, Blue
	End Method
End Type


Local tempImage = CreateImage(256,256)
Local pMap : TPixmap
Local RGB : TRGB = New TRGB

Local LastTime:Int
Local TimeDiff : Int
Local StartTime:Int
Local timecount:Int = 0
Local counter :Int =0


While Not KeyDown(KEY_ESCAPE)

StartTime = MilliSecs()

	Cls

	'Local tempImage = CreateImage(256,256)
	pMap = LockImage(tempImage)
	
	For Local X:Int = 0 To 255
		For Local Y:Int = 0 To 255
			RGB.Red = Rand(0,255)
			RGB.Green = Rand(0,255)
			RGB.Blue = Rand(0,255)
			
			WritePixel(pMap, X,Y,ALPHABITS|RGB.AsInt())
		Next
	Next
	UnlockImage(tempImage)
			
	'DrawImageRect(tempImage, 0, 0, GraphicsWidth(),GraphicsHeight()) 
	DrawImage(tempImage,0, 0)

	

	Flip

TimeDiff = MilliSecs()-StartTime
TimeCount :+TimeDiff
counter :+ 1
FlushMem

Wend


Print TimeCount/counter +"ms/frame"
Print "FPS: "+1000/(TimeCount/counter)
tempImage = Null
pMap = Null

FlushMem()
FlushKeys()
Cls
DrawText("press any key for plot test", 10,10)
Flip

WaitKey()

LastTime = 0
TimeDiff = 0
StartTime = 0
timecount = 0
counter = 0


'plot test
'Local RGB:TRGB = New TRGB

While Not KeyDown(KEY_ESCAPE)
StartTime = MilliSecs()
Cls

	For Local X2:Int = 0 To 255
		For Local Y2:Int = 0 To 255
			RGB.Red = Rand(0,255)
			RGB.Green = Rand(0,255)
			RGB.Blue = Rand(0,255)
			RGB.SetCol
			Plot(X2,Y2)
		Next
	Next
FlushMem

Flip

TimeDiff = MilliSecs()-StartTime
TimeCount :+TimeDiff
counter :+ 1

Wend

Print TimeCount/counter +"ms/frame"
Print "FPS: "+1000/(TimeCount/counter)

End