Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DrawTextGL.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __DrawTextGL_hh__
26 #define __DrawTextGL_hh__
27 
28 #include <bias_config.h>
29 
30 #ifndef BIAS_HAVE_OPENGL
31 # error Please recompile BIAS with USE_OPENGL to use this file.
32 #endif // BIAS_HAVE_OPENGL
33 
34 #ifndef BIAS_HAVE_FONTGL
35 # error Please enable BIAS_HAVE_FONTGL to use this class (not completely tested on Linux) (JW)
36 #endif
37 
38 // default font size, should be negative, e.g. -14 (pixel)
39 #define DrawTextGL_DEFAULT_FONTSIZE -14
40 
41 // default font name
42 #ifdef WIN32
43 # define DrawTextGL_DEFAULT_FONTNAME "Arial"
44 #else // WIN32
45 # define DrawTextGL_DEFAULT_FONTNAME "-*-helvetica-bold-r-normal--24-*-*-*-p-*-iso8859-1"
46 #endif // WIN32
47 
48 
49 #include <string>
50 // BIAS
51 #include <Base/Common/W32Compat.hh>
52 
53 namespace BIAS {
54 
55 /** @brief Draw text to OpenGL as 2D bitmap font.
56  Implemented as setting up a 2D display list for every standard character.
57  - Creates font by given name and size "on the fly" for all installed fonts, e.g. True Type fonts or GLX fonts.
58  - Does not depend on third party libraries (like glut,..)
59  - Does not need to read a pre-rendered font from disk (like glf does)
60  - The font has to be available on each client machine at runtime, fallback is tried for unsupported font names.
61 
62  Uses standard Win32 calls to render TTF fonts on Windows
63  and GLX fonts on Linux.
64 
65  Tested with MS Windows XP and (Suse 9.2) Linux (JW).
66 
67  See Gui/Examples/ExampleGLShared for an Example.
68 
69  See http://www.opengl.org/resources/features/fontsurvey/ for other possible implementations, in particular 3D "outlined" fonts.
70  @author Jan Woetzel */
71 class BIASUtils_EXPORT DrawTextGL
72 {
73 public:
74  /// destructor, kills display lists JW
75  virtual ~DrawTextGL();
76 
77  /// ctor JW
78  DrawTextGL();
79 
80  /// frees the display lists JW
81  void DeleteFont();
82 
83  /** set the font up
84  @return 0 on success, negativ eon error JW
85  @param theFontname name of the font, e.g. "Arial"
86  @param theFontname e.g. "Arial", "Times New Roman" or on Linux: "-*-helvetica-bold-r-normal--24-*-*-*-p-*-iso8859-1");"
87  @param handleDC pointer to protected GDI device context,
88  on WIN32: a HDC, e.g. for wxWindow use: GetDC(HWND(this->GetHandle()))
89  on Linux: .. TODO ..
90  @author Jan Woetzel */
91  int InitFont(void* handleDC,
92  const std::string theFontname = std::string(DrawTextGL_DEFAULT_FONTNAME) ,
93  const int fontHeight = DrawTextGL_DEFAULT_FONTSIZE
94  );
95 
96  /** print text on OpenGL screen using current RasterPosition , settings etc. JW */
97  void Print(const std::string & text) const;
98 
99  /** print text on OpenGL screen at 2D pos (xpos,ypos) in windows (pixel) coordiantes.
100  @param winWidthFallback and @param winHeightFallback are used only as GL 1.1 fallback. JW */
101  void PrintWinCoords(const std::string & text,
102  const int & xpos, const int & ypos,
103  const int & winWidthFallback=640, const int &winHeightFallback=480 ) const;
104 
105  /** print text on OpenGL screen in 0..1 normalized coordinates
106  with origin at lower left corner
107  with 0..1 normalizedx coordinates and origin in lower left corner:
108  \code
109  Y=1
110  ^
111  |
112  |
113  0,0 ---> x=1
114  \endcode
115  JW */
116  void PrintNormCoords(const std::string & text,
117  const float & xpos, const float & ypos) const;
118 
119  // use current MVP matrix and draw text in 3D position JW */
120  void Print3D(const std::string & text,
121  const float & xpos, const float & ypos, const float & zpos) const;
122 
123  /** draw text in 3d at absolute position,
124  thus ModelView matrix is set to identity (using push and pop).
125  Projection matrix is kept JW */
126  void Print3DAbsolute(const std::string & text,
127  const float & xpos, const float & ypos, const float & zpos) const;
128 
129 
130  bool IsInitialized() const {return initialized;};
131 
132 protected:
133  // --- data members: --------------------
134 
135  /// the name of our font, e.g. "Arial" or "-*-helvetica-bold-r-normal--24-*-*-*-p-*-iso8859-1");"
136  std::string fontname;
137 
138  /// true if we created the font as display lists
140 
141  /// inde xof our first display list:
142  unsigned int base;
143 };
144 
145 } //namespace BIAS
146 #endif // __FontGL_HH__
147 
unsigned int base
inde xof our first display list:
Definition: DrawTextGL.hh:142
bool initialized
true if we created the font as display lists
Definition: DrawTextGL.hh:139
bool IsInitialized() const
Definition: DrawTextGL.hh:130
Draw text to OpenGL as 2D bitmap font.
Definition: DrawTextGL.hh:71