Skip to content

Commit

Permalink
Refactor tutorial 07
Browse files Browse the repository at this point in the history
  • Loading branch information
TatriX committed Jul 19, 2021
1 parent 87170a2 commit 8efaa28
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
21 changes: 11 additions & 10 deletions 07/tutorial-07.lisp → 07-texture-loading-and-rendering.lisp
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
(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)

(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 ()
Expand Down
File renamed without changes
4 changes: 2 additions & 2 deletions sdl2-tutorial.asd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 8efaa28

Please sign in to comment.