Carp/examples/fonts.carp

27 lines
1.1 KiB
Plaintext
Raw Normal View History

(load "SDL.carp")
(load "SDL_ttf.carp")
2018-03-22 15:36:16 +03:00
(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)
2018-03-22 15:36:16 +03:00
(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 []
2018-03-22 15:36:16 +03:00
(let [app (SDLApp.create "Font Rendering with SDL_ttf" 400 300)
rend @(SDLApp.renderer &app)]
(do
(if (= 0 (TTF.init))
2018-03-22 15:36:16 +03:00
(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)))