mojo2 drawing to canvas

Monkey Forums/Monkey Programming/mojo2 drawing to canvas

Capn Lee(Posted 2016) [#1]
I think I may be missing something in how the canvas works and hope someone can explain where I'm going wrong

Import mojo2

Const VWIDTH:Int = 320
Const VHEIGHT:Int =240

Class MyApp Extends App
    Field canvas:Canvas
    
    Method OnCreate()
        canvas=New Canvas()
        canvas.SetProjection2d(0, VWIDTH, 0, VHEIGHT)
    End
    
    Method OnRender()
        
        canvas.Clear()
		canvas.SetColor(1, 0, 1)
        For Local w:Int = 0 Until VWIDTH
			canvas.DrawLine(w, 0, w, VHEIGHT)
		Next
        canvas.Flush()
    End
End

Function Main()
    New MyApp()
End


What I would expect this code to do would draw in each strip of the canvas in magenta, what actually happens changes depending on the target


(this image is scaled a bit, click for the full size image)

in html5 is blends the black and magenta colors together to form a muddy color and on glfw it displays every other line as magenta. It seems like it is only filling in every other line in the render method.

This is only a problem when using SetProjection2D so seems to be me misunderstanding how it works in some way. Any help would be greatly appreciated


skid(Posted 2016) [#2]
The problem here seems to be antialiasing. With GLFW target on my Mac the lines are not antialised by default where as in WebGL they are.


ratking(Posted 2016) [#3]
Yeah, the WebGL antialiasing is unfortunate, I wonder if there's a way around it.


rIKmAN(Posted 2016) [#4]
I'm guessing it doesn't work with Mojo2 like it does with Mojo1 as skid would have suggested it, but I'll throw it out there as a suggestion:
#MOJO_IMAGE_FILTERING_ENABLED = True



ratking(Posted 2016) [#5]
Yes, that doesn't work, especially not with HTML5.