mojo2.mod - scissor

Started by wombats, February 25, 2024, 03:45:21

Previous topic - Next topic

wombats

Hi,

Is it possible to rotate the scissor rectangle in mojo2? I have rotated bitmap text that I only want to be visible if it fits within its container. Is there another way to achieve that if the scissor can't be rotated?

angros47

No, it is not possible, because it is not supported by the graphic driver. To do what you want you would likely need to use stencils.

Derron

I assume mojo has some render2texture thing ? 

Render your text on the canvas/rendertarget which has the "scissor rectangle" size. Use x,y (offsets) of your bitmap text draw command as desired ...
Render out the created canvas/rendertarget as desired (rotated, scaled, ...)

This way you also can "cache" all bitmap font glyphs on a single canvas/texture resulting in a single draw call at the end - instead of one for each character displayed.
Of course it is better for static stuff (so no animation done with the individual chars or similar) - but it would work with that too.


bye
Ron

wombats

#3
Quote from: Derron on February 25, 2024, 10:04:30I assume mojo has some render2texture thing ?

Render your text on the canvas/rendertarget which has the "scissor rectangle" size. Use x,y (offsets) of your bitmap text draw command as desired ...
Render out the created canvas/rendertarget as desired (rotated, scaled, ...)

This way you also can "cache" all bitmap font glyphs on a single canvas/texture resulting in a single draw call at the end - instead of one for each character displayed.
Of course it is better for static stuff (so no animation done with the individual chars or similar) - but it would work with that too.


bye
Ron
Thanks for the idea. I tried it before, but it crashes...the rendertoimage.bmx example crashes as well on line 20:

QuoteLocal image:TImage = New TImage.Create( 256,256 )

There seems to be an issue in the Destroy() method of TMaterial in graphics.bmx. I'm on macOS 13.4.1.

Derron

On Linux (Mint 21.1) it works as expected:
Just had to update that rendertoimage.bmx line a bit:

icanvas.SetColor(Float(Sin( MilliSecs()*.1 )*.5+.5), Float(Cos( MilliSecs()*.1 )*.5+.5), .5)


PS: Mky.mod/mojo2.mod is using OpenGL ... dunno how fancy a current macOS is about OGL. If you are just playing around with mojo2.mod for now you _might_ consider using sdl.mod and max2d (so for now no shader support out of the box).


bye
Ron