Drawing 2d pixels

About Monkey 2 Forums Monkey 2 Programming Help Drawing 2d pixels

Tagged: 

This topic contains 6 replies, has 3 voices, and was last updated by  Voidwalker 1 year, 7 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #9944

    Voidwalker
    Participant

    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.

    #9945

    Voidwalker
    Participant

    [codebox]

    #Import “<std>”
    #Import “<mojo>”

    Using std..
    Using mojo..

    Function Main()
    New AppInstance()
    New GameWindow( “2D Test”, 800, 600 )
    App.Run()
    End Function

    Class GameWindow Extends Window
    Protected
    Field _renderTime:Int
    Field _renderTimeCurrent:Int
    Field _renderFrameCount:Int
    Field _lastRenderTime:Int

    Public
    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 Method

    Method 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 Method

    Method 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 If

    For 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]

    #9946

    Voidwalker
    Participant

    Sorry, 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”?

    #9947

    Jesse
    Participant

    My 2013 MacBook Air does it in between 10 and 12 Milliseconds in release mode.

    #9948

    Voidwalker
    Participant

    Interesting. Mine is a MacBook Air from 2011 but running Windows 10.

    #9951

    abakobo
    Participant

    This has been discussed on this topic :

    Julia set fractal generator optimisation (drawpoint)

    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.

    #10108

    Voidwalker
    Participant

    Thanks, 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?

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.