2023-12-12 03:37:17 +00:00
|
|
|
; LIBGL_ALWAYS_INDIRECT=1
|
2023-12-01 01:10:16 +00:00
|
|
|
(local fennel (require :fennel))
|
2023-12-12 03:37:17 +00:00
|
|
|
(import-macros {: def : q : ttype : static : eval : printform} :terra)
|
2023-12-09 19:35:04 +00:00
|
|
|
(local SDL (require :SDL))
|
2023-12-03 16:49:11 +00:00
|
|
|
|
2023-12-12 03:37:17 +00:00
|
|
|
(local CreateWindowAndRenderer (def [w int h int flags uint32]
|
2023-12-09 19:35:04 +00:00
|
|
|
(var window [SDL.Window] nil)
|
|
|
|
(var renderer [SDL.Renderer] nil)
|
|
|
|
(var result (SDL.CreateWindowAndRenderer w h flags (& window) (& renderer)))
|
2023-12-12 03:37:17 +00:00
|
|
|
(return result window renderer)))
|
2023-12-05 03:47:59 +00:00
|
|
|
|
2023-12-30 17:04:47 +00:00
|
|
|
(local clear (static (def [renderer [SDL.Renderer]]
|
|
|
|
(SDL.SetRenderDrawColor renderer 0 0 0 255)
|
|
|
|
(SDL.RenderClear renderer))))
|
|
|
|
|
|
|
|
(local hello (def [renderer [SDL.Renderer]]
|
|
|
|
(clear renderer)
|
|
|
|
(SDL.SetRenderDrawColor renderer 0 0 255 255)
|
|
|
|
(var rect (SDL.Rect {x 100 y 100 w 50 h 30}))
|
|
|
|
(SDL.RenderFillRect renderer (& rect))
|
|
|
|
(SDL.RenderPresent renderer)))
|
|
|
|
|
|
|
|
(local last-event (printform (static (q (SDL.Event {type 0})))))
|
2023-12-12 03:37:17 +00:00
|
|
|
(fn event-loop [f]
|
|
|
|
(while (not= (SDL.PollEvent (last-event:getpointer)) 0) (f (last-event:get))))
|
|
|
|
|
|
|
|
(local rect (def [x int y int w int h int]
|
|
|
|
(return (SDL.Rect {x x y y w w h h}))))
|
2023-12-09 19:35:04 +00:00
|
|
|
|
2023-12-30 17:04:47 +00:00
|
|
|
(fn patch-clear [r g b]
|
|
|
|
(let [new-clear (def [renderer [SDL.Renderer]]
|
|
|
|
(SDL.SetRenderDrawColor renderer r g b 255)
|
|
|
|
(SDL.RenderClear renderer))]
|
|
|
|
((def [] (set clear new-clear))))) ; no idea why (clear:set new-clear) doesn't work
|
|
|
|
|
2023-12-09 19:35:04 +00:00
|
|
|
(SDL.Init SDL.INIT_EVERYTHING)
|
2023-12-12 03:37:17 +00:00
|
|
|
(let [windowflags SDL.WINDOW_RESIZABLE
|
|
|
|
(ok window renderer) (unpacktuple (CreateWindowAndRenderer 640 480 windowflags))]
|
2023-12-30 17:04:47 +00:00
|
|
|
(event-loop #nil)
|
|
|
|
(hello renderer)
|
|
|
|
{: window : renderer : rect : event-loop : clear : hello : patch-clear})
|