I know this code is not the shortest one, but it does not need external mediafiles.
At the moment, the graphics are drawn ten times per flip ... if you increase it to 100, you will see an increase of the time the flip needs...
I think "DrawImage" is not also "draw the image to the memory of the backbuffer" - if this would be that way, there would be a nearly constant flip-time.
Some results:
. . Athlon 1800xp+, 1024mb ram, Radeon 9600Pro, 32Bit, 1280x1024, 60Hz TFT:
. . . . AvgFlipTime: 8ms
. . . . FPS: 96
. . Pentium IV 2,4GHz, 1024mb ram, Sis 651 (64mb shared memory), 32Bit, 1024x768, 75Hz CRT:
. . . . AvgFlipTime: 32ms
. . . . FPS: 27
(slight increase possible, when in fullscreen and 16bit on the sis-chip)
As I am drawing many small sprites (figures, doors, plants, clouds, parallax-scrolling-background-buildings,...) the amount of loops in the code could be 1/2 to be equal to the things my game draws.
bye
MB
At the moment, the graphics are drawn ten times per flip ... if you increase it to 100, you will see an increase of the time the flip needs...
I think "DrawImage" is not also "draw the image to the memory of the backbuffer" - if this would be that way, there would be a nearly constant flip-time.
Some results:
. . Athlon 1800xp+, 1024mb ram, Radeon 9600Pro, 32Bit, 1280x1024, 60Hz TFT:
. . . . AvgFlipTime: 8ms
. . . . FPS: 96
. . Pentium IV 2,4GHz, 1024mb ram, Sis 651 (64mb shared memory), 32Bit, 1024x768, 75Hz CRT:
. . . . AvgFlipTime: 32ms
. . . . FPS: 27
(slight increase possible, when in fullscreen and 16bit on the sis-chip)
As I am drawing many small sprites (figures, doors, plants, clouds, parallax-scrolling-background-buildings,...) the amount of loops in the code could be 1/2 to be equal to the things my game draws.
SuperStrict Framework brl.GLMax2D Import brl.Max2D Import brl.d3d7max2d Import brl.glmax2d Import BRL.StandardIO Import brl.Random SetGraphicsDriver GLMax2DDriver() Global g:TGraphics = Graphics(800, 600, 0, 60, 0) SetBlend ALPHABLEND Global ExitGame:Int = 0 Global GrafikFPS:Int = 0 Global tempGrafikFPS:Int = 0 Global LastSecondTime:Int = 0 Global FlipTime:Int =0 Global FlipTimeSum:Int =0 Global FlipCount:Int =0 Global AvgFlipTime:Int =0 'creating images '=============================================== Global gfx_interface_left:TImage = CreateImage(20,373) SetColor 255,0,255; DrawRect(0,0,20,373); GrabImage(gfx_Interface_left,0,0);Cls Global gfx_interface_top:TImage = CreateImage(800,10) SetColor 205,0,105; DrawRect(0,0,800,10); GrabImage(gfx_Interface_top,0,0);Cls Global gfx_interface_right:TImage = CreateImage(20,373) SetColor 255,0,255; DrawRect(0,0,20,373); GrabImage(gfx_Interface_right,0,0);Cls Global gfx_interface_bottom:TImage = CreateImage(800,217) SetColor 155,0,205; DrawRect(0,0,800,217); GrabImage(gfx_Interface_bottom,0,0);Cls Global gfx_mousecursor:TImage = CreateImage(32,32) SetColor 0,100,0; DrawRect(0,0,32,32); GrabImage(gfx_mousecursor,0,0);Cls 'normally an image with alpha component Global gfx_interface_antenna:TImage= CreateImage(100,60) Local Pix:TPixmap = LockImage(gfx_interface_antenna) For Local i:Int = 0 To 100 -1 For Local j:Int = 0 To 60 -1 WritePixel(Pix, i, j, (Int(Rand(255)*$1000000)+Int(255*$10000)+Int(Rand(255)*$100)+Int(0))) Next Next UnlockImage(gfx_interface_antenna) Global gfx_building_house:TImage = CreateImage(512,1080) Pix = LockImage(gfx_building_house) For Local i:Int = 0 To 512 -1 For Local j:Int = 0 To 1080 -1 WritePixel(Pix, i, j, (Int(255*$1000000)+Int(0*$10000)+Int(Rand(255)*$100)+Int(0))) Next Next UnlockImage(gfx_building_house) '=============================================== Function DrawMain() Cls SetColor 255,255,255 'try increasing the loop-amount here... it affects the FlipTime-value For Local i:Int = 0 To 10 SetViewport(10,10,780,373) DrawImage(gfx_building_house, 127, -420) SetViewport(0,0,800,600) DrawImage(gfx_interface_top,0,0) DrawImage(gfx_interface_left,0,10) DrawImage(gfx_interface_right,780,10) DrawImage(gfx_interface_bottom, 0, 383) DrawImage(gfx_interface_antenna, 98,328) DrawImage(gfx_mousecursor, MouseX(),MouseY()) Next SetColor 0,0,0; DrawRect(10,15,170,60); SetColor 255,255,255 DrawText ("FlipTime: "+FlipTime + "ms", 15,20) DrawText ("AvgFlipTime: "+AvgFlipTime + "ms", 15,35) DrawText ("FPS: "+GrafikFPS, 15,50) FlipTime = MilliSecs() Flip 0 FlipTime = MilliSecs()-FlipTime FlipTimeSum:+ FlipTime FlipCount:+1 Delay(1) EndFunction Repeat Local NowSecondTime:Int = MilliSecs() If KeyHit(KEY_ESCAPE) ExitGame = 1;Exit DrawMain() tempGrafikFPS:+1 'calculating FPS and average FlipTime If NowSecondTime-LastSecondTime > 1000 Then GrafikFPS = Ceil((tempGrafikFPS*1000) / (NowSecondTime-LastSecondTime-tempGrafikFPS)) LastSecondTime = NowSecondTime If FlipCount > 0 Then AvgFlipTime = Ceil(FlipTimeSum*100 / FlipCount)/100 FlipTimeSum = 0 FlipCount = 0 tempGrafikFPS = 0 EndIf Until AppTerminate() Or ExitGame = 1
bye
MB