Skip to content

Instantly share code, notes, and snippets.

@fouric
Last active August 9, 2018 00:45
Show Gist options
  • Save fouric/b48c09ac7ea9b63ac42253e9ad9d1f75 to your computer and use it in GitHub Desktop.
Save fouric/b48c09ac7ea9b63ac42253e9ad9d1f75 to your computer and use it in GitHub Desktop.
(proclaim '(optimize (speed 0) (safety 0) (space 0) (debug 3)))
(eval-when (:compile-toplevel)
(ql:quickload :sdl2)
(ql:quickload :sdl2-ttf))
(let ((rect (sdl2:make-rect 0 0 0 0)))
(defun render-rectangle (renderer x y w h r g b &optional (filled t))
;; NOT thread-safe!
(plus-c:c-let ((rect sdl2-ffi:sdl-rect :from rect))
(setf (rect :x) x
(rect :y) y
(rect :w) w
(rect :h) h))
(sdl2:set-render-draw-color renderer r g b 255)
(if filled
(sdl2:render-fill-rect renderer rect)
(sdl2:render-draw-rect renderer rect))))
(defun graygoo ()
(let* ((window-width 640)
(window-height 480))
(sdl2:with-init (:everything)
(sdl2-ttf:init)
(sdl2:with-window (window :w window-width :h window-height)
(sdl2:with-renderer (renderer window :flags '(:accelerated :presentvsync))
(sdl2:with-event-loop (:method :poll)
(:keydown (:keysym keysym)
(let ((scancode (sdl2:scancode-value keysym))
(sym (sdl2:sym-value keysym))
(mod-value (sdl2:mod-value keysym)))
(cond
((sdl2:scancode= scancode :scancode-q) (sdl2:push-event :quit))
((sdl2:scancode= scancode :scancode-s) (sdl2:show-cursor))
((sdl2:scancode= scancode :scancode-h) (sdl2:hide-cursor)))
(format t "Key sym: ~a, code: ~a, mod: ~a~%"
sym
scancode
mod-value)))
(:mousemotion (:x x :y y)
(print (cons x y)))
(:idle ()
(sdl2:set-render-draw-color renderer 0 0 0 255)
(sdl2:render-clear renderer)
(render-rectangle renderer 10 20 50 50 200 0 0)
(sdl2:render-present renderer))
(:quit ()
t)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment