38 #include FT_FREETYPE_H 94 GLboolean depth_mask=0;
95 glGetBooleanv(GL_DEPTH_WRITEMASK, &depth_mask);
96 glDepthMask(GL_FALSE);
126 glDepthMask(depth_mask);
131 GLboolean color_mask[4];
132 glGetBooleanv(GL_COLOR_WRITEMASK, color_mask);
133 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
136 int stencil_front_mask=0;
137 glGetIntegerv(GL_STENCIL_WRITEMASK, &stencil_front_mask);
138 int stencil_back_mask=0;
140 glGetIntegerv(GL_STENCIL_BACK_WRITEMASK, &stencil_back_mask);
150 glColorMask(color_mask[0],color_mask[1],color_mask[2],color_mask[3]);
153 glStencilMask(stencil_front_mask);
155 glStencilMaskSeparate(GL_BACK, stencil_back_mask);
163 Log::error(
"CoreText::renderText() error: no Font assigned to the CoreText object.\n");
168 if (!
font()->mFT_Face)
170 Log::error(
"CoreText::renderText() error: invalid FT_Face: probably you tried to load an unsupported font format.\n");
189 float texc[] = { 0,0,0,0,0,0,0,0 };
190 VL_glActiveTexture( GL_TEXTURE0 );
191 VL_glClientActiveTexture( GL_TEXTURE0 );
192 glEnable(GL_TEXTURE_2D);
193 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
194 glTexCoordPointer(2, GL_FLOAT, 0, texc);
197 glColor4fv(color.
ptr());
200 glNormal3fv(
fvec3(0,0,1).ptr() );
203 glEnableClientState( GL_VERTEX_ARRAY );
204 glVertexPointer(3, GL_FLOAT, 0, vect[0].ptr());
206 FT_Long use_kerning = FT_HAS_KERNING(
font()->mFT_Face );
207 FT_UInt previous = 0;
219 std::vector< String > lines;
220 lines.push_back(
String() );
223 if (
text()[i] ==
'\n')
226 lines.push_back(
String() );
229 lines.back() +=
text()[i];
232 for(
unsigned iline=0; iline<lines.size(); iline++)
239 int horz_text_align = 0;
241 int just_remained_space = 0;
243 for(
int c=0; c<(int)lines[iline].
length(); c++)
244 if ( lines[iline][c] ==
' ' )
249 just_space = int(rbbox.
width() - linebox.
width()) / space_count;
250 just_remained_space = int(rbbox.
width() - linebox.
width()) % space_count;
259 horz_text_align = -
int(rbbox.
width() - linebox.
width());
262 horz_text_align = -
int((rbbox.
width() - linebox.
width()) / 2.0f);
267 horz_text_align =
int(rbbox.
width() - linebox.
width());
273 horz_text_align = +
int((rbbox.
width() - linebox.
width()) / 2.0f);
279 if (iline != 0 && !lines[iline].
length())
281 pen.
y() -=
mFont->mHeight;
285 for(
int c=0; c<(int)lines[iline].
length(); c++)
287 if (c == 0 && iline != 0)
289 pen.
y() -=
mFont->mHeight;
293 const Glyph* glyph =
mFont->glyph( lines[iline][c] );
300 FT_Vector delta; delta.y = 0;
303 FT_Get_Kerning(
font()->mFT_Face, previous, glyph->
glyphIndex(), FT_KERNING_DEFAULT, &delta );
304 pen.
x() += delta.x / 64.0f;
309 FT_Get_Kerning(
font()->mFT_Face, glyph->
glyphIndex(), previous, FT_KERNING_DEFAULT, &delta );
310 pen.
x() -= delta.x / 64.0f;
312 pen.
y() += delta.y / 64.0f;
320 texc[0] = glyph->
s0();
321 texc[1] = glyph->
t1();
322 texc[2] = glyph->
s1();
323 texc[3] = glyph->
t1();
324 texc[4] = glyph->
s1();
325 texc[5] = glyph->
t0();
326 texc[6] = glyph->
s0();
327 texc[7] = glyph->
t0();
331 vect[0].
x() = pen.
x() + glyph->
width()*0 + left -1;
334 vect[1].
x() = pen.
x() + glyph->
width()*1 + left +1;
337 vect[2].
x() = pen.
x() + glyph->
width()*1 + left +1;
340 vect[3].
x() = pen.
x() + glyph->
width()*0 + left -1;
345 vect[0].
x() -= glyph->
width()-1 +2;
346 vect[1].
x() -= glyph->
width()-1 +2;
347 vect[2].
x() -= glyph->
width()-1 +2;
348 vect[3].
x() -= glyph->
width()-1 +2;
351 vect[0].
y() -=
mFont->mHeight;
352 vect[1].
y() -=
mFont->mHeight;
353 vect[2].
y() -=
mFont->mHeight;
354 vect[3].
y() -=
mFont->mHeight;
357 vect[0] -= (
fvec3)bbox.minCorner();
358 vect[1] -= (
fvec3)bbox.minCorner();
359 vect[2] -= (
fvec3)bbox.minCorner();
360 vect[3] -= (
fvec3)bbox.minCorner();
363 vect[0].
x() +=
margin() + horz_text_align;
365 vect[1].
x() +=
margin() + horz_text_align;
367 vect[2].
x() +=
margin() + horz_text_align;
369 vect[3].
x() +=
margin() + horz_text_align;
373 vect[0].
x() += offset.
x();
374 vect[0].
y() += offset.
y();
375 vect[1].
x() += offset.
x();
376 vect[1].
y() += offset.
y();
377 vect[2].
x() += offset.
x();
378 vect[2].
y() += offset.
y();
379 vect[3].
x() += offset.
x();
380 vect[3].
y() += offset.
y();
383 for(
int i=0; i<4; ++i)
389 vect[i].
x() -= (int)(bbox.width() / 2.0f);
396 vect[i].
x() -= (int)bbox.width();
403 vect[i].
y() -= (int)bbox.height();
410 vect[i].
y() -= int(bbox.height() / 2.0);
414 glDrawArrays(GL_QUADS, 0, 4);
417 glDisable(GL_TEXTURE_2D);
418 glColor3fv(
vec3(1,0,0).ptr());
419 glDrawArrays(GL_LINE_LOOP, 0, 4);
420 glColor4fv(color.
ptr());
421 glEnable(GL_TEXTURE_2D);
425 if (just_space && lines[iline][c] ==
' ' && iline != lines.size()-1)
429 pen.
x() += just_space + (just_remained_space?1:0);
435 pen.
x() -= just_space + (just_remained_space?1:0);
438 if(just_remained_space)
439 just_remained_space--;
457 glDisableClientState( GL_VERTEX_ARRAY );
458 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
462 glDisable(GL_TEXTURE_2D);
463 glBindTexture(GL_TEXTURE_2D, 0);
473 Log::error(
"CoreText::rawboundingRect() error: no Font assigned to the CoreText object.\n");
478 if (!
font()->mFT_Face)
480 Log::error(
"CoreText::rawboundingRect() error: invalid FT_Face: probably you tried to load an unsupported font format.\n");
488 FT_Long use_kerning = FT_HAS_KERNING(
font()->mFT_Face );
489 FT_UInt previous = 0;
491 for(
int c=0; c<(int)text.
length(); c++)
508 FT_Vector delta; delta.y = 0;
511 FT_Get_Kerning(
font()->mFT_Face, previous, glyph->
glyphIndex(), FT_KERNING_DEFAULT, &delta );
512 pen.
x() += delta.x / 64.0f;
517 FT_Get_Kerning(
font()->mFT_Face, glyph->
glyphIndex(), previous, FT_KERNING_DEFAULT, &delta );
518 pen.
x() -= delta.x / 64.0f;
520 pen.
y() += delta.y / 64.0f;
528 vect[0].
x() = pen.
x() + glyph->
width()*0 + left -1;
531 vect[1].
x() = pen.
x() + glyph->
width()*1 + left +1;
534 vect[2].
x() = pen.
x() + glyph->
width()*1 + left +1;
537 vect[3].
x() = pen.
x() + glyph->
width()*0 + left -1;
542 vect[0].
x() -= glyph->
width()-1 +2;
543 vect[1].
x() -= glyph->
width()-1 +2;
544 vect[2].
x() -= glyph->
width()-1 +2;
545 vect[3].
x() -= glyph->
width()-1 +2;
548 vect[0].
y() -=
mFont->mHeight;
549 vect[1].
y() -=
mFont->mHeight;
550 vect[2].
y() -=
mFont->mHeight;
551 vect[3].
y() -=
mFont->mHeight;
578 glNormal3fv(
fvec3(0,0,1).ptr() );
589 a.
z() = b.
z() = c.
z() = d.
z() = 0;
592 glEnableClientState( GL_VERTEX_ARRAY );
593 glVertexPointer(3, GL_FLOAT, 0, vect);
595 glDrawArrays(GL_QUADS,0,4);
597 glDisableClientState( GL_VERTEX_ARRAY );
609 glNormal3fv(
fvec3(0,0,1).ptr() );
620 a.
z() = b.
z() = c.
z() = d.
z() = 0;
623 glEnableClientState( GL_VERTEX_ARRAY );
624 glVertexPointer(3, GL_FLOAT, 0, vect);
626 glDrawArrays(GL_LINE_LOOP,0,4);
628 glDisableClientState( GL_VERTEX_ARRAY );
651 min.
x() -= int(bbox.
width() / 2.0);
652 max.
x() -= int(bbox.
width() / 2.0);
659 min.
x() -= (int)bbox.
width();
660 max.
x() -= (int)bbox.
width();
675 min.
y() -= int(bbox.
height() / 2.0);
676 max.
y() -= int(bbox.
height() / 2.0);
Associates a Renderable object to an Effect and Transform.
Vector3< float > fvec3
A 3 components vector with float precision.
bool borderEnabled() const
If true draws a rectangular border around the text.
ETextLayout layout() const
Text layout: left to right, right to left.
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
const T_Scalar & z() const
void renderBackground(const Actor *actor, const Camera *camera) const
Represents an OpenGL context, possibly a widget or a pbuffer, which can also respond to keyboard...
The Glyph associated to a character of a given Font.
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
void renderBorder(const Actor *actor, const Camera *camera) const
int textOrigin() const
The origin of the text (pivot point for offsetting and rotations).
int margin() const
The margin to be left around the text.
unsigned int textureHandle() const
void renderText(const Actor *, const Camera *camera, const fvec4 &color, const fvec2 &offset) const
AABB boundingRect() const
Returns the plain 2D bounding box of the text, in local coordinates.
Visualization Library main namespace.
virtual void render_Implementation(const Actor *actor, const Shader *shader, const Camera *camera, OpenGLContext *gl_context) const
int length() const
Returns the length of the string.
Vector2< float > fvec2
A 2 components vector with float precision.
const fvec2 & advance() const
The AABB class implements an axis-aligned bounding box using vl::real precision.
AABB rawboundingRect(const String &text) const
const fvec4 & color() const
The color of the text.
ETextAlign textAlignment() const
Text alignment: left, right, center, justify.
real width() const
Returns the width of the AABB computed as max.x - min.x.
bool kerningEnabled() const
If enabled text rendering uses kerning information for better quality results (slower).
const vec3 & maxCorner() const
Returns the corner of the AABB with the maximum x y z coordinates.
float max(float a, float b)
float min(float a, float b)
void setMinCorner(real x, real y, real z)
Sets the corner of the AABB with the minimum x y z coordinates.
const fvec4 & outlineColor() const
The color of the character outline.
void setMaxCorner(real x, real y, real z)
Sets the corner of the AABB with the maximum x y z coordinates.
void addPoint(const vec3 &p, real radius)
Updates the AABB to contain the given point.
const T_Scalar & y() const
bool outlineEnabled() const
If true the characters are drawn with an outline.
unsigned int glyphIndex() const
Manages most of the OpenGL rendering states responsible of the final aspect of the rendered objects...
const vec3 & minCorner() const
Returns the corner of the AABB with the minimum x y z coordinates.
const fvec4 & shadowColor() const
The color of the text shadow.
void bindVAS(const IVertexAttribSet *vas, bool use_vbo, bool force)
Activates the specified vertex attribute set - For internal use only.
fvec3 vec3
Defined as: 'typedef fvec3 vec3'. See also VL_PIPELINE_PRECISION.
const fvec2 & shadowVector() const
The offset vector of the shadow.
const T_Scalar & x() const
bool backgroundEnabled() const
If true draws a rectangular background below the text.
The ref<> class is used to reference-count an Object.
const T_Scalar & x() const
Represents a virtual camera defining, among other things, the point of view from which scenes can be ...
bool shadowEnabled() const
If true a sort of shadow is rendered below the text.
const Font * font() const
The font to be used to render the text.
const T_Scalar & y() const
const String & text() const
The text to be rendered.
real height() const
Returns the height of the AABB computed as max.y - min.y.