SDL Tutorial 1

Zach Kost-Smith edited this page May 16, 2013 · 4 revisions

Introduction

The CLinch graphics engine is meant to be a simpler alternative for 2 and 3 dimensional graphics development in Lisp. It is meant to only be a graphics engine so it doesn't contain any windowing libraries or game asset importers, etc. This is by design, in order to make CLinch more useful to a wide array of developers. It currently requires OpenGL (through CL-OpenGL). It also includes binders for the Cairo Vector Graphics Library, Pango Test Layout Engine, and FreeImage File Format Read/Write Library.

For these tutorials, you will need a implementation of Common Lisp. I recommend SBCL, as that is what I use. You can find it here. I will also be using QuickLisp, a wonderful package management tool. Follow these instructions, if you don't already have it. Next you will need CL-OpenGL and Lispbuilder-SDL. To install these, start up an REPL and use quicklisp:quickload to install them as follows:

(quicklisp:quickload :cl-opengl)
(quicklisp:quickload :lispbuilder-sdl)

Finally, go to your "~/quicklisp/local-projects/" directory (this will be different in windows) and type:

git clone http://github.com/BradWBeer/CLinch.git

This should create a directory named "CLinch". Quicklisp looks in "local-projects" automatically, so this will let you 'quickload' CLinch the same as the other packages. If you don't have git, you can find it here. In you slime session load CLinch with the following to verify everything works:

(quicklisp:quickload :clinch)

Congratulations, you're system should be setup properly for CLinch.

Creating a Window

In order to creating a window, we need to load up our windowing library Lispbuilder-SDL and CLinch. So open up a new file (I named my "sdl-tutorial01.lisp") and add the following lines:

(ql:quickload :lispbuilder-sdl)
(ql:quickload :clinch)

Now we need some placeholder functions for initialization, clean-up and the main loop:

(defun init ()
  )

(defun main-loop ()
  )

(defun clean-up ()
  )

Finally, we can add the start function. This will create the window and call the various functions we defined. It doesn't seem like it does much, but creating an OpenGL window is a tedious task and this can almost be done from memory.

(defun start ()
  (sdl:with-init ()
    (sdl:window 400 300
                :flags sdl-cffi::sdl-opengl
	    :resizable t
	    :double-buffer t
	    :title-caption "Tutorial 1"
	    :icon-caption "Tutorial 1")
    (init)
    (setf (sdl:frame-rate) 60)
    (sdl:with-events ()
      (:quit-event () t)
      (:idle ()         
         (main-loop)
         (sdl:update-display)))
    (clean-up)))

Save, load the file and run (start). You should see a black window with the title "Tutorial 1". Hopefully it was fairly easy. In the [next tutorial](SDL Tutorial 2) we will make some simple shapes!

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.