Skip to content

Instantly share code, notes, and snippets.

@lockie
Last active February 3, 2023 12:25
Show Gist options
  • Save lockie/62865d0ffddea135caefe567ccebd518 to your computer and use it in GitHub Desktop.
Save lockie/62865d0ffddea135caefe567ccebd518 to your computer and use it in GitHub Desktop.
(use-modules (ice-9 threads)
(sdl2)
(sdl2 events)
(sdl2 rect)
(sdl2 render)
(sdl2 video))
(define window-width 640)
(define window-height 480)
(define (draw ren)
"Draws the window"
(clear-renderer ren)
(set-renderer-draw-color! ren 0 255 0 0)
(render-fill-rect ren (make-rect 0 0 window-width window-height))
(present-renderer ren))
(define (need-quit?)
"#t if main window was closed, #f otherwise"
(let ([event (poll-event)])
(if event
(quit-event? event)
#f)))
(define (main-loop ren)
"Main application loop"
(draw ren)
(unless (need-quit?)
(main-loop ren)))
(define (main)
"Application entry point"
(sdl-init)
(call-with-window (make-window #:title "Test"
#:size (list window-width window-height))
(lambda (window)
(call-with-renderer (make-renderer window)
main-loop)))
(sdl-quit))
(call-with-new-thread main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment