Add graphics-context class for managing SDL2 resources

This commit is contained in:
Camden Dixie O'Brien 2025-05-29 01:14:30 +01:00
parent 24df86fa44
commit 5ce814867d

View File

@ -63,3 +63,25 @@
(defun overlay (&rest drawings)
(apply #'append drawings))
(defclass graphics-context ()
(window
renderer
(width :initarg :width :initform 800)
(height :initarg :height :initform 600)))
(defmethod initialize-instance :after ((ctx graphics-context) &key)
(with-slots (window renderer width height) ctx
(sdl2:init)
(setf window
(sdl2:create-window :title "Simulation"
:w width :h height
:flags '(:shown)))
(setf renderer
(sdl2:create-renderer window -1 '(:accelerated :presentvsync)))))
(defmethod cleanup ((ctx graphics-context))
(with-slots (window renderer) ctx
(sdl2:destroy-renderer renderer)
(sdl2:destroy-window window)
(sdl2:quit)))