Carp/core/SDL_ttf.carp
Jorge Acereda 9b08b6df3c Merge
2020-05-11 16:10:35 +02:00

52 lines
1.6 KiB
Plaintext

(system-include "SDL2/SDL_ttf.h")
(add-pkg "SDL2_ttf")
(Project.config "cflag" "-Wno-incompatible-pointer-types-discards-qualifiers")
(register-type TTF_Font)
(defmodule TTF
(register init (Fn [] Int) "TTF_Init")
(register quit (Fn [] ()) "TTF_Quit")
(register get-error (Fn [] (Ptr CChar)) "TTF_GetError")
;; Loading / unloading
(register open-font (Fn [(Ptr CChar) Int] (Ptr TTF_Font)) "TTF_OpenFont")
(register close-font (Fn [(Ptr TTF_Font)] ()) "TTF_CloseFont")
;; Styles
;; int TTF_GetFontStyle(TTF_Font *font)
;; void TTF_SetFontStyle(TTF_Font *font, int style)
;; TTF_STYLE_BOLD
;; TTF_STYLE_ITALIC
;; TTF_STYLE_UNDERLINE
;; TTF_STYLE_STRIKETHROUGH
;; Render
(register render-text-solid
(Fn [(Ptr TTF_Font) (Ptr CChar) SDL_Color] (Ptr SDL_Surface))
"TTF_RenderText_Solid")
(register render-text-shaded
(Fn [(Ptr TTF_Font) (Ptr CChar) SDL_Color SDL_Color] (Ptr SDL_Surface))
"TTF_RenderText_Shaded")
(register render-text-blended
(Fn [(Ptr TTF_Font) (Ptr CChar) SDL_Color] (Ptr SDL_Surface))
"TTF_RenderText_Blended")
(register render-text-blended-wrapped
(Fn [(Ptr TTF_Font) (Ptr CChar) SDL_Color Int] (Ptr SDL_Surface))
"TTF_RenderText_Blended_Wrapped")
;; Helpers to make everything a bit nicer
(defn ok? [error-code]
(= 0 error-code))
(defn render-text-to-texture [rend font str color]
(let [surface (render-text-blended font (cstr str) color)
texture (SDL.create-texture-from-surface rend surface)]
(do (SDL.free-surface surface)
texture)))
)