diff --git a/03/tutorial-03.lisp b/03/tutorial-03.lisp index 17d6354..b7a7c2e 100644 --- a/03/tutorial-03.lisp +++ b/03/tutorial-03.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl2-tutorial-3 +(defpackage #:sdl2-tutorial-03 (:use :common-lisp) (:export :main)) -(in-package :sdl2-tutorial-3) +(in-package :sdl2-tutorial-03) (defparameter *screen-width* 640) (defparameter *screen-height* 480) @@ -17,12 +17,20 @@ (let ((,surface (sdl2:get-window-surface ,window))) ,@body)))) -(defun main() +(defun load-image (pathname) + (let* ((fullpath (merge-pathnames pathname (asdf:system-source-directory :sdl2-tutorial))) + (image (sdl2:load-bmp fullpath))) + (if (autowrap:wrapper-null-p image) + (error "cannot load image ~a (check that file exists)" fullpath) + image))) + +(defun run () (with-window-surface (window screen-surface) - (let ((image (sdl2:load-bmp "3/exit.bmp"))) + (let ((image (load-image "./03/exit.bmp"))) (sdl2:with-event-loop (:method :poll) (:quit () t) (:idle () (sdl2:blit-surface image nil screen-surface nil) (sdl2:update-window window) - (sdl2:delay 100)))))) ;reduce cpu usage + ;; reduce cpu usage + (sdl2:delay 100))))))