diff --git a/14/tutorial-14.lisp b/14-animated-sprites-and-vsync.lisp similarity index 89% rename from 14/tutorial-14.lisp rename to 14-animated-sprites-and-vsync.lisp index 05def6b..428617a 100644 --- a/14/tutorial-14.lisp +++ b/14-animated-sprites-and-vsync.lisp @@ -1,8 +1,9 @@ -(defpackage #:sdl2-tutorial-14 - (:use :common-lisp) - (:export :main)) +(defpackage #:sdl2-tutorial-14-animated-sprites-and-vsync + (:use :cl) + (:export :run) + (:import-from :sdl2-tutorial-utils :asset-pathname)) -(in-package :sdl2-tutorial-14) +(in-package #:sdl2-tutorial-14-animated-sprites-and-vsync) (defparameter *screen-width* 640) (defparameter *screen-height* 480) @@ -54,7 +55,7 @@ (defmacro with-window-renderer ((window renderer) &body body) `(sdl2:with-init (:video) (sdl2:with-window (,window - :title "SDL2 Tutorial" + :title "SDL2 Tutorial 14" :w *screen-width* :h *screen-height* :flags '(:shown)) @@ -70,10 +71,10 @@ (defmacro clamp-decf (x delta) `(setf ,x (clamp (- ,x ,delta)))) -(defun main() +(defun run () (with-window-renderer (window renderer) (sdl2-image:init '(:png)) - (let ((spritesheet-tex (load-texture-from-file renderer "14/character.png")) + (let ((spritesheet-tex (load-texture-from-file renderer (asset-pathname "assets/14/character.png"))) (clip (sdl2:make-rect 0 0 64 96)) (sprite-frames 4) (current-sprite-frame 0) diff --git a/15/tutorial-15.lisp b/15-rotation-and-flipping.lisp similarity index 89% rename from 15/tutorial-15.lisp rename to 15-rotation-and-flipping.lisp index 99699a0..9d980e8 100644 --- a/15/tutorial-15.lisp +++ b/15-rotation-and-flipping.lisp @@ -1,8 +1,9 @@ -(defpackage #:sdl2-tutorial-15 - (:use :common-lisp) - (:export :main)) +(defpackage #:sdl2-tutorial-15-rotation-and-flipping + (:use :cl) + (:export :run) + (:import-from :sdl2-tutorial-utils :asset-pathname)) -(in-package :sdl2-tutorial-15) +(in-package #:sdl2-tutorial-15-rotation-and-flipping) (defparameter *screen-width* 640) (defparameter *screen-height* 480) @@ -51,17 +52,17 @@ (defmacro with-window-renderer ((window renderer) &body body) `(sdl2:with-init (:video) (sdl2:with-window (,window - :title "SDL2 Tutorial" + :title "SDL2 Tutorial 15" :w *screen-width* :h *screen-height* :flags '(:shown)) (sdl2:with-renderer (,renderer ,window :index -1 :flags '(:accelerated)) ,@body)))) -(defun main() +(defun run () (with-window-renderer (window renderer) (sdl2-image:init '(:png)) - (let ((texture (load-texture-from-file renderer "15/arrow.png")) + (let ((texture (load-texture-from-file renderer (asset-pathname "assets/15/arrow.png"))) (flip :none) (degrees 0) (delta 60)) diff --git a/16/tutorial-16.lisp b/16-true-type-fonts.lisp similarity index 83% rename from 16/tutorial-16.lisp rename to 16-true-type-fonts.lisp index 367933f..82d328d 100644 --- a/16/tutorial-16.lisp +++ b/16-true-type-fonts.lisp @@ -1,8 +1,9 @@ -(defpackage #:sdl2-tutorial-16 - (:use :common-lisp) - (:export :main)) +(defpackage #:sdl2-tutorial-16-true-type-fonts + (:use :cl) + (:export :run) + (:import-from :sdl2-tutorial-utils :asset-pathname)) -(in-package :sdl2-tutorial-16) +(in-package #:sdl2-tutorial-16-true-type-fonts) (defparameter *screen-width* 640) (defparameter *screen-height* 480) @@ -23,6 +24,10 @@ :accessor tex-texture :initform nil))) +(defun free-tex (tex) + (with-slots (texture) tex + (sdl2:destroy-texture texture))) + (defun load-texture-from-file (renderer filename) (let ((tex (make-instance 'tex :renderer renderer))) (with-slots (renderer texture width height) tex @@ -46,7 +51,7 @@ (defun set-color (tex r g b) (sdl2:set-texture-color-mod (tex-texture tex) r g b)) -(defun render (tex x y &key clip angle center flip) +(defun render (tex x y &key clip angle center (flip :none)) (with-slots (renderer texture width height) tex (sdl2:render-copy-ex renderer texture @@ -62,18 +67,18 @@ (defmacro with-window-renderer ((window renderer) &body body) `(sdl2:with-init (:video) (sdl2:with-window (,window - :title "SDL2 Tutorial" + :title "SDL2 Tutorial 16" :w *screen-width* :h *screen-height* :flags '(:shown)) (sdl2:with-renderer (,renderer ,window :index -1 :flags '(:accelerated)) ,@body)))) -(defun main() +(defun run () (with-window-renderer (window renderer) (sdl2-image:init '(:png)) (sdl2-ttf:init) - (setf *font* (sdl2-ttf:open-font "16/Pacifico.ttf" 28)) + (setf *font* (sdl2-ttf:open-font (asset-pathname "assets/16/Pacifico.ttf") 28)) (let ((texture (load-texture-from-text renderer "The quick brown fox jumps over the lazy dog"))) (sdl2:with-event-loop (:method :poll) (:quit () t) @@ -83,6 +88,8 @@ (render texture (round (/ (- *screen-width* (tex-width texture)) 2)) (round (/ (- *screen-height* (tex-height texture)) 2))) - (sdl2:render-present renderer)))) + (sdl2:render-present renderer))) + ;; clean up + (free-tex texture)) (sdl2-ttf:quit) (sdl2-image:quit))) diff --git a/14/character.png b/assets/14/character.png similarity index 100% rename from 14/character.png rename to assets/14/character.png diff --git a/15/arrow.png b/assets/15/arrow.png similarity index 100% rename from 15/arrow.png rename to assets/15/arrow.png diff --git a/16/Pacifico.ttf b/assets/16/Pacifico.ttf similarity index 100% rename from 16/Pacifico.ttf rename to assets/16/Pacifico.ttf diff --git a/sdl2-tutorial.asd b/sdl2-tutorial.asd index eecee57..7350e3a 100644 --- a/sdl2-tutorial.asd +++ b/sdl2-tutorial.asd @@ -18,9 +18,9 @@ (:file "11-clip-rendering-and-sprite-sheets") (:file "12-color-modulation") (:file "13-alpha-blending") - (:file "14/tutorial-14") - (:file "15/tutorial-15") - (:file "16/tutorial-16")) + (:file "14-animated-sprites-and-vsync") + (:file "15-rotation-and-flipping") + (:file "16-true-type-fonts")) :in-order-to ((test-op (test-op "sdl2-tutorial/tests"))))