From 8efaa281657343ec166f645bd861577be1dd8237 Mon Sep 17 00:00:00 2001 From: TatriX Date: Mon, 19 Jul 2021 23:42:54 +0200 Subject: [PATCH] Refactor tutorial 07 --- ...p => 07-texture-loading-and-rendering.lisp | 21 +++++++++--------- {07 => assets/07}/texture.png | Bin sdl2-tutorial.asd | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) rename 07/tutorial-07.lisp => 07-texture-loading-and-rendering.lisp (59%) rename {07 => assets/07}/texture.png (100%) diff --git a/07/tutorial-07.lisp b/07-texture-loading-and-rendering.lisp similarity index 59% rename from 07/tutorial-07.lisp rename to 07-texture-loading-and-rendering.lisp index 833491c..cd761ee 100644 --- a/07/tutorial-07.lisp +++ b/07-texture-loading-and-rendering.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl2-tutorial-7 - (:use :common-lisp) - (:export :main)) +(defpackage #:sdl2-tutorial-07-texture-loading-and-rendering + (:use :cl) + (:export :run)) -(in-package :sdl2-tutorial-7) +(in-package :sdl2-tutorial-07-texture-loading-and-rendering) (defparameter *screen-width* 640) (defparameter *screen-height* 480) @@ -10,21 +10,22 @@ (defmacro with-window-renderer ((window renderer) &body body) `(sdl2:with-init (:video) (sdl2:with-window (,window - :title "SDL2 Tutorial" + :title "SDL2 Tutorial 07" :w *screen-width* :h *screen-height* :flags '(:shown)) (sdl2:with-renderer (,renderer ,window :index -1 :flags '(:accelerated)) - ,@body)))) + ,@body)))) -(defun load-texture (renderer filename) - (sdl2:create-texture-from-surface renderer (sdl2-image:load-image filename))) +(defun load-texture (renderer pathname) + (let ((fullpath (merge-pathnames pathname (asdf:system-source-directory :sdl2-tutorial)))) + (sdl2:create-texture-from-surface renderer (sdl2-image:load-image fullpath)))) -(defun main() +(defun run() (with-window-renderer (window renderer) (sdl2-image:init '(:png)) (sdl2:set-render-draw-color renderer #xFF #xFF #xFF #xFF) - (let ((texture (load-texture renderer "7/texture.png"))) + (let ((texture (load-texture renderer "assets/07/texture.png"))) (sdl2:with-event-loop (:method :poll) (:quit () t) (:idle () diff --git a/07/texture.png b/assets/07/texture.png similarity index 100% rename from 07/texture.png rename to assets/07/texture.png diff --git a/sdl2-tutorial.asd b/sdl2-tutorial.asd index 14c45e0..f89bcd8 100644 --- a/sdl2-tutorial.asd +++ b/sdl2-tutorial.asd @@ -8,8 +8,8 @@ (:file "03-event-driven-programming") (:file "04-key-presses") (:file "05-optimized-surface-loading-and-soft-stretching") - (:file "06-extension-libraries-and-loading-other-image-formats.lisp ") - (:file "07/tutorial-07") + (:file "06-extension-libraries-and-loading-other-image-formats.lisp") + (:file "07-texture-loading-and-rendering.lisp") (:file "08/tutorial-08") (:file "09/tutorial-09") (:file "10/tutorial-10")