Skip to content

Commit

Permalink
Refactor tutorial 06
Browse files Browse the repository at this point in the history
  • Loading branch information
TatriX committed Jul 18, 2021
1 parent 15c80ef commit 87170a2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
(defpackage #:sdl2-tutorial-6
(:use :common-lisp)
(:export :main))
(defpackage #:sdl2-tutorial-06-extension-libraries-and-loading-other-image-formats
(:use :cl)
(:export :run))

(in-package :sdl2-tutorial-6)
(in-package :sdl2-tutorial-06-extension-libraries-and-loading-other-image-formats)

(defparameter *screen-width* 640)
(defparameter *screen-height* 480)

(defmacro with-window-surface ((window surface) &body body)
`(sdl2:with-init (:video)
(sdl2:with-window (,window
:title "SDL2 Tutorial"
:title "SDL2 Tutorial 06"
:w *screen-width*
:h *screen-height*
:flags '(:shown))
(let ((,surface (sdl2:get-window-surface ,window)))
,@body))))
(sdl2-image:init '(:png))
,@body
(sdl2-image:quit)))))

(defun load-surface (filename &optional pixel-format)
(sdl2:convert-surface-format (sdl2-image:load-image filename) pixel-format))
(defun load-surface (pathname pixel-format)
(let ((fullpath (merge-pathnames pathname (asdf:system-source-directory :sdl2-tutorial))))
(sdl2:convert-surface-format (sdl2-image:load-image fullpath) pixel-format)))

(defun main()
(defun run ()
(with-window-surface (window screen-surface)
(sdl2-image:init '(:png))
(let ((image-surface (load-surface "6/loaded.png" (sdl2:surface-format-format screen-surface)))
(let ((image-surface (load-surface "assets/06/loaded.png" (sdl2:surface-format-format screen-surface)))
(rect (sdl2:make-rect 0 0 *screen-width* *screen-height*)))
(sdl2:with-event-loop (:method :poll)
(:quit () t)
Expand Down
Binary file removed 06/loaded.png
Binary file not shown.
Binary file added assets/06/loaded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion sdl2-tutorial.asd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(:file "03-event-driven-programming")
(:file "04-key-presses")
(:file "05-optimized-surface-loading-and-soft-stretching")
(:file "06/tutorial-06")
(:file "06-extension-libraries-and-loading-other-image-formats.lisp ")
(:file "07/tutorial-07")
(:file "08/tutorial-08")
(:file "09/tutorial-09")
Expand Down

0 comments on commit 87170a2

Please sign in to comment.