Skip to content

Instantly share code, notes, and snippets.

@RednibCoding
Created April 20, 2025 19:44
Show Gist options
  • Save RednibCoding/339463eae6cd98e673343f73b41a4dcb to your computer and use it in GitHub Desktop.
Save RednibCoding/339463eae6cd98e673343f73b41a4dcb to your computer and use it in GitHub Desktop.
BlitzMax Resizable Window
SuperStrict
Framework Brl.StandardIO
Import SDL.SDLRenderMax2D
Import Brl.pngloader ' If you need to load PNGs
Import Brl.Retro
Import Brl.Map
Global windowWidth:Int = 800
Global windowHeight:Int = 600
AppTitle = "Resizable Window"
Graphics(windowWidth, windowHeight, 0, 0, SDL_WINDOW_RESIZABLE)
AddHook(EmitEventHook, WindowResizedHook, Null, -10000)
Repeat
Cls()
' === Render Your Game Here
DrawText("Hello World", windowWidth-100, windowHeight-25)
Flip(1)
Until AppTerminate()
' Resize Callback to resize the canvas when the window size changes
Function WindowResizedHook:Object( id:Int, data:Object,context:Object )
Local ev:TEvent=TEvent( data )
If Not ev Return Null
If ev.id <> EVENT_WINDOWSIZE Then Return Null
Local driver:TSDLRenderMax2DDriver = TSDLRenderMax2DDriver(brl.max2d._max2dDriver)
If driver
Local outputW:Int, outputH:Int
driver.renderer.GetOutputSize(outputW, outputH)
If outputW <> windowHeight Or outputH <> windowHeight
driver.renderer.SetLogicalSize(outputW, outputH)
SetViewport(0,0, outputW, outputH)
windowWidth = outputW
windowHeight = outputH
EndIf
EndIf
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment