gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
TextRenderer.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2017, Dr Franck P. Vidal (franck.p.vidal@fpvidal.net),
4 http://www.fpvidal.net/
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation and/or
15 other materials provided with the distribution.
16 
17 3. Neither the name of the Bangor University nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 */
33 
34 
35 #ifndef __TextRenderer_h
36 #define __TextRenderer_h
37 
38 
66 //******************************************************************************
67 // Include
68 //******************************************************************************
69 #ifndef __gVirtualXRayConfig_h
71 #endif
72 
73 #include <map>
74 #include <memory>
75 
76 #ifdef HAS_FREETYPE
77 #include <ft2build.h>
78 #include FT_FREETYPE_H
79 #endif
80 
81 #ifdef __VBO_h
82 #include "VBO.h"
83 #endif
84 
85 #ifndef __Shader_h
86 #include "gVirtualXRay/Shader.h"
87 #endif
88 
89 #ifdef __Vec3_h
90 #include "Vec3.h"
91 #endif
92 
93 
94 //******************************************************************************
95 // namespace
96 //******************************************************************************
97 namespace gVirtualXRay {
98 
99 
100 //==============================================================================
105 //==============================================================================
107 //------------------------------------------------------------------------------
108 {
109 //******************************************************************************
110 private:
111  //==========================================================================
117  //==========================================================================
118  class Character
119  {
120  //**************************************************************************
121  public:
122  //----------------------------------------------------------------------
124 
133  //----------------------------------------------------------------------
134  Character(unsigned int aTextureID = 0,
135  int aWidth = 0,
136  int aHeight = 0,
137  float aVX = 0,
138  float aVY = 0,
139  float aXOffset = 0,
140  float aYOffset = 0);
141 
142 
143  //----------------------------------------------------------------------
145  //----------------------------------------------------------------------
146  virtual ~Character();
147 
148 
149  void release();
150 
151 
152  unsigned int m_texture_id;
153  int m_width;
154  int m_height;
155  float m_vx;
156  float m_vy;
157  float m_x_offset;
158  float m_y_offset;
159  };
160 
161 
162 //******************************************************************************
163 public:
164  //--------------------------------------------------------------------------
166  //--------------------------------------------------------------------------
167  inline TextRenderer();
168 
169 
170  //--------------------------------------------------------------------------
172  //--------------------------------------------------------------------------
173  virtual ~TextRenderer();
174 
175 
176  void release();
177 
178 
179  //--------------------------------------------------------------------------
181 
184  //--------------------------------------------------------------------------
185  void initialise(unsigned int aFontSize = 16*38);
186 
187 
188  //--------------------------------------------------------------------------
190 
193  //--------------------------------------------------------------------------
194  void initialize(unsigned int aFontSize = 16*38);
195 
196 
197  //--------------------------------------------------------------------------
199 
203  //--------------------------------------------------------------------------
204  void initialise(const std::string aFontFile, unsigned int aFontSize = 16*38);
205 
206 
207  //--------------------------------------------------------------------------
209 
213  //--------------------------------------------------------------------------
214  void initialize(const std::string aFontFile, unsigned int aFontSize = 16*38);
215 
216 
217  //--------------------------------------------------------------------------
219 
227  //--------------------------------------------------------------------------
228  void renderText(const std::string& aText,
229  float x, float y,
230  Matrix4x4<GLfloat>& aProjectionMatrix,
231  GLfloat* apBackgroundColour,
232  GLfloat* apFontColour);
233 
234 
235  //--------------------------------------------------------------------------
237 
240  //--------------------------------------------------------------------------
241  bool isInitialised() const;
242 
243 
244 //******************************************************************************
245 protected:
246  //--------------------------------------------------------------------------
248 
251  //--------------------------------------------------------------------------
252  void initialiseInternalStates(unsigned int aFontSize);
253 
254 
255 #ifdef HAS_FREETYPE
256  FT_Library m_free_type;
258 
259 
261  FT_Face m_face;
262 
263 
265  std::map<char, Character> m_character_set;
266 
267 
269 #if __cplusplus < 199711L
270  std::auto_ptr<VBO> m_text_vbo;
271 #else
272  std::unique_ptr<VBO> m_text_vbo;
273 #endif
274 
275 
277  Shader m_display_text_shader;
278 #endif
279 
282 };
283 
284 
285 } // namespace gVirtualXRay
286 
287 
288 //******************************************************************************
289 #include "TextRenderer.inl"
290 
291 
292 #endif // __TextRenderer_h
void initialise(unsigned int aFontSize=16 *38)
Initialise the default font.
Class to render text using OpenGL and FreeType2.
void renderText(const std::string &aText, float x, float y, Matrix4x4< GLfloat > &aProjectionMatrix, GLfloat *apBackgroundColour, GLfloat *apFontColour)
Display some text.
virtual ~TextRenderer()
Destructor.
Class to handle GLSL shaders.
TextRenderer()
Default constructor.
Class to handle vertex buffer objects (VBOs).
TextRenderer is a class to render text using OpenGL and FreeType2.
Definition: TextRenderer.h:106
void initialiseInternalStates(unsigned int aFontSize)
Initialise internal states.
Template class to handle 3D vectors.
void initialize(unsigned int aFontSize=16 *38)
Initialise the default font.
Shader is a class to handle shaders written in GLSL.
Definition: Shader.h:87
bool m_initialised
Flag set to true when the fond is initialised.
Definition: TextRenderer.h:281
bool isInitialised() const
Accessor on the initialisation flag.
Matrix4x4 is a template class to handle a 4 by 4 matrix.
Definition: Matrix4x4.h:89