Browse Source

Add basic render drawing functions

Added:

  - ```render-clear```
  - ```set-render-draw-color```
  - ```render-draw-line```

And a new example demo.
main
James King 8 years ago
parent
commit
b2519d8dbe
  1. 1
      .gitignore
  2. 30
      examples/renderer.lisp
  3. 3
      sdl2.asd
  4. 5
      src/package.lisp
  5. 14
      src/render.lisp

1
.gitignore vendored

@ -1,5 +1,6 @@
*.fasl
*.lx??fsl
*.dx??fsl
src/sdl2-cffi.lisp
src/sdl2-macros.lisp
.plant/

30
examples/renderer.lisp

@ -0,0 +1,30 @@
(in-package :sdl2-examples)
(require :sdl2)
(require :cl-opengl)
(defun test-render-clear (renderer)
(progn (sdl2:set-render-draw-color renderer 0 0 0 255)
(sdl2:render-clear renderer)))
(defun test-render-line (renderer)
(progn (sdl2:set-render-draw-color renderer 255 0 0 255)
(sdl2:render-draw-line renderer 2 2 30 200)))
(defun renderer-test ()
"Test the SDL_render.h API"
(sdl2:with-init (:everything)
(sdl2:with-window (win :flags '(:shown))
(sdl2:with-renderer (renderer win :flags '(:renderer-accelerated))
(sdl2:with-event-loop (:method :poll)
(:keyup
(:keysym keysym)
(when (sdl2:scancode= (sdl2:scancode-value keysym) :scancode-escape)
(sdl2:push-event :quit)))
(:idle
()
(test-render-clear renderer)
(test-render-line renderer)
(sdl2:render-present renderer))
(:quit () t))))))

3
sdl2.asd

@ -50,4 +50,5 @@
:pathname "examples"
:serial t
:components ((:file "basic")))
:components ((:file "basic")
(:file "renderer")))

5
src/package.lisp

@ -138,6 +138,9 @@
#:union-rect
;; render.lisp
#:render-clear
#:render-draw-line
#:set-render-draw-color
#:render-copy
#:render-present
#:update-texture
@ -202,4 +205,4 @@
(defpackage #:sdl2-examples
(:use #:cl #:alexandria #:cffi)
(:export #:basic-test))
(:export #:basic-test #:renderer-test))

14
src/render.lisp

@ -1,7 +1,5 @@
(in-package :sdl2)
;;;; TODO
;;;; SDL_CreateWindowAndRenderer
;;;; SDL_GetRendererOutputSize
(defun make-renderer-info ()
@ -106,6 +104,18 @@ the SDL_Renderer structure."
"Use this function to copy a portion of the texture to the current rendering target."
(check-rc (sdl2-ffi.functions:sdl-render-copy renderer texture source-rect dest-rect)))
(defun set-render-draw-color (renderer r g b a)
"Use this function to set the color used for drawing operations (Rect, Line and Clear)."
(check-rc (sdl2-ffi.functions:sdl-set-render-draw-color renderer r g b a)))
(defun render-draw-line (renderer x1 y1 x2 y2)
"Use this function to draw a line on the current rendering target."
(check-rc (sdl2-ffi.functions:sdl-render-draw-line renderer x1 y1 x2 y2)))
(defun render-clear (renderer)
"Use this function to clear the current rendering target with the drawing color."
(check-rc (sdl2-ffi.functions:sdl-render-clear renderer)))
(defun render-present (renderer)
"Use this function to update the screen with rendering performed."
(sdl2-ffi.functions:sdl-render-present renderer))

Loading…
Cancel
Save