SyntaxBoom

Languages & Coding => BlitzMax (NG/Vanilla variants) => Tutorials => Topic started by: Midimaster on Aug 30, 2025, 09:11 AM

Title: RenderImage() together with MaxGui
Post by: Midimaster on Aug 30, 2025, 09:11 AM
I asked myself if it is possible to render Draw... commands direct to an image instead of the screen. Therefore we have SetRenderImage() which redirects all drawing command to an TImage. But does this also work with MaxGui and Canvases?

Yes it works. Here is an example code:

SuperStrict

Import MaxGui.Drivers
Global Window:TGadget = CreateWindow( "SetRenderImage Demo", 100, 100, 900, 600, Null )
Global Canvas:TGadget = CreateCanvas(100,5,775,590, Window)
Global Render:TRenderImage = CreateRenderImage(320, 200, False)
Global i:Int
ManipulateImage
CreateTimer 60
Repeat
WaitEvent()
Select EventID()
Case EVENT_WINDOWCLOSE
End
Case EVENT_TIMERTICK
DrawAll
If i Mod 60 =0 Then ManipulateImage
End Select
Forever

Function DrawAll()
I:+1
SetGraphics CanvasGraphics(Canvas)
SetClsColor 111,111,231
Cls
    DrawImage Render, i, 100
Flip
End Function


Function ManipulateImage()
SetGraphics CanvasGraphics(Canvas)
SetClsColor 200,255,200
SetRenderImage Render
Cls
SetColor 1,1,1
DrawText Rand(12345,23456),100,100
SetRenderImage Null
SetColor 255,255,255
End Function 

Of course this will also work without MaxGui. Here is a minimalistic example:

SuperStrict
Graphics 800,600
Global Render:TRenderImage = CreateRenderImage(320, 200, False)
Global i:Int
ManipulateImage

Repeat
I:+1
SetClsColor 111,111,231
Cls
    DrawImage Render, i, 100
Flip 1

If i Mod 60 =0 Then ManipulateImage

Until AppTerminate()

Function ManipulateImage()
SetClsColor 200,255,200
SetRenderImage Render
Cls
SetColor 1,1,1
DrawText Rand(12345,23456),100,100
SetRenderImage Null
SetColor 255,255,255
End Function

Title: Re: RenderImage() together with MaxGui
Post by: Dabzy on Aug 30, 2025, 09:41 AM
Yep, render targets are really handy things, which is what I liked about Blitz's old school "image buffers", you could just swap the drawing buffer from the back buffer to an image buffer and bingo.

Dabz