# SDL_gfx API

## Slava Pestov — 2004-10-17 23:35:48

    Hi all,

    the SDL_gfx API, for which a partial binding exists in Factor 0.67, can

    be used to render simple geometric shapes.

    Right now it is not optimal since the surface object and x/y co-ordinate

    must be passed on the stack to each call. I'll be working on a 'turtle

    graphics' API for the next release, where instead one moves a pen, and

    the surface is taken from the scope of the [ ... ] with-surface combinator.

    Here is some code:

    ----------->8-----------

    IN: sdl-gfx-test

    USE: alien

    USE: combinators

    USE: errors

    USE: kernel

    USE: lists

    USE: logic

    USE: math

    USE: namespaces

    USE: sdl

    USE: stack

    USE: vectors

    USE: prettyprint

    USE: stdio

    USE: test

    : render ( -- )

         surface get 10 10 255 0 0 255 pack-rgba pixelColor

         surface get 10 100 10 255 0 0 255 pack-rgba hlineColor

         surface get 10 10 100 255 0 0 255 pack-rgba vlineColor

         surface get 50 40 120 300 255 255 0 255 pack-rgba rectangleColor

         surface get 55 45 125 305 255 0 255 255 pack-rgba boxColor

         surface get 0 0 640 480 255 0 255 200 pack-rgba lineColor

         surface get 0 640 640 0 255 0 255 200 pack-rgba aalineColor

         surface get 320 200 50 255 120 120 200 pack-rgba circleColor

         surface get 300 220 50 30 255 250 120 200 pack-rgba ellipseColor

         surface get 300 220 40 20 255 120 120 200 pack-rgba filledEllipseColor

         surface get 200 200 50 4 50 0 244 0 255 pack-rgba filledPieColor

         surface get 30 30 "HELLO WORLD" 255 255 255 255 pack-rgba stringColor

         surface get 100 100 150 100 100 150 120 120 120 255 pack-rgba

    trigonColor

         surface get 200 100 150 170 100 150 120 120 120 255 pack-rgba

    aatrigonColor

         surface get 200 100 150 170 100 150 120 120 120 255 pack-rgba

    filledTrigonColor

         ;

    : gfx-test ( -- )

         640 480 32 SDL_HWSURFACE SDL_SetVideoMode drop

         [

             render

         ] with-surface

         <event> event-loop

         SDL_Quit ;

    gfx-test

    -------------->8-------------