From fedd9bca3d6397e22e5400e8653879bb77bbff2e Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 17 Jan 2018 12:01:41 -0500 Subject: render: Refactor sprite rendering. * chickadee/render/texture.scm (): Delete type. ()[width, height, gl-size]: Delete fields. [parent, rect, gl-rect]: Add fields. (texture-region?): Rewrite. (make-texture, null-texture): Use new texture constructor. (make-texture-region): Rewrite in terms of type. (list->texture-atlas, split-texture): Use new texture region constructor. * chickadee/render/sprite.scm (draw-sprite*): New procedure. (draw-sprite): Rewrite in terms of draw-sprite*. (draw-nine-patch*): New procedure. (draw-nine-patch): Rewrite in terms of draw-nine-patch*. * chickadee/render/font.scm (draw-text*): New procedure. (draw-text): Rewrite in terms of draw-text*. * doc/api.texi: Update draw-sprite, draw-nine-patch, and draw-text docs. --- doc/api.texi | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'doc/api.texi') diff --git a/doc/api.texi b/doc/api.texi index cb3c885..e2864a5 100644 --- a/doc/api.texi +++ b/doc/api.texi @@ -681,10 +681,26 @@ players, NPCs, items, particles, text, etc. In Chickadee, bitmaps are stored in textures (@pxref{Textures}) and can be used to draw sprites via the @code{draw-sprite} procedure. -@deffn {Procedure} draw-sprite @var{texture} @var{region} @ - [#:scale] [#:rotation] [#:blend-mode alpha] [#:texcoords] @ - [#:shader] +@deffn {Procedure} draw-sprite @var{texture} @var{position} @ + [#:origin] [#:scale] [#:rotation] [#:blend-mode alpha] @ + [#:rect] [#:shader] + +Draw @var{texture} at @var{position}. + +Optionally, other transformations may be applied to the sprite. +@var{rotation} specifies the angle to rotate the sprite, in radians. +@var{scale} specifies the scaling factor as a 2D vector. All +transformations are applied relative to @var{origin}, a 2D vector, +which defaults to the lower-left corner. + +Alpha blending is used by default but the blending method can be +changed by specifying @var{blend-mode}. + +The area drawn to is as big as the texture, by default. To draw to an +arbitrary section of the screen, specify @var{rect}. +Finally, advanced users may specify @var{shader} to change the way the +sprite is rendered entirely. @end deffn It's not uncommon to need to draw hundreds or thousands of sprites @@ -740,10 +756,10 @@ interface widgets like buttons and dialog boxes. By using a nine patch, they can be rendered at any size without unappealing scaling artifacts. -@deffn {Procedure} draw-nine-patch @var{texture} @var{region} @ +@deffn {Procedure} draw-nine-patch @var{texture} @var{rect} @ [#:margin 0] [#:top-margin margin] [#:bottom-margin margin] @ [#:left-margin margin] [#:right-margin margin] @ - [#:texture-region] [#:scale] [#:rotation] [#:blend-mode alpha] @ + [#:origin] [#:scale] [#:rotation] [#:blend-mode alpha] @ [#:shader] Draw a nine patch sprite. A nine patch sprite renders @var{texture} @@ -809,9 +825,7 @@ rendering technique comes in. Introduced by @url{http://www.valvesoftware.com/.../2007/SIGGRAPH2007_AlphaTestedMagnification.pdf, Valve} in 2007, signed distance field fonts can be efficiently stored in a bitmap and be rendered at arbitrary scale factors with good -results. Chickadee can render both traditional bitmap fonts and -signed distance field fonts. @emph{Signed distance field font -rendering is not yet available, so be patient.} +results. While Chickadee does not yet offer a tool for converting TTF fonts into FNT fonts, tools such as @@ -851,7 +865,7 @@ Return @code{#t} if @var{font} is an italicized font. @end deffn @deffn {Procedure} draw-text @var{font} @var{text} @var{position} - [#:scale] [#:rotation] [#:blend-mode] + [#:origin] [#:scale] [#:rotation] [#:blend-mode] Draw the string @var{text} with the first character starting at @var{position} using @var{font}. -- cgit v1.2.3