(load "SDL.carp") (load "SDL_ttf.carp") (def text1 (the (Ptr SDL_Texture) NULL)) (defn draw [app rend state-ref] (do (SDL.set-render-draw-color rend 240 240 220 255) (SDL.render-clear rend) (let [dims (SDL.dimensions text1) dest (SDL.rect (- 200 (/ @(SDL_Rect.w &dims) 2)) (- 150 @(SDL_Rect.h &dims)) @(SDL_Rect.w &dims) @(SDL_Rect.h &dims))] (SDL.render-copy rend text1 (address dims) (address dest))))) (defn main [] (let [app (SDLApp.create "Font Rendering with SDL_ttf" 400 300) rend @(SDLApp.renderer &app)] (do (if (= 0 (TTF.init)) (let-do [font (TTF.open-font (cstr "resources/Hasklig.otf") 20) surface (TTF.render-text-blended font (cstr "Carp!") (SDL.rgb 0 0 0))] (set! text1 (SDL.create-texture-from-surface rend surface)) (SDLApp.run-with-callbacks &app SDLApp.default-event-handler id draw 0)) (println* "Failed to initialize SDL_ttf: " &(str (TTF.get-error)))) 0)))