Carp/examples/fonts.carp

28 lines
1016 B
Plaintext
Raw Normal View History

(load "SDL.carp")
(load "SDL_ttf.carp")
(def font (the (Ptr TTF_Font) NULL))
(def texture (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)
(SDL.render-copy rend
texture
(address (SDL.dimensions texture))
(address (SDL.rect 100 100 300 300)))
))
(defn main []
(let [app (SDLApp.create "Font Rendering with SDL_ttf" 800 600)
rend @(SDLApp.renderer &app)]
(do
(if (= 0 (TTF.init))
(do
(set! font (TTF.open-font (cstr "resources/Hasklig.otf") 20))
(let [surface (TTF.render-text-solid font (cstr "Carp!") (SDL.color 0 0 0))]
(set! texture (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)))