diff --git a/1/main.lisp b/1/main.lisp index 98d4bf8..7be644b 100644 --- a/1/main.lisp +++ b/1/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-1 +(defpackage #:sdl2-tutorial-1 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-1) +(in-package :sdl2-tutorial-1) (defparameter *screen-width* 640) (defparameter *screen-height* 480) @@ -15,4 +15,7 @@ nil (sdl2:map-rgb (sdl2:surface-format screen-surface) 255 255 255)) (sdl2:update-window window) - (sdl2:delay delay))))) + (sdl2:with-event-loop (:method :poll) + (:quit () t) + (:idle () + (sdl2:delay delay))))))) diff --git a/10/main.lisp b/10/main.lisp index 3b29dee..4c9d341 100644 --- a/10/main.lisp +++ b/10/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-10 +(defpackage #:sdl2-tutorial-10 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-10) +(in-package :sdl2-tutorial-10) (defparameter *screen-width* 640) (defparameter *screen-height* 480) diff --git a/11/main.lisp b/11/main.lisp index 42a1db0..d4ff3f8 100644 --- a/11/main.lisp +++ b/11/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-11 +(defpackage #:sdl2-tutorial-11 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-11) +(in-package :sdl2-tutorial-11) (defparameter *screen-width* 640) (defparameter *screen-height* 480) diff --git a/12/main.lisp b/12/main.lisp index 77ce6aa..d6c803f 100644 --- a/12/main.lisp +++ b/12/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-12 +(defpackage #:sdl2-tutorial-12 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-12) +(in-package :sdl2-tutorial-12) (defparameter *screen-width* 640) (defparameter *screen-height* 480) diff --git a/13/main.lisp b/13/main.lisp index 4d20537..0f62a18 100644 --- a/13/main.lisp +++ b/13/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-13 +(defpackage #:sdl2-tutorial-13 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-13) +(in-package :sdl2-tutorial-13) (defparameter *screen-width* 640) (defparameter *screen-height* 480) diff --git a/14/main.lisp b/14/main.lisp index e84642b..05def6b 100644 --- a/14/main.lisp +++ b/14/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-14 +(defpackage #:sdl2-tutorial-14 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-14) +(in-package :sdl2-tutorial-14) (defparameter *screen-width* 640) (defparameter *screen-height* 480) diff --git a/15/main.lisp b/15/main.lisp index 80844cf..99699a0 100644 --- a/15/main.lisp +++ b/15/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-15 +(defpackage #:sdl2-tutorial-15 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-15) +(in-package :sdl2-tutorial-15) (defparameter *screen-width* 640) (defparameter *screen-height* 480) @@ -62,7 +62,7 @@ (with-window-renderer (window renderer) (sdl2-image:init '(:png)) (let ((texture (load-texture-from-file renderer "15/arrow.png")) - (flip :flip-none) + (flip :none) (degrees 0) (delta 60)) (sdl2:with-event-loop (:method :poll) diff --git a/16/main.lisp b/16/main.lisp index 806a918..367933f 100644 --- a/16/main.lisp +++ b/16/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-16 +(defpackage #:sdl2-tutorial-16 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-16) +(in-package :sdl2-tutorial-16) (defparameter *screen-width* 640) (defparameter *screen-height* 480) diff --git a/2/main.lisp b/2/main.lisp index c6a4d82..411891f 100644 --- a/2/main.lisp +++ b/2/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-2 +(defpackage #:sdl2-tutorial-2 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-2) +(in-package :sdl2-tutorial-2) (defparameter *screen-width* 640) (defparameter *screen-height* 480) @@ -24,5 +24,7 @@ screen-surface nil) (sdl2:update-window window) - (sdl2:delay delay))) - + (sdl2:with-event-loop (:method :poll) + (:quit () t) + (:idle () + (sdl2:delay delay))))) diff --git a/3/main.lisp b/3/main.lisp index 5964512..17d6354 100644 --- a/3/main.lisp +++ b/3/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-3 +(defpackage #:sdl2-tutorial-3 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-3) +(in-package :sdl2-tutorial-3) (defparameter *screen-width* 640) (defparameter *screen-height* 480) diff --git a/4/main.lisp b/4/main.lisp index 7a75bfb..8ca43c2 100644 --- a/4/main.lisp +++ b/4/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-4 +(defpackage #:sdl2-tutorial-4 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-4) +(in-package :sdl2-tutorial-4) (defparameter *screen-width* 640) (defparameter *screen-height* 480) diff --git a/5/main.lisp b/5/main.lisp index f855a88..34fd608 100644 --- a/5/main.lisp +++ b/5/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-5 +(defpackage #:sdl2-tutorial-5 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-5) +(in-package :sdl2-tutorial-5) (defparameter *screen-width* 640) (defparameter *screen-height* 480) diff --git a/6/main.lisp b/6/main.lisp index 277451a..d19a729 100644 --- a/6/main.lisp +++ b/6/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-6 +(defpackage #:sdl2-tutorial-6 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-6) +(in-package :sdl2-tutorial-6) (defparameter *screen-width* 640) (defparameter *screen-height* 480) diff --git a/7/main.lisp b/7/main.lisp index 78c0b73..833491c 100644 --- a/7/main.lisp +++ b/7/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-7 +(defpackage #:sdl2-tutorial-7 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-7) +(in-package :sdl2-tutorial-7) (defparameter *screen-width* 640) (defparameter *screen-height* 480) diff --git a/8/main.lisp b/8/main.lisp index 61770f8..47e4596 100644 --- a/8/main.lisp +++ b/8/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-8 +(defpackage #:sdl2-tutorial-8 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-8) +(in-package :sdl2-tutorial-8) (defparameter *screen-width* 640) (defparameter *screen-height* 480) diff --git a/9/main.lisp b/9/main.lisp index 9ea7205..c640ac7 100644 --- a/9/main.lisp +++ b/9/main.lisp @@ -1,8 +1,8 @@ -(defpackage #:sdl-tutorial-9 +(defpackage #:sdl2-tutorial-9 (:use :common-lisp) (:export :main)) -(in-package :sdl-tutorial-9) +(in-package :sdl2-tutorial-9) (defparameter *screen-width* 640) (defparameter *screen-height* 480) diff --git a/README.md b/README.md index 20856fd..62a10c1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,54 @@ # Common Lisp SDL2 tutorials Adapted from http://lazyfoo.net/tutorials/SDL/ + + +## Installing the SDL2 Libraries + + The tutorial requires that SDL2, SDL2 Image, and SDL2 TTF are installed before + running the examples. + +### Mac OS X + +Mac OS X requires each library to be downloaded and copied to +$HOME/Library/Frameworks or /Library/Frameworks. + + Library Name | Download Link + ------------ | ------------- + SDL2 | https://www.libsdl.org/download-2.0.php + SDL2 Image | https://www.libsdl.org/projects/SDL_image + SDL2 TTF | https://www.libsdl.org/projects/SDL_ttf + +Running the tutorials will cause Catalina to report that the framework cannot be +opened because the developer cannot be verified. The workaround for this problem +is the following: + +1. Navigate to System Preferences -> Security & Privacy -> General on the Mac + +2. Run repl.sh + +3. When the dialog appears about the developer not being verified, click the +"Cancel" button. + +4. Examine the Security & Privacy screen for a button called "Allow Anyway" for +the framework. Click the "Allow Anyway" button with the identified framework. + +5. The verification dialog will now appear a second time, but there will be an +option to "Open" the framework. Click "Open". + +6. Repeat steps 3 through 5 for the different frameworks. + +### Linux + +The SDL2 libraries can be installed on a Debian based system with the command +below. + + apt install libsdl2-2.0 libsdl2-image-2.0 libsdl2-ttf-2.0 + + +## Running the Examples + +A repl.sh script is provided that loads SDL2-TUTORIAL with quicklisp and then +starts up a swank thread on port 4005 for repl connections. + + 1. ./repl.sh + 2. (sdl2-tutorial:main #'sdl2-tutorial-1:main) diff --git a/repl.sh b/repl.sh new file mode 100755 index 0000000..1293363 --- /dev/null +++ b/repl.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +sbcl --eval "(ql:quickload \"sdl2-tutorial\")" \ + --eval "(sdl2-tutorial:create-swank-server)" diff --git a/sdl2-tutorial.asd b/sdl2-tutorial.asd new file mode 100644 index 0000000..f72be9c --- /dev/null +++ b/sdl2-tutorial.asd @@ -0,0 +1,22 @@ +(defsystem "sdl2-tutorial" + :description "SDL2 Tutorial based upon http://lazyfoo.net/tutorials/SDL" + :version "0.0.1" + :licence "Public Domain" + :depends-on ("bordeaux-threads" "sdl2" "sdl2-image" "sdl2-ttf" "swank") + :components ((:file "1/main") + (:file "2/main") + (:file "3/main") + (:file "4/main") + (:file "5/main") + (:file "6/main") + (:file "7/main") + (:file "8/main") + (:file "9/main") + (:file "10/main") + (:file "11/main") + (:file "12/main") + (:file "13/main") + (:file "14/main") + (:file "15/main") + (:file "16/main") + (:file "sdl2-tutorial"))) diff --git a/sdl2-tutorial.lisp b/sdl2-tutorial.lisp new file mode 100644 index 0000000..7346b9c --- /dev/null +++ b/sdl2-tutorial.lisp @@ -0,0 +1,11 @@ +(defpackage :sdl2-tutorial + (:use cl bt) + (:export :main :create-swank-server)) + +(in-package :sdl2-tutorial) + +(defun create-swank-server() + (bt:make-thread (lambda () (swank:create-server :port 4005 :dont-close t)))) + +(defun main(fn) + (sdl2:make-this-thread-main fn))