Bug Found: DrawRect not drawing accurate alpha levels.
Verified on 2 different GPU's.
You can change a var at the top to change the driver in order to test the code.
SuperStrict
'
' Basic Blitzmax Noob Sprite Demo By "MGE"
'
'Import "Dx9Max2dDriver\Dx9Max2dGraphicsDriver0.5.bmx"
Import "Dx9Max2dDriver\Dx9Max2dGraphicsDriver.bmx"
'
' Just change this var to test the various drivers
'
Global testdriver:Int = 1 ' 1=dx9, 2=dx7, 3=opengl
'
'
'
Incbin "Media\tile.png"
'
Const howmany:Int = 100 ' <<<<<< Change this value for how many
'
Global sprites:TSprite[howmany] ' Create an array of the type "TSprite"
Global MyImage:Timage = LoadAnimImage:TImage( "Incbin::Media\tile.png",32,32,0,64,FILTEREDIMAGE | MIPMAPPEDIMAGE)
Global fps:Int ' used to display the frames per second
Global fpstotal:Int ' counts how many frames rendered in 1000ms (1 second)
Global ms:Float ' var to keep track if 1000ms (1 sec) has passed
Global ms_start:Float ' var holds the beginning ms value at top of loop
Global delta:Float ' simple delta time var. Different between start and end in loop.
'
Type TSprite
Field x:Float,y:Float
Field xdir:Float,ydir:Float
Field alfa:Float
Field blendtype:Int
Field tile:Int
'
Method init()
x = Rand(100,700)
y = Rand(100,500)
xdir = Rnd(-.2,.2)
ydir = Rnd(-.2,.2)
tile=Rand(0,63)
If Rand(0,100)>50
blendtype = ALPHABLEND
Else
blendtype = LIGHTBLEND
EndIf
alfa = Rnd(.1,1)
End Method
'
Method update()
x=x+(xdir*delta)
y=y+(ydir*delta)
If x>800 Or x<0
xdir=-xdir
x=x+xdir
EndIf
If y>600 Or y<0
ydir=-ydir
y=y+ydir
EndIf
'
End Method
'
Method render()
SetAlpha alfa
SetBlend blendtype
DrawImage MyImage:Timage,x,y,tile
'DrawRect x,y,32,32
End Method
'
End Type
'
Select testdriver
Case 1
SetGraphicsDriver D3D9Max2DDriver()
Case 2
SetGraphicsDriver D3D7Max2DDriver()
Case 3
SetGraphicsDriver GLMax2DDriver()
End Select
'
FlushKeys()
FlushMouse()
'
If Confirm("FULL SCREEN?")= True
Graphics(800,600,32,60) ' width, height, depth (16,32, 0=windowed), hz
Else
Graphics(800,600,0,60) ' width, height, depth (16,32, 0=windowed), hz
EndIf
'
For Local c:Int = 0 To howmany-1 ' arrays start at 0 so we go to total - 1
sprites[c] = New TSprite ' fill our array with our object type
sprites[c].init ' call the Object's init routine to set up the sprite
Next
'
HideMouse()
FlushKeys()
FlushMouse()
'
resetstates() ' reset render states
ms = MilliSecs() ' get the current 1000ms clock
'
Repeat
'
ms_start=MilliSecs()
'
Cls
'
SetColor(255,0,0)
Local x1:Int=0,y1:Int=0,x2:Int=799,y2:Int=599
For Local c:Int=1 To 10
DrawLine x1,y1,x2,y1
DrawLine x2,y1,x2,y2
DrawLine x2,y2,x1,y2
DrawLine x1,y2,x1,y1
x1=x1+20
y1=y1+20
x2=x2-20
y2=y2-20
Next
'
SetColor(255,255,255)
'
For Local obj:TSprite = EachIn sprites ' cycle through all objects in array
obj.update ' Call the "update" method to update sprite's position.
obj.render ' Call the "render" method to display the sprite.
Next
'
' ---------------------------------------------------------
' Here's the bug
'
' In DX7 and OpenGL mode, the rect is draw full alpha, over drawing everything.
' In DX9, the rect still has alpha in it, not over drawing everything.
'
SetTransform(0,1,1)
SetColor(255,255,255)
SetAlpha(1)
SetBlend(ALPHABLEND)
DrawRect(300,200,200,200)
'
' ---------------------------------------------------------
'
resetstates()
DrawText "FPS: "+fps,0,0 ' Display how fast the program is running.
If KeyDown(KEY_V)
Flip(1) ' Flip(1) for vsync, Flip(0) for full speed
Else
Flip(0)
EndIf
delta = MilliSecs() - ms_start ' Computer delta, start time - end time of loop
'
DoFPS() ' Keep track of how many frames per second
'
Until KeyHit(KEY_ESCAPE) ' Press ESC to exit
'
ShowMouse()
EndGraphics() ' Close down graphics device
End ' Still need docs on this command.
'
Function resetstates() ' Reset render states
SetColor(255,255,255)
SetAlpha(1)
SetBlend(ALPHABLEND)
SetTransform 0,1,1
End Function
'
Function DoFPS() ' Inc frames, and track if 1 sec has passed
fpstotal = fpstotal + 1
If MilliSecs()>ms
fps = fpstotal
fpstotal = 0
ms = MilliSecs() + 1000
EndIf
End Function