2 Copyright (c)2006-2007 - Brett Lajzer
4 See LICENSE for license information.
11 #include <SDL/SDL_ttf.h>
12 #include "funcs_font.h"
13 #include "funcs_video.h"
14 #include "gl_surface.h"
16 //loads a font and returns a pointer to it
17 int l_load_font(lua_State
*L
){
19 font
= TTF_OpenFont(luaL_checkstring(L
,1), (int)lua_tonumber(L
,2));
21 lua_pushlightuserdata(L
,font
);
26 int l_close_font(lua_State
*L
){
27 TTF_CloseFont((TTF_Font
*)lua_touserdata(L
,1));
32 //gets dimensions of a string as rendered with a font
33 int l_font_string_metrics(lua_State
*L
){
35 TTF_SizeUTF8((TTF_Font
*)lua_touserdata(L
,1), luaL_checkstring(L
,2), &w
, &h
);
37 lua_pushinteger(L
, w
);
38 lua_pushinteger(L
, h
);
43 //render a string in a font
44 int l_render_string(lua_State
*L
){
48 color
.r
= (int)lua_tonumber(L
,3);
49 color
.g
= (int)lua_tonumber(L
,4);
50 color
.b
= (int)lua_tonumber(L
,5);
52 temp
= TTF_RenderUTF8_Blended((TTF_Font
*)lua_touserdata(L
,1),luaL_checkstring(L
,2), color
);
54 GLuint new_tex
= surfaceToTexture(L
, temp
);
56 GLSurface
*final
= new GLSurface(new_tex
, temp
->w
, temp
->h
);
58 SDL_FreeSurface(temp
);
60 lua_pushlightuserdata(L
, final
);
61 lua_pushinteger(L
, final
->w
);
62 lua_pushinteger(L
, final
->h
);