About Monkey 2 › Forums › Monkey 2 Programming Help › Drawing 2d pixels
Tagged: http://
This topic contains 6 replies, has 3 voices, and was last updated by
Voidwalker 1 year, 7 months ago.
-
AuthorPosts
-
August 20, 2017 at 1:46 pm #9944
Hi all!
I’m coming from a BlitzMax background, then Monkey now Monkey 2 and have a question. I want to draw quite a lot of single pixels onto the screen. My question, is there a faster way of doing it like I do?
Using Monkey 1 it takes about 10ms for a 512×512 texture to be filled, where Monkey 2 already takes 40ms on my laptop.
August 20, 2017 at 1:48 pm #9945[codebox]
#Import “<std>”
#Import “<mojo>”Using std..
Using mojo..Function Main()
New AppInstance()
New GameWindow( “2D Test”, 800, 600 )
App.Run()
End FunctionClass GameWindow Extends Window
Protected
Field _renderTime:Int
Field _renderTimeCurrent:Int
Field _renderFrameCount:Int
Field _lastRenderTime:IntPublic
Method New( title:String, width:Int, height:Int, flags:WindowFlags = Null )
Super.New( title, width, height, flags )
” Layout = “stretch”
ClearColor = Color.Black
SwapInterval = 0 ‘disable vsync
_lastRenderTime = Millisecs()
SeedRnd( Millisecs() )
End MethodMethod OnWindowEvent( event:WindowEvent ) Override
Select event.Type
Case EventType.WindowMoved
Case EventType.WindowResized
App.RequestRender()
Case EventType.WindowGainedFocus
Case EventType.WindowLostFocus
Default
Super.OnWindowEvent( event )
End Select
End MethodMethod OnRender( canvas:Canvas ) Override
App.RequestRender()
Local st:Int = Millisecs()
_renderTimeCurrent += ( Millisecs() – st )
_renderFrameCount += 1
If( _renderTimeCurrent > 500 )
_renderTime = _renderTimeCurrent / _renderFrameCount
_renderTimeCurrent = 0
_renderFrameCount = 0
End IfFor Local y:Int = 0 Until 511
For Local x:Int = 0 Until 511
Local col:Float = Rnd( 0.0, 1.0 )
canvas.Color = New Color( col, col, col, 1.0 )
canvas.DrawPoint( x, y )
Next
Next_renderTime = Millisecs() – st
Local fps:Int = 0
If( _renderTime > 0 )
fps = 1000 / _renderTime
Else
fps = 1000
End If
canvas.Color = Color.White
canvas.DrawText( “Rendertime: ” + _renderTime + “ms / FPS: ” + fps, 10, 580 )_lastRenderTime = Millisecs()
End Method
End Class[/codebox]
August 20, 2017 at 1:49 pm #9946Sorry, I cannot format the code better, because I get:
<h1>403 Forbidden</h1>
A potentially unsafe operation has been detected in your request to this site.WTF? I may not even attach a monkey2 file… I’m sorry if this comes a bit unstructured.
How am I supposed to use “code tags”?
August 20, 2017 at 4:45 pm #9947My 2013 MacBook Air does it in between 10 and 12 Milliseconds in release mode.
August 20, 2017 at 5:04 pm #9948Interesting. Mine is a MacBook Air from 2011 but running Windows 10.
August 21, 2017 at 12:48 pm #9951This has been discussed on this topic :
An even faster way would be custom glsl shader but I don’t know how shaders are managed now after the modifications induced by mojo3d.
August 29, 2017 at 7:15 pm #10108Thanks, this speeded up things from 40ms to 14ms on my old laptop. Fantastic!
I wish there would be something like a good documentation. Is this coming at any time?
-
AuthorPosts
You must be logged in to reply to this topic.