Skip to content

Instantly share code, notes, and snippets.

@six519
Created November 13, 2022 08:52
Show Gist options
  • Save six519/ac27853675b8e4d7089a2ac2cdbfcdd5 to your computer and use it in GitHub Desktop.
Save six519/ac27853675b8e4d7089a2ac2cdbfcdd5 to your computer and use it in GitHub Desktop.
Titik Programming Language/Interpreter SDL2 Draw Text
if(!(s_it())) # init ttf
abt('Unable to init ttf...')
fi
if(!(s_i(S_E))) # init sdl
abt('Unable to initialize SDL...')
fi
win = s_cw("Test", S_WP_U, S_WP_U, 800, 600, S_W_S) #create window
if(win == Nil)
abt('Unable to create window...')
fi
fnt = s_oft("test.ttf", 32) #open font
if(fnt == Nil)
abt('Unable to initialize font...')
fi
text = s_rft(fnt, "Hello, World!", 255, 191, 0, 255) #render font (amber color)
if(text == Nil)
abt('Unable to create text...')
fi
surface = s_gsw(win) #get window surface
if(surface == Nil)
abt('Unable to get window surface...')
fi
dd = s_gdsw(text) #get surface dimension
xx = 400 - (dd['width'] / 2)
yy = 300 - (dd['height'] / 2)
rct = s_cr(xx, yy, 0, 0) #create rectangle
s_bsw(text, "", surface, rct) #text blit
s_usw(win)
wl(T)
event = s_pe()
event_type = s_gte(event)
if(event_type == S_E_Q)
brk
fi
s_d(16)
s_ce(event)
lw
s_fsw(text) #free surface
s_cft(fnt) #close font
s_dw(win) #destroy window
s_qt() #quit ttf
s_q() #quit sdl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment