Skip to content

Commit

Permalink
Refactor tutorial 02
Browse files Browse the repository at this point in the history
  • Loading branch information
TatriX committed Jul 13, 2021
1 parent 5ee5706 commit 289f917
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions 02/tutorial-02.lisp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(defpackage #:sdl2-tutorial-2
(:use :common-lisp)
(:export :main))
(defpackage #:sdl2-tutorial-02
(:use :cl)
(:export :run))

(in-package :sdl2-tutorial-2)
(in-package :sdl2-tutorial-02)

(defparameter *screen-width* 640)
(defparameter *screen-height* 480)
Expand All @@ -17,14 +17,18 @@
(let ((,surface (sdl2:get-window-surface ,window)))
,@body))))

(defun main(&key (delay 2000))
(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)
(sdl2:blit-surface (sdl2:load-bmp "2/hello_world.bmp")
nil
screen-surface
nil)
(sdl2:update-window window)
(sdl2:with-event-loop (:method :poll)
(:quit () t)
(:idle ()
(sdl2:delay delay)))))
(let ((image (load-image #p"./02/hello_world.bmp")))
(sdl2:blit-surface image nil screen-surface nil)
(sdl2:update-window window)
(sdl2:delay 2000)
;; clean up
(sdl2:free-surface image))))

0 comments on commit 289f917

Please sign in to comment.