libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo es el conjunto de objetos y funciones, que permiten ejecutar las operaciones básicas de la plataforma Moldeo, y que compone su núcleo.
moOGLFT.h
Ir a la documentación de este archivo.
1 // -*- c++ -*-
2 /*
3  * OGLFT: A library for drawing text with OpenGL using the FreeType library
4  * Copyright (C) 2002 lignum Computing, Inc. <oglft@lignumcomputing.com>
5  * $Id: OGLFT.h,v 1.15 2003/10/01 14:41:09 allen Exp $
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  */
22 #include <moTypes.h>
23 
24 #ifndef OGLFT_H
25 #define OGLFT_H
26 
27 #define OGLFT_NO_QT 1
28 #ifdef MO_MACOSX
29  #define OGLFT_NO_SOLID 1
30 #endif
31 
32 #ifdef MO_USING_VC
33  #define OGLFT_NO_SOLID 1
34 #endif
35 
36 #include <iostream>
37 #include <iomanip>
38 
39 #ifdef HAVE_CONFIG_H
40 //#include <m_Config.h>
41 #endif
42 #ifndef OGLFT_NO_QT
43 #include <qregexp.h>
44 #endif
45 
46 #include <cmath>
47 #include <map>
48 #include <list>
49 #include <vector>
50 #ifdef HAVE_MPATROL
51 #include <mpdebug.h>
52 #endif
53 
54 #ifndef OGLFT_NO_SOLID
55 #include <GL/gle.h>
56 #endif
57 
58 #ifndef OGLFT_NO_QT
59 #include <qstring.h>
60 #include <qcolor.h>
61 #endif
62 
63 #include <ft2build.h>
64 #include FT_FREETYPE_H
65 #include FT_GLYPH_H
66 #include FT_OUTLINE_H
67 #include FT_TRIGONOMETRY_H
68 
70 
71 namespace OGLFT
72 {
73 
76  {
77  X,
78  Y,
79  Z,
80  W
81  };
82 
85  {
86  R,
87  G,
88  B,
89  A,
90  };
91 
93  //typedef void (*GLUTessCallback)();
94  #ifdef WIN32
95  typedef void (__stdcall * GLUTessCallback) (void);
96  #else
97  typedef void (*GLUTessCallback) (void);
98  #endif
99 
101 
109  {
110  public:
116  static FT_Library & instance (void);
117 
118  protected:
124  Library (void);
128  ~Library (void);
129 
130  private:
131  static Library library;
132  static FT_Library library_;
133  };
134 
138  struct Advance
139  {
140  float dx_;
141  float dy_;
142 
144  Advance (float dx = 0, float dy = 0):dx_ (dx), dy_ (dy)
145  {
146  }
147 
149  Advance (FT_Vector v)
150  {
151  dx_ = v.x / 64.;
152  dy_ = v.y / 64.;
153  }
154 
157  Advance & operator+= (const FT_Vector v)
158  {
159  dx_ += v.x / 64.;
160  dy_ += v.y / 64.;
161  return *this;
162  }
163  };
164 
167  struct BBox
168  {
169  float x_min_;
170  float y_min_;
171  float x_max_;
172  float y_max_;
174 
176  BBox ():x_min_ (0), y_min_ (0), x_max_ (0), y_max_ (0)
177  {
178  }
179 
186  BBox (FT_BBox ft_bbox)
187  {
188  x_min_ = ft_bbox.xMin / 64.;
189  y_min_ = ft_bbox.yMin / 64.;
190  x_max_ = ft_bbox.xMax / 64.;
191  y_max_ = ft_bbox.yMax / 64.;
192  }
193 
197  BBox & operator*= (double k)
198  {
199  x_min_ *= k;
200  y_min_ *= k;
201  x_max_ *= k;
202  y_max_ *= k;
203  advance_.dx_ *= k;
204  advance_.dy_ *= k;
205 
206  return *this;
207  }
208 
216  BBox & operator+= (const BBox & b)
217  {
218  float new_value;
219 
220  new_value = b.x_min_ + advance_.dx_;
221  if (new_value < x_min_)
222  x_min_ = new_value;
223 
224  new_value = b.y_min_ + advance_.dy_;
225  if (new_value < y_min_)
226  y_min_ = new_value;
227 
228  new_value = b.x_max_ + advance_.dx_;
229  if (new_value > x_max_)
230  x_max_ = new_value;
231 
232  new_value = b.y_max_ + advance_.dy_;
233  if (new_value > y_max_)
234  y_max_ = new_value;
235 
236  advance_.dx_ += b.advance_.dx_;
237  advance_.dy_ += b.advance_.dy_;
238 
239  return *this;
240  }
241  };
242 
246  class ColorTess
247  {
248  public:
249 
250  virtual ~ ColorTess ()
251  {
252  };
258  virtual MOfloat *color (MOdouble * p) = 0;
259  };
260 
265  {
266  public:
267  virtual ~ TextureTess ()
268  {
269  };
275  virtual MOfloat *texCoord (MOdouble * p) = 0;
276  };
277 
280  typedef std::vector < GLuint > DisplayLists;
281 
283  typedef DisplayLists::const_iterator DLCI;
284 
286  typedef DisplayLists::iterator DLI;
287 
289 
293  class Face
294  {
295  public:
299  {
303  RIGHT
304  };
305 
309  {
313  TOP
314  };
315 
323  {
325  IMMEDIATE
326  };
327 
328  private:
336  struct FaceData
337  {
338  FT_Face face_;
340  FaceData (FT_Face face, bool free_on_exit = true):face_ (face),
341  free_on_exit_
342  (free_on_exit)
343  {
344  }
345  };
346  protected:
350  std::vector < FaceData > faces_;
351 
353  bool valid_;
354 
356  enum GlyphCompileMode compile_mode_;
357 
359  float point_size_;
360 
362  FT_UInt resolution_;
363 
365  bool advance_;
366 
372  GLfloat foreground_color_[4];
373 
375  GLfloat background_color_[4];
376 
378  enum HorizontalJustification horizontal_justification_;
379 
381  enum VerticalJustification vertical_justification_;
382 
385 
389 
392 
396 
398  typedef std::map < FT_UInt, GLuint > GlyphDLists;
399 
402  typedef GlyphDLists::const_iterator GDLCI;
403 
406  typedef GlyphDLists::iterator GDLI;
407 
409  GlyphDLists glyph_dlists_;
410 
414 
415  public:
424  Face (const char *filename, float point_size = 12, FT_UInt resolution =
425  100);
426 
437  Face (FT_Face face, float point_size = 12, FT_UInt resolution = 100);
438 
443  virtual ~ Face (void);
444 
449  bool isValid (void) const
450  {
451  return valid_;
452  }
453 
461  bool addAuxiliaryFace (const char *filename);
462 
471  bool addAuxiliaryFace (FT_Face face);
472 
482  void setCompileMode (enum GlyphCompileMode compile_mode)
483  {
484  compile_mode_ = compile_mode;
485  }
486 
490  enum GlyphCompileMode compileMode (void) const
491  {
492  return compile_mode_;
493  }
494 
516  void setPointSize (float point_size);
517 
521  float pointSize (void)
522  {
523  return point_size_;
524  }
525 
536  void setResolution (FT_UInt resolution);
537 
541  FT_UInt resolution (void)
542  {
543  return resolution_;
544  }
545 
555  void setAdvance (bool advance)
556  {
557  advance_ = advance;
558  }
559 
563  bool advance (void) const
564  {
565  return advance_;
566  }
567 
577  void setForegroundColor (GLfloat red = 0.0,
578  GLfloat green = 0.0,
579  GLfloat blue = 0.0, GLfloat alpha = 1.0);
580 
588  void setForegroundColor (const GLfloat foreground_color[4]);
589  #ifndef OGLFT_NO_QT
590 
596  void setForegroundColor (const QRgb foreground_color);
597  #endif /* OGLFT_NO_QT */
598 
601  GLfloat foregroundRed (void) const
602  {
603  return foreground_color_[R];
604  }
608  GLfloat foregroundGreen (void) const
609  {
610  return foreground_color_[G];
611  }
615  GLfloat foregroundBlue (void) const
616  {
617  return foreground_color_[B];
618  }
622  GLfloat foregroundAlpha (void) const
623  {
624  return foreground_color_[A];
625  }
626 
636  void setBackgroundColor (GLfloat red = 1.0,
637  GLfloat green = 1.0,
638  GLfloat blue = 1.0, GLfloat alpha = 0.0);
639 
647  void setBackgroundColor (const GLfloat background_color[4]);
648  #ifndef OGLFT_NO_QT
649 
655  void setBackgroundColor (const QRgb background_color);
656  #endif /* OGLFT_NO_QT */
657 
660  GLfloat backgroundRed (void) const
661  {
662  return background_color_[R];
663  }
667  GLfloat backgroundGreen (void) const
668  {
669  return background_color_[G];
670  }
674  GLfloat backgroundBlue (void) const
675  {
676  return background_color_[B];
677  }
681  GLfloat backgroundAlpha (void) const
682  {
683  return background_color_[A];
684  }
685 
690  virtual void setCharacterRotationZ (GLfloat character_rotation_z) = 0;
691 
695  virtual GLfloat characterRotationZ (void) const = 0;
696 
702  void setCharacterRotationReference (unsigned char c);
703 
712  void setStringRotation (GLfloat string_rotation);
713 
717  GLfloat stringRotation (void) const
718  {
719  return string_rotation_;
720  }
721 
727  horizontal_justification)
728  {
729  horizontal_justification_ = horizontal_justification;
730  }
731 
735  enum HorizontalJustification horizontalJustification (void) const
736  {
737  return horizontal_justification_;
738  }
739 
745  vertical_justification)
746  {
747  vertical_justification_ = vertical_justification;
748  }
749 
753  enum VerticalJustification verticaljustification (void) const
754  {
755  return vertical_justification_;
756  }
757 
765  void setCharacterDisplayLists (const DisplayLists & character_display_lists)
766  {
767  character_display_lists_ = character_display_lists;
768  }
769 
774  DisplayLists & characterDisplayLists (void)
775  {
776  return character_display_lists_;
777  }
778 
782  virtual double height (void) const = 0;
783 
789  virtual BBox measure (unsigned char c) = 0;
790  #ifndef OGLFT_NO_QT
791 
796  virtual BBox measure (QChar c) = 0;
797  #endif /* OGLFT_NO_QT */
798 
803  virtual BBox measure (const char *s);
810  virtual BBox measureRaw (const char *s);
811  #ifndef OGLFT_NO_QT
812 
817  virtual BBox measure (const QString & s);
824  virtual BBox measure (const QString & format, double number);
831  virtual BBox measureRaw (const QString & s);
832  #endif /* OGLFT_NO_QT */
833 
843  GLuint compile (const char *s);
844  #ifndef OGLFT_NO_QT
845 
855  GLuint compile (const QString & s);
856  #endif /* OGLFT_NO_QT */
857 
864  GLuint compile (unsigned char c);
865  #ifndef OGLFT_NO_QT
866 
873  GLuint compile (const QChar c);
874  #endif /* OGLFT_NO_QT */
875 
881  void draw (const char *s);
882  #ifndef OGLFT_NO_QT
883 
889  void draw (const QString & s);
890  #endif /* OGLFT_NO_QT */
891 
897  void draw (unsigned char c);
898 
899  #ifndef OGLFT_NO_QT
900 
906  void draw (const QChar c);
907  #endif /* OGLFT_NO_QT */
908 
916  void draw (GLfloat x, GLfloat y, unsigned char c);
926  void draw (GLfloat x, GLfloat y, GLfloat z, unsigned char c);
927  #ifndef OGLFT_NO_QT
928 
936  void draw (GLfloat x, GLfloat y, QChar c);
946  void draw (GLfloat x, GLfloat y, GLfloat z, QChar c);
947  #endif /* OGLFT_NO_QT */
948 
954  void draw (GLfloat x, GLfloat y, const char *s);
962  void draw (GLfloat x, GLfloat y, GLfloat z, const char *s);
963  #ifndef OGLFT_NO_QT
964 
970  void draw (GLfloat x, GLfloat y, const QString & s);
978  void draw (GLfloat x, GLfloat y, GLfloat z, const QString & s);
996  void draw (GLfloat x, GLfloat y, const QString & format, double number);
1015  void draw (GLfloat x, GLfloat y, GLfloat z, const QString & format,
1016  double number);
1017  #endif /* OGLFT_NO_QT */
1018 
1022  int ascender (void)
1023  {
1024  return faces_.front ().face_->ascender;
1025  }
1026 
1031  int descender (void)
1032  {
1033  return faces_.front ().face_->descender;
1034  }
1035 
1036  protected:
1037  // The various styles override these routines
1038 
1044  virtual GLuint compileGlyph (FT_Face face, FT_UInt glyph_index) = 0;
1045 
1049  virtual void renderGlyph (FT_Face face, FT_UInt glyph_index) = 0;
1050 
1053  virtual void setCharSize (void) = 0;
1054 
1057  virtual void clearCaches (void) = 0;
1058 
1062  virtual void setRotationOffset (void) = 0;
1063 
1064  private:
1065  void init (void);
1066  BBox measure_nominal (const char *s);
1067  #ifndef OGLFT_NO_QT
1068  BBox measure_nominal (const QString & s);
1069  QString format_number (const QString & format, double number);
1070  #endif /* OGLFT_NO_QT */
1071  };
1072 
1074 
1078  class Polygonal:public Face
1079  {
1080  protected:
1082  struct
1083  {
1084  bool active_;
1085  GLfloat x_, y_, z_;
1086  } character_rotation_;
1087 
1091  unsigned int tessellation_steps_;
1092 
1097  double delta_, delta2_, delta3_;
1098 
1104 
1106  FT_Outline_Funcs interface_;
1107 
1110  static const unsigned int DEFAULT_TESSELLATION_STEPS = 4;
1111 
1125  {
1126  double v_[3];
1127 
1134 
1138 
1142  VertexInfo (ColorTess * color_tess = 0, TextureTess * texture_tess = 0):color_tess_ (color_tess),
1143  texture_tess_
1144  (texture_tess)
1145  {
1146  v_[X] = v_[Y] = v_[Z] = 0.;
1147  }
1148 
1156  VertexInfo (FT_Vector * ft_v, ColorTess * color_tess = 0, TextureTess * texture_tess = 0):color_tess_ (color_tess),
1157  texture_tess_
1158  (texture_tess)
1159  {
1160  v_[X] = (double) (ft_v->x / 64) + (double) (ft_v->x % 64) / 64.;
1161  v_[Y] = (double) (ft_v->y / 64) + (double) (ft_v->y % 64) / 64.;
1162  v_[Z] = 0.;
1163  }
1164 
1171  VertexInfo (double p[2], ColorTess * color_tess = 0, TextureTess * texture_tess = 0):color_tess_ (color_tess),
1172  texture_tess_
1173  (texture_tess)
1174  {
1175  v_[X] = p[X];
1176  v_[Y] = p[Y];
1177  v_[Z] = 0.;
1178  }
1179 
1187  VertexInfo (double x, double y, ColorTess * color_tess = 0, TextureTess * texture_tess = 0):color_tess_ (color_tess),
1188  texture_tess_
1189  (texture_tess)
1190  {
1191  v_[X] = x;
1192  v_[Y] = y;
1193  v_[Z] = 0.;
1194  }
1195 
1198  void normalize (void)
1199  {
1200  double length = sqrt (v_[X] * v_[X] + v_[Y] * v_[Y] + v_[Z] * v_[Z]);
1201  v_[X] /= length;
1202  v_[Y] /= length;
1203  v_[Z] /= length;
1204  }
1205  };
1206 
1212 
1214  typedef std::list < VertexInfo * >VertexInfoList;
1215 
1217  typedef VertexInfoList::const_iterator VILCI;
1218 
1220  typedef VertexInfoList::iterator VILI;
1221 
1227  VertexInfoList vertices_;
1228 
1232 
1236 
1240 
1241  public:
1249  Polygonal (const char *filename, float point_size = 12,
1250  FT_UInt resolution = 100);
1251 
1259  Polygonal (FT_Face face, float point_size = 12, FT_UInt resolution = 100);
1260 
1264  virtual ~ Polygonal (void);
1265 
1278  void setTessellationSteps (unsigned int tessellation_steps);
1279 
1284  unsigned int tessellationSteps (void) const
1285  {
1286  return tessellation_steps_;
1287  }
1288 
1293  void setCharacterRotationX (GLfloat character_rotation_x);
1294 
1299  void setCharacterRotationY (GLfloat character_rotation_y);
1300 
1305  void setCharacterRotationZ (GLfloat character_rotation_z);
1306 
1310  GLfloat characterRotationX (void) const
1311  {
1312  return character_rotation_.x_;
1313  }
1314 
1318  GLfloat characterRotationY (void) const
1319  {
1320  return character_rotation_.y_;
1321  }
1322 
1326  GLfloat characterRotationZ (void) const
1327  {
1328  return character_rotation_.z_;
1329  }
1330 
1337  void setColorTess (ColorTess * color_tess);
1341  ColorTess *colorTess (void) const
1342  {
1343  return color_tess_;
1344  }
1351  void setTextureTess (TextureTess * texture_tess);
1355  TextureTess *textureTess (void) const
1356  {
1357  return texture_tess_;
1358  }
1359 
1363  double height (void) const;
1364 
1370  BBox measure (unsigned char c);
1371  #ifndef OGLFT_NO_QT
1372 
1377  BBox measure (const QChar c);
1378  #endif /* OGLFT_NO_QT */
1379 
1385  BBox measure (const char *s)
1386  {
1387  return Face::measure (s);
1388  }
1389  #ifndef OGLFT_NO_QT
1390 
1396  BBox measure (const QString & format, double number)
1397  {
1398  return Face::measure (format, number);
1399  }
1400  #endif /* OGLFT_NO_QT */
1401 
1402  private:
1403  void init (void);
1404  void setCharSize (void);
1405  void setRotationOffset (void);
1406  GLuint compileGlyph (FT_Face face, FT_UInt glyph_index);
1407  protected:
1408  void clearCaches (void);
1409  };
1410 
1412 
1429  class Outline:public Polygonal
1430  {
1431  public:
1439  Outline (const char *filename, float point_size = 12,
1440  FT_UInt resolution = 100);
1448  Outline (FT_Face face, float point_size = 12, FT_UInt resolution = 100);
1449 
1453  ~Outline (void);
1454  private:
1455  void init (void);
1456  void renderGlyph (FT_Face face, FT_UInt glyph_index);
1457  static int moveToCallback (FT_Vector * to, Outline * outline);
1458  static int lineToCallback (FT_Vector * to, Outline * outline);
1459  static int conicToCallback (FT_Vector * control, FT_Vector * to,
1460  Outline * outline);
1461  static int cubicToCallback (FT_Vector * control1, FT_Vector * control2,
1462  FT_Vector * to, Outline * outline);
1463  };
1464 
1466 
1489  class Filled:public Polygonal
1490  {
1493  GLUtesselator *tess_obj_;
1494 
1497 
1498  protected:
1503  GLfloat depth_offset_;
1504 
1505  public:
1513  Filled (const char *filename, float point_size = 12,
1514  FT_UInt resolution = 100);
1522  Filled (FT_Face face, float point_size = 12, FT_UInt resolution = 100);
1527  virtual ~ Filled (void);
1528 
1534  {
1535  return extra_vertices_;
1536  }
1537 
1538  protected:
1539  void renderGlyph (FT_Face face, FT_UInt glyph_index);
1540  private:
1541  void init (void);
1542  static int moveToCallback (FT_Vector * to, Filled * filled);
1543  static int lineToCallback (FT_Vector * to, Filled * filled);
1544  static int conicToCallback (FT_Vector * control, FT_Vector * to,
1545  Filled * filled);
1546  static int cubicToCallback (FT_Vector * control1, FT_Vector * control2,
1547  FT_Vector * to, Filled * filled);
1548  static void vertexCallback (VertexInfo * vertex);
1549  static void beginCallback (GLenum which);
1550  static void endCallback (void);
1551  static void combineCallback (GLdouble coords[3], void *vertex_data[4],
1552  GLfloat weight[4], void **out_data,
1553  Filled * filled);
1554  static void errorCallback (GLenum error_code);
1555  };
1556 
1557  #ifndef OGLFT_NO_SOLID
1558 
1587  class Solid:public Filled
1588  {
1589  private:
1590 
1595  FT_Outline_Funcs interface_;
1596 
1598  static const unsigned int N_POLYLINE_PTS = 4;
1599 
1601  struct glePoint2D
1602  {
1603  double p_[2];
1604  glePoint2D (double p[2])
1605  {
1606  p_[X] = p[X];
1607  p_[Y] = p[Y];
1608  }
1609  glePoint2D (double x, double y)
1610  {
1611  p_[X] = x;
1612  p_[Y] = y;
1613  }
1615  {
1616  p_[X] = v.v_[X];
1617  p_[Y] = v.v_[Y];
1618  }
1619  };
1620 
1622  struct
1623  {
1624  double depth_;
1625  struct
1626  {
1627  int x_, y_;
1628  } normal_sign_;
1629  std::vector < glePoint2D > contour_;
1630  std::vector < glePoint2D > contour_normals_;
1631  gleDouble up_[3];
1633  gleDouble point_array_[N_POLYLINE_PTS][3];
1634  } extrusion_;
1635 
1636  public:
1644  Solid (const char *filename, float point_size = 12, FT_UInt resolution =
1645  100);
1646 
1654  Solid (FT_Face face, float point_size = 12, FT_UInt resolution = 100);
1655 
1659  ~Solid (void);
1664  void setDepth (double depth);
1665 
1669  double depth (void) const
1670  {
1671  return extrusion_.depth_;
1672  }
1673 
1674  private:
1675  // It would be nice if C/C++ had real matrix notation (like Perl!)
1676  void assign (gleDouble a[3], double x, double y, double z)
1677  {
1678  a[X] = x;
1679  a[Y] = y;
1680  a[Z] = z;
1681  }
1682 
1683  void init (void);
1684  void renderGlyph (FT_Face face, FT_UInt glyph_index);
1685  static int moveToCallback (FT_Vector * to, Solid * solid);
1686  static int lineToCallback (FT_Vector * to, Solid * solid);
1687  static int conicToCallback (FT_Vector * control, FT_Vector * to,
1688  Solid * solid);
1689  static int cubicToCallback (FT_Vector * control1, FT_Vector * control2,
1690  FT_Vector * to, Solid * solid);
1691  };
1692  #endif /* OGLFT_NO_SOLID */
1693 
1699  class Raster:public Face
1700  {
1701  protected:
1705  public:
1713  Raster (const char *filename, float point_size = 12, FT_UInt resolution =
1714  100);
1722  Raster (FT_Face face, float point_size = 12, FT_UInt resolution = 100);
1726  virtual ~ Raster (void);
1731  void setCharacterRotationZ (GLfloat character_rotation_z);
1735  GLfloat characterRotationZ (void) const
1736  {
1737  return character_rotation_z_;
1738  }
1739 
1743  double height (void) const;
1744 
1750  BBox measure (unsigned char c);
1751  #ifndef OGLFT_NO_QT
1752 
1757  BBox measure (const QChar c);
1758  #endif /* OGLFT_NO_QT */
1759 
1765  BBox measure (const char *s)
1766  {
1767  return Face::measure (s);
1768  }
1769  #ifndef OGLFT_NO_QT
1770 
1776  BBox measure (const QString & format, double number)
1777  {
1778  return Face::measure (format, number);
1779  }
1780  #endif /* OGLFT_NO_QT */
1781 
1782  private:
1783  void init (void);
1784  GLuint compileGlyph (FT_Face face, FT_UInt glyph_index);
1785  void setCharSize (void);
1786  void setRotationOffset (void);
1787  void clearCaches (void);
1788  };
1789 
1791 
1810  class Monochrome:public Raster
1811  {
1812  public:
1820  Monochrome (const char *filename, float point_size = 12,
1821  FT_UInt resolution = 100);
1829  Monochrome (FT_Face face, float point_size = 12, FT_UInt resolution =
1830  100);
1834  ~Monochrome (void);
1835  private:
1836  GLubyte * invertBitmap (const FT_Bitmap & bitmap);
1837  void renderGlyph (FT_Face face, FT_UInt glyph_index);
1838  };
1839 
1841 
1861  class Grayscale:public Raster
1862  {
1863  public:
1871  Grayscale (const char *filename, float point_size = 12,
1872  FT_UInt resolution = 100);
1880  Grayscale (FT_Face face, float point_size = 12, FT_UInt resolution = 100);
1884  ~Grayscale (void);
1885  private:
1886  GLubyte * invertPixmap (const FT_Bitmap & bitmap);
1887  void renderGlyph (FT_Face face, FT_UInt glyph_index);
1888  };
1889 
1891 
1917  class Translucent:public Raster
1918  {
1919  public:
1927  Translucent (const char *filename, float point_size = 12,
1928  FT_UInt resolution = 100);
1936  Translucent (FT_Face face, float point_size = 12, FT_UInt resolution =
1937  100);
1938 
1942  ~Translucent (void);
1943 
1944  private:
1945  GLubyte * invertPixmapWithAlpha (const FT_Bitmap & bitmap);
1946  void renderGlyph (FT_Face face, FT_UInt glyph_index);
1947  };
1948 
1950  class Texture:public Face
1951  {
1952  protected:
1954  struct
1955  {
1956  bool active_;
1957  GLfloat x_,
1959  y_,
1960  z_;
1961  } character_rotation_;
1962 
1970  {
1975  bottom_bearing_;
1976  int width_,
1977  height_;
1978  GLfloat texture_s_,
1981  texture_t_;
1982  FT_Vector advance_;
1985  };
1986 
1988  typedef std::map < FT_UInt, TextureInfo > GlyphTexObjs;
1989 
1992  typedef GlyphTexObjs::const_iterator GTOCI;
1993 
1996  typedef GlyphTexObjs::iterator GTOI;
1997 
1999  GlyphTexObjs glyph_texobjs_;
2000 
2001  public:
2009  Texture (const char *filename, float point_size = 12,
2010  FT_UInt resolution = 100);
2011 
2019  Texture (FT_Face face, float point_size = 12, FT_UInt resolution = 100);
2020 
2024  virtual ~ Texture (void);
2029  void setCharacterRotationX (GLfloat character_rotation_x);
2030 
2035  void setCharacterRotationY (GLfloat character_rotation_y);
2036 
2041  void setCharacterRotationZ (GLfloat character_rotation_z);
2042 
2046  GLfloat characterRotationX (void) const
2047  {
2048  return character_rotation_.x_;
2049  }
2050 
2054  GLfloat characterRotationY (void) const
2055  {
2056  return character_rotation_.y_;
2057  }
2058 
2062  GLfloat characterRotationZ (void) const
2063  {
2064  return character_rotation_.z_;
2065  }
2066 
2070  double height (void) const;
2071 
2077  BBox measure (unsigned char c);
2078  #ifndef OGLFT_NO_QT
2079 
2084  BBox measure (const QChar c);
2085  #endif /* OGLFT_NO_QT */
2086 
2092  BBox measure (const char *s)
2093  {
2094  return Face::measure (s);
2095  }
2096  #ifndef OGLFT_NO_QT
2097 
2103  BBox measure (const QString & format, double number)
2104  {
2105  return Face::measure (format, number);
2106  }
2107  #endif /* OGLFT_NO_QT */
2108 
2109  protected:
2118  unsigned int nearestPowerCeil (unsigned int a);
2126  virtual void bindTexture (FT_Face face, FT_UInt glyph_index) = 0;
2127 
2128  private:
2129  void init (void);
2130  void setCharSize (void);
2131  void setRotationOffset (void);
2132  GLuint compileGlyph (FT_Face face, FT_UInt glyph_index);
2133  void renderGlyph (FT_Face face, FT_UInt glyph_index);
2134  void clearCaches (void);
2135  };
2136 
2138 
2165  {
2166  public:
2174  MonochromeTexture (const char *filename, float point_size = 12,
2175  FT_UInt resolution = 100);
2183  MonochromeTexture (FT_Face face, float point_size = 12,
2184  FT_UInt resolution = 100);
2188  ~MonochromeTexture (void);
2189  private:
2190  GLubyte * invertBitmap (const FT_Bitmap & bitmap, int *width,
2191  int *height);
2192  void bindTexture (FT_Face face, FT_UInt glyph_index);
2193  };
2194 
2196 
2223  {
2224  public:
2232  GrayscaleTexture (const char *filename, float point_size = 12,
2233  FT_UInt resolution = 100);
2241  GrayscaleTexture (FT_Face face, float point_size = 12,
2242  FT_UInt resolution = 100);
2246  ~GrayscaleTexture (void);
2247  private:
2248  GLubyte * invertPixmap (const FT_Bitmap & bitmap, int *width,
2249  int *height);
2250  void bindTexture (FT_Face face, FT_UInt glyph_index);
2251  };
2252 
2254 
2287  {
2288  public:
2296  TranslucentTexture (const char *filename, float point_size = 12,
2297  FT_UInt resolution = 100);
2305  TranslucentTexture (FT_Face face, float point_size = 12,
2306  FT_UInt resolution = 100);
2310  ~TranslucentTexture (void);
2311  private:
2312  GLubyte * invertPixmap (const FT_Bitmap & bitmap, int *width,
2313  int *height);
2314  void bindTexture (FT_Face face, FT_UInt glyph_index);
2315  };
2316 } // Close OGLFT namespace
2317 #endif /* OGLFT_H */
BBox measure(const char *s)
Definition: moOGLFT.h:2092
Baseline alignment of text (default)
Definition: moOGLFT.h:311
Render text as a filled polygons.
Definition: moOGLFT.h:1489
float x_max_
The right-most position at which "ink" appears.
Definition: moOGLFT.h:171
GLuint texture_name_
< A bound texture name is an integer in OpenGL.
Definition: moOGLFT.h:1972
static FT_Library library_
Definition: moOGLFT.h:132
VertexInfoList::const_iterator VILCI
A convenience definition of the iterator over the list of vertices.
Definition: moOGLFT.h:1217
The Blue component of a color.
Definition: moOGLFT.h:88
DisplayLists::const_iterator DLCI
A convenience definition of an iterator for display list vectors.
Definition: moOGLFT.h:283
std::map< FT_UInt, TextureInfo > GlyphTexObjs
Type of the cache of defined glyph to texture objects mapping.
Definition: moOGLFT.h:1988
Advance(float dx=0, float dy=0)
Default constructor. An otherwise uninitialized Advance contains zeros.
Definition: moOGLFT.h:144
The Z component of space.
Definition: moOGLFT.h:79
int ascender(void)
Definition: moOGLFT.h:1022
unsigned int tessellationSteps(void) const
Definition: moOGLFT.h:1284
GlyphTexObjs::iterator GTOI
Definition: moOGLFT.h:1996
float y_min_
the bottom-most position at which "ink" appears.
Definition: moOGLFT.h:170
ColorTess * color_tess_
Definition: moOGLFT.h:1235
GLfloat characterRotationY(void) const
Definition: moOGLFT.h:1318
GlyphCompileMode
Definition: moOGLFT.h:322
This is the base class of the polygonal styles: outline, filled and solid.
Definition: moOGLFT.h:1078
VertexInfo last_vertex_
Definition: moOGLFT.h:1211
bool contour_open_
Definition: moOGLFT.h:1231
static Library library
Definition: moOGLFT.h:131
GLfloat foregroundAlpha(void) const
Definition: moOGLFT.h:622
virtual BBox measure(unsigned char c)=0
GLfloat characterRotationZ(void) const
Definition: moOGLFT.h:1326
TextureTess * texture_tess_
Definition: moOGLFT.h:1137
GLfloat characterRotationY(void) const
Definition: moOGLFT.h:2054
The Red component of a color.
Definition: moOGLFT.h:86
DisplayLists & characterDisplayLists(void)
Definition: moOGLFT.h:774
float y_max_
The top-most position at which "ink" appears.
Definition: moOGLFT.h:172
void setVerticalJustification(enum VerticalJustification vertical_justification)
Definition: moOGLFT.h:744
bool advance(void) const
Definition: moOGLFT.h:563
DisplayLists::iterator DLI
A convenience definition of an iterator for display list vectors.
Definition: moOGLFT.h:286
VertexInfo(double p[2], ColorTess *color_tess=0, TextureTess *texture_tess=0)
Definition: moOGLFT.h:1171
int descender(void)
Definition: moOGLFT.h:1031
The FreeType library instance.
Definition: moOGLFT.h:108
Render text as a polygon outline.
Definition: moOGLFT.h:1429
GlyphDLists::iterator GDLI
Definition: moOGLFT.h:406
bool advance_
Does rendering text affect the MODELVIEW matrix?
Definition: moOGLFT.h:365
float point_size_
Nominal point size.
Definition: moOGLFT.h:359
Advance(FT_Vector v)
Initialize an advance from a FreeType advance member.
Definition: moOGLFT.h:149
GLfloat characterRotationZ(void) const
Definition: moOGLFT.h:1735
Left justified justification of text.
Definition: moOGLFT.h:300
bool active_
the other values.)
Definition: moOGLFT.h:1956
Render text as texture mapped grayscale quads.
Definition: moOGLFT.h:2222
ColorSpace
Who to credit? Newton? I&#39;d consider these manifest constants.
Definition: moOGLFT.h:84
FT_UInt resolution(void)
Definition: moOGLFT.h:541
FT_Face rotation_reference_face_
The rotation reference character could be in any face.
Definition: moOGLFT.h:391
std::vector< FaceData > faces_
Definition: moOGLFT.h:350
float dx_
Advance increment in the X direction.
Definition: moOGLFT.h:140
Render text as a grayscale raster image.
Definition: moOGLFT.h:1861
GLfloat characterRotationX(void) const
Definition: moOGLFT.h:2046
#define LIBMOLDEO_API
Definition: moTypes.h:180
GLfloat rotation_offset_y_
Definition: moOGLFT.h:395
std::vector< glePoint2D > contour_normals_
Definition: moOGLFT.h:1630
Render text as a monochrome raster image.
Definition: moOGLFT.h:1810
#define MOfloat
Definition: moTypes.h:403
VerticalJustification
Definition: moOGLFT.h:308
Render text as a translucent raster image.
Definition: moOGLFT.h:1917
Descender alignment of text.
Definition: moOGLFT.h:310
VertexInfo(double x, double y, ColorTess *color_tess=0, TextureTess *texture_tess=0)
Definition: moOGLFT.h:1187
glePoint2D(const VertexInfo &v)
Definition: moOGLFT.h:1614
int n_polyline_pts_
Definition: moOGLFT.h:1632
FT_UInt resolution_
Display resolution in pixels per inch.
Definition: moOGLFT.h:362
float dy_
Advance increment in the Y direction.
Definition: moOGLFT.h:141
void setCompileMode(enum GlyphCompileMode compile_mode)
Definition: moOGLFT.h:482
bool valid_
Did a font load OK?
Definition: moOGLFT.h:353
VertexInfoList & extraVertices(void)
Definition: moOGLFT.h:1533
Compile new glyphs when seen for the first time.
Definition: moOGLFT.h:324
GLfloat foregroundRed(void) const
Definition: moOGLFT.h:601
GLfloat backgroundRed(void) const
Definition: moOGLFT.h:660
void assign(gleDouble a[3], double x, double y, double z)
Definition: moOGLFT.h:1676
Render text as texture mapped translucent quads.
Definition: moOGLFT.h:2286
FT_Outline_Funcs interface_
Definition: moOGLFT.h:1595
FT_UInt rotation_reference_glyph_
Definition: moOGLFT.h:388
Render text as solid letters.
Definition: moOGLFT.h:1587
GLfloat characterRotationX(void) const
Definition: moOGLFT.h:1310
void setCharacterDisplayLists(const DisplayLists &character_display_lists)
Definition: moOGLFT.h:765
glePoint2D(double p[2])
Definition: moOGLFT.h:1604
Render text as texture mapped monochrome quads.
Definition: moOGLFT.h:2164
The Alpha (or transparency) of a color.
Definition: moOGLFT.h:89
void setHorizontalJustification(enum HorizontalJustification horizontal_justification)
Definition: moOGLFT.h:726
BBox measure(const char *s)
Definition: moOGLFT.h:1765
virtual ~ TextureTess()
Definition: moOGLFT.h:267
TextureTess * texture_tess_
Definition: moOGLFT.h:1239
bool isValid(void) const
Definition: moOGLFT.h:449
The projection component of space.
Definition: moOGLFT.h:80
std::map< FT_UInt, GLuint > GlyphDLists
Type of the cache of defined glyph to display list mapping.
Definition: moOGLFT.h:398
unsigned int tessellation_steps_
Definition: moOGLFT.h:1091
GlyphDLists::const_iterator GDLCI
Definition: moOGLFT.h:402
GLfloat characterRotationZ(void) const
Definition: moOGLFT.h:2062
GLfloat backgroundAlpha(void) const
Definition: moOGLFT.h:681
GlyphTexObjs glyph_texobjs_
Cache of defined glyph texture objects.
Definition: moOGLFT.h:1999
VertexInfoList vertices_
Definition: moOGLFT.h:1227
int width_
The 2**l width of the texture.
Definition: moOGLFT.h:1976
VertexInfoList extra_vertices_
A place to store any extra vertices generated by the Combine callback.
Definition: moOGLFT.h:1496
GLfloat depth_offset_
Definition: moOGLFT.h:1503
Data for the gleExtrusion routine.
Definition: moOGLFT.h:1601
GLfloat string_rotation_
Rotate an entire string in the Z plane.
Definition: moOGLFT.h:384
The Y component of space.
Definition: moOGLFT.h:78
GLfloat foregroundGreen(void) const
Definition: moOGLFT.h:608
GLUtesselator * tess_obj_
Definition: moOGLFT.h:1493
float pointSize(void)
Definition: moOGLFT.h:521
BBox(FT_BBox ft_bbox)
Definition: moOGLFT.h:186
Advance advance_
The (total) advancement.
Definition: moOGLFT.h:173
The X component of space.
Definition: moOGLFT.h:77
BBox measure(const char *s)
Definition: moOGLFT.h:1385
TextureTess * textureTess(void) const
Definition: moOGLFT.h:1355
double depth(void) const
Definition: moOGLFT.h:1669
GLfloat foregroundBlue(void) const
Definition: moOGLFT.h:615
VertexInfoList::iterator VILI
A convenience definition of the iterator over the list of vertices.
Definition: moOGLFT.h:1220
#define MOdouble
Definition: moTypes.h:404
Centered alignment of text.
Definition: moOGLFT.h:312
A face (aka font) used to render text with OpenGL.
Definition: moOGLFT.h:293
VertexInfo(ColorTess *color_tess=0, TextureTess *texture_tess=0)
Definition: moOGLFT.h:1142
The Green component of a color.
Definition: moOGLFT.h:87
std::vector< glePoint2D > contour_
Definition: moOGLFT.h:1629
ColorTess * colorTess(void) const
Definition: moOGLFT.h:1341
Center justified alignment of text.
Definition: moOGLFT.h:302
Coordinates
Thanks to DesCartes, I&#39;d consider these manifest constants.
Definition: moOGLFT.h:75
GLfloat backgroundGreen(void) const
Definition: moOGLFT.h:667
BBox()
Default constructor is all zeros.
Definition: moOGLFT.h:176
void setAdvance(bool advance)
Definition: moOGLFT.h:555
glePoint2D(double x, double y)
Definition: moOGLFT.h:1609
HorizontalJustification
Definition: moOGLFT.h:298
GlyphDLists glyph_dlists_
Cache of defined glyph display lists.
Definition: moOGLFT.h:409
All of OGLFT C++ objects are in this namespace.
Definition: moOGLFT.cpp:23
double vector_scale_
Definition: moOGLFT.h:1103
GLfloat character_rotation_z_
Definition: moOGLFT.h:1704
void(* GLUTessCallback)(void)
Callback from GLU tessellation routines.
Definition: moOGLFT.h:97
VertexInfo(FT_Vector *ft_v, ColorTess *color_tess=0, TextureTess *texture_tess=0)
Definition: moOGLFT.h:1156
FaceData(FT_Face face, bool free_on_exit=true)
Definition: moOGLFT.h:340
GlyphTexObjs::const_iterator GTOCI
Definition: moOGLFT.h:1992
GLfloat backgroundBlue(void) const
Definition: moOGLFT.h:674
float x_min_
The left-most position at which "ink" appears.
Definition: moOGLFT.h:169
Natural origin alignment of text (default)
Definition: moOGLFT.h:301
This is the base class of the texture style.
Definition: moOGLFT.h:1950
GLfloat stringRotation(void) const
Definition: moOGLFT.h:717
std::vector< GLuint > DisplayLists
Definition: moOGLFT.h:280
std::list< VertexInfo *> VertexInfoList
Normally, we will consider a list of vertices.
Definition: moOGLFT.h:1214
FT_Outline_Funcs interface_
Callbacks for FreeType glyph decomposition into outlines.
Definition: moOGLFT.h:1106
double depth_
Definition: moOGLFT.h:1624
DisplayLists character_display_lists_
Definition: moOGLFT.h:413
virtual ~ ColorTess()
Definition: moOGLFT.h:250