Skip to content

Commit

Permalink
Refactor tutorial 03
Browse files Browse the repository at this point in the history
  • Loading branch information
TatriX committed Jul 16, 2021
1 parent 289f917 commit 1cec5d8
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions 03/tutorial-03.lisp
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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))))))

0 comments on commit 1cec5d8

Please sign in to comment.