diff options
author | Pierre-Antoine Rouby <contact@parouby.fr> | 2019-05-29 22:53:44 +0200 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2019-05-31 09:51:18 -0400 |
commit | faba3b60ca4d4e9d4545cb5d8511db02a332855f (patch) | |
tree | 335afa738e2cb9fa2a198b1575470f80fc2431fa | |
parent | e455ed5e2d41cb5f8c0f4d536f650a40a9cdc534 (diff) |
render: Add SDL_RenderDrawLines binding.
* sdl2/bindings.scm (sdl-render-draw-lines): New procedure.
* sdl2/render.scm (render-draw-lines): New procedure.
* doc/api.texi: Document it.
-rw-r--r-- | doc/api.texi | 5 | ||||
-rw-r--r-- | sdl2/bindings.scm | 3 | ||||
-rw-r--r-- | sdl2/render.scm | 16 |
3 files changed, 24 insertions, 0 deletions
diff --git a/doc/api.texi b/doc/api.texi index b692725..85d03b3 100644 --- a/doc/api.texi +++ b/doc/api.texi @@ -1061,6 +1061,11 @@ Draw a line from (@var{x1}, @var{y1}) to (@var{x2}, @var{y2}) on the current rendering target of @var{renderer}. @end deffn +@deffn {Procedure} render-draw-lines renderer point +Draw a series of connected lines from @var{points} on the current +rendering target of @var{renderer}. +@end deffn + @deffn {Procedure} render-draw-point renderer x y Draw a point at (@var{x}, @var{y}) on the current rendering target of @var{renderer}. diff --git a/sdl2/bindings.scm b/sdl2/bindings.scm index bf8db7a..900b641 100644 --- a/sdl2/bindings.scm +++ b/sdl2/bindings.scm @@ -252,6 +252,9 @@ RETURN-TYPE and accept arguments of ARG-TYPES." (define-foreign sdl-render-draw-line int "SDL_RenderDrawLine" (list '* int int int int)) +(define-foreign sdl-render-draw-lines + int "SDL_RenderDrawLines" (list '* '* int)) + (define-foreign sdl-render-draw-point int "SDL_RenderDrawPoint" (list '* int int)) diff --git a/sdl2/render.scm b/sdl2/render.scm index 326745f..0b92bc4 100644 --- a/sdl2/render.scm +++ b/sdl2/render.scm @@ -39,6 +39,7 @@ render-copy set-render-draw-color render-draw-line + render-draw-lines render-draw-point render-draw-points @@ -115,6 +116,21 @@ color." "Draw line on RENDERER." (ffi:sdl-render-draw-line (unwrap-renderer renderer) x1 y1 x2 y2)) +(define (render-draw-lines renderer points) + "Draw lines connecting POINTS on RENDERER." + (define (fill-bv bv l n) + (match l + (() bv) + (((x y) . r) + (s32vector-set! bv n x) + (s32vector-set! bv (+ n 1) y) + (fill-bv bv r (+ 2 n))))) + (let* ((count (length points)) + (bv (fill-bv (make-s32vector (* count 2)) points 0))) + (ffi:sdl-render-draw-lines (unwrap-renderer renderer) + (bytevector->pointer bv) + count))) + (define (render-draw-point renderer x y) "Draw point on RENDERER." (ffi:sdl-render-draw-point (unwrap-renderer renderer) x y)) |