30 #include "../vrml_parser/Structs.h"
31 #include "opengl/RasterFont.h"
32 #include "opengl/OpenGL_Utils.h"
36 #include "../main/headers.h"
37 #include "../input/EAIHelpers.h"
38 #include "../scenegraph/Component_Text.h"
52 static vec4f_t static_xf_colors[] = {
53 { 1.0f, 1.0f, 1.0f, 1.0f },
54 { 0.0f, 0.0f, 0.0f, 1.0f },
55 { 0.5f, 0.5f, 0.5f, 1.0f }
70 void *RasterFont_constructor(){
75 void RasterFont_init(
struct tRasterFont *t){
78 t->prv = RasterFont_constructor();
86 p->rf_initialized = FALSE;
88 p->xf_color = xf_white;
89 memcpy(p->xf_colors,static_xf_colors,
sizeof(static_xf_colors));
99 void rf_print(
const char *text)
103 p->myText.string.p[0]->touched = 0;
104 verify_Uni_String (p->myText.string.p[0],(
char *)text);
105 if (p->myText.string.p[0]->touched > 0) {
111 render_Text (&p->myText);
115 void rf_printf(
int x,
int y,
const char *format, ...)
117 #if defined(IPHONE) || defined(_ANDROID ) || defined(GLES2)
121 char xfont_buffer[5000];
124 if (!p->rf_initialized) {
125 ERROR_MSG(
"xfont not initialized !!! initializing with defaults (fixed white)\n");
126 if (!rf_xfont_init(
"fixed")) {
129 rf_xfont_set_color(xf_white);
132 va_start(ap, format);
133 vsprintf(xfont_buffer, format, ap);
136 FW_GL_RASTERPOS2I(x, y);
138 #ifdef HAVE_TO_REIMPLEMENT
140 FW_GL_COLOR4FV(p->xf_colors[p->xf_color]);
143 rf_print(xfont_buffer);
150 #ifdef GL_ES_VERSION_2_0
153 FW_GL_PUSH_ATTRIB(GL_ENABLE_BIT);
155 glDisable(GL_DEPTH_TEST);
156 glDisable(GL_CULL_FACE);
160 FW_GL_MATRIX_MODE(GL_PROJECTION);
162 FW_GL_LOAD_IDENTITY();
164 FW_GL_ORTHO(0.0, (GLfloat) gglobal()->display.screenWidth,
165 0.0, (GLfloat) gglobal()->display.screenHeight,
168 FW_GL_MATRIX_MODE(GL_MODELVIEW);
170 FW_GL_LOAD_IDENTITY();
171 FW_GL_TRANSLATE_F(0.375f, 0.375f, 0.0f);
174 void rf_leave_layer2D()
176 #ifdef GL_ES_VERSION_2_0
182 FW_GL_MATRIX_MODE(GL_PROJECTION);
184 FW_GL_MATRIX_MODE(GL_MODELVIEW);
188 int rf_xfont_init(
const char *fontname)
195 bzero (&p->myText,sizeof (
struct X3D_Text));
197 p->myText._nodeType=NODE_Text;
198 p->myText.fontStyle = NULL;
199 p->myText.solid = TRUE;
200 p->myText.__rendersub = 0;
201 p->myText.origin.c[0] = 0;p->myText.origin.c[1] = 0;p->myText.origin.c[2] = 0;;
204 p->myText.string.p = MALLOC (
struct Uni_String **,
sizeof(
struct Uni_String)*1);p->myText.string.p[0] = newASCIIString(
"Initial String for Status Line");p->myText.string.n=1; ;
207 p->myText.textBounds.c[0] = 0;p->myText.textBounds.c[1] = 0;;
208 p->myText.length.n=0; p->myText.length.p=0;
209 p->myText.maxExtent = 0;
210 p->myText.lineBounds.n=0; p->myText.lineBounds.p=0;
211 p->myText.metadata = NULL;
212 p->myText._defaultContainer = FIELDNAMES_geometry;
217 p->myFont._nodeType = NODE_FontStyle;
218 p->myFont.language = newASCIIString(
"");
219 p->myFont.leftToRight = TRUE;
220 p->myFont.topToBottom = TRUE;
221 p->myFont.style = newASCIIString(
"PLAIN");
222 p->myFont.size = 20.0f;
223 p->myFont.justify.p = MALLOC (
struct Uni_String **,
sizeof(
struct Uni_String)*1);p->myFont.justify.p[0] = newASCIIString(
"BEGIN");p->myFont.justify.n=1; ;
224 p->myFont.metadata = NULL;
225 p->myFont.spacing = 1;
226 p->myFont.horizontal = TRUE;
228 p->myFont.family.p = MALLOC (
struct Uni_String **,
sizeof(
struct Uni_String)*1);p->myFont.family.p[0] = newASCIIString(
"TYPEWRITER");p->myFont.family.n=1; ;
229 p->myFont._defaultContainer = FIELDNAMES_fontStyle;
231 p->myText.fontStyle = X3D_NODE(&p->myFont);
232 p->rf_initialized = TRUE;
236 void rf_xfont_set_color(e_xfont_color_t index)
240 ASSERT(index < e_xfont_color_max);
244 void rf_xfont_set_usercolor(vec4f_t color)
248 p->xf_colors[xf_user][0] = color[0];
249 p->xf_colors[xf_user][1] = color[1];
250 p->xf_colors[xf_user][2] = color[2];
251 p->xf_colors[xf_user][3] = color[3];