| GL Studio C++ Runtime API

gls_font_renderer.h
Go to the documentation of this file.
1/*! \file
2 \brief The disti::GlsFontRenderer class and related classes.
3
4 \par Copyright Information
5
6 Copyright (c) 2017 by The DiSTI Corporation.<br>
7 11301 Corporate Blvd; Suite 100<br>
8 Orlando, Florida 32817<br>
9 USA<br>
10 <br>
11 All rights reserved.<br>
12
13 This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38
39*/
40#ifndef _GLS_FONT_RENDERER_H
41#define _GLS_FONT_RENDERER_H
42
43#include "gls_gl.h"
44#include <string>
45#include <vector>
46#ifdef GLES
47# include "gls_quad_storage.h"
48# include "gls_state_manager.h"
49#endif
50#include "IFontImage.h"
51#include "gls_color.h"
52#include "gls_cpp_lang_support.h"
53#include "gls_font_base.h"
54#include "gls_state_manager.h"
55#include "image.h"
56#include "vertex.h"
57
58//===========================================================================
59// BEGIN NAMESPACE
60//===========================================================================
61 namespace disti
62{
63//---------------------------------------------------------------------------
64// FORWARD REFERENCES
65//---------------------------------------------------------------------------
66 class VertexNoColor;
67 class GlsColor;
68 class Image;
69
70 typedef VertexNoColor Vector;
71
72//===========================================================================
73/**
74*
75* The GlsFontRenderer object can be used to render characters from a GlsFontBase in
76* Open GL at specific locations and with several different text effects.
77* Prior to rendering any characters, InitRendering must be invoked to set
78* up the proper drawing environment. Then call Render for each character
79* to be drawn.
80*
81* \sa GlsFontBase
82*
83*/
84//===========================================================================
85 class GlsFontRenderer
86{
87 public:
88 typedef GlsFontBase::Char_t Char_t; ///< Shorthand for GlsFontBase::Char_t.
89 typedef GlsFontBase::CharAttr_t CharAttr_t; ///< Shorthand for GlsFontBase::CharAttr_t.
90
91 //----------------------------------------
92 // Character rendering state variables
93 //----------------------------------------
94
95 /// \return The minification filter for this font.
96 unsigned char TextureMinFilter()
97 {
98 return _textureMinFilter;
99 }
100
101 /// Sets the minification filter for this font.
102 /// \param val The new minification to set.
103 void TextureMinFilter( unsigned char val )
104 {
105 _textureMinFilter = val;
106 }
107
108 /// \return The magnification filter for this font.
109 unsigned char TextureMagFilter()
110 {
111 return _textureMagFilter;
112 }
113
114 /// Sets the magnification filter for this font.
115 /// \param val The new magnification to set.
116 void TextureMagFilter( unsigned char val )
117 {
118 _textureMagFilter = val;
119 }
120
121 //----------------------------------------
122 // Setup and cleanup for rendering
123 //----------------------------------------
124
125 /// Set the font to use.
126 /// The font pointer must be set before calling any rendering methods.
127 /// \param font The new font to use.
128 void SetFont( const GlsFontBase* font )
129 {
130 _font = font;
131 }
132
133 /// \return A pointer to the font currently in use.
134 const GlsFontBase* GetFont()
135 {
136 return _font;
137 }
138
139#ifdef GLES
140 /// Initializes the font to begin rendering characters. This will set up
141 /// Open GL texture modes, bind the font's texture, set up minification
142 /// and magnification filters, etc. This must be called once before
143 /// invoking Render to draw characters. This version overwrites the
144 /// texture minification and magnification filters before initializing.
145 /// \param textureMinFilter Minification mode for the font texture.
146 /// \param textureMagFilter Magnification mode for the font texture.
147 /// \param stateManager The object responsible for rendering the font.
148 void InitRendering(
149 unsigned char textureMinFilter,
150 unsigned char textureMagFilter,
151 IGlsStateManager* stateManager )
152 {
153 _textureMinFilter = textureMinFilter;
154 _textureMagFilter = textureMagFilter;
155 InitRendering( stateManager );
156 }
157
158 /// Initializes the font to begin rendering characters. This will set up
159 /// Open GL texture modes, bind the font's texture, set up minification
160 /// and magnification filters, etc. This must be called before
161 /// using any of the Render methods draw characters.
162 /// \param stateManager The state manager that will handle rendering the font.
163 void InitRendering( IGlsStateManager* stateManager )
164 {
165 SetupTexture( _font->Texture(), stateManager );
166 }
167
168#else // !GLES
169
170 /// Initializes the font to begin rendering characters. This will set up
171 /// Open GL texture modes, bind the font's texture, set up minification
172 /// and magnification filters, etc. This must be called once before
173 /// invoking Render to draw characters. This version overwrites the
174 /// texture minification and magnification filters before initializing.
175 /// \param textureMinFilter Minification mode for the font texture.
176 /// \param textureMagFilter Magnification mode for the font texture.
177 void InitRendering(
178 unsigned char textureMinFilter,
179 unsigned char textureMagFilter )
180 {
181 _textureMinFilter = textureMinFilter;
182 _textureMagFilter = textureMagFilter;
183 InitRendering();
184 }
185
186 /// Initializes the font to begin rendering characters. This will set up
187 /// Open GL texture modes, bind the font's texture, set up minification
188 /// and magnification filters, etc. This must be called before
189 /// using any of the Render methods draw characters.
190 void InitRendering()
191 {
192 SetupTexture( _font->Texture() );
193 }
194
195 /**
196 * Restores the Open GL state as it was before the call to InitRendering.
197 * This should be called after all characters have been rendered using
198 * the Render methods.
199 */
200 void TermRendering()
201 {
202 glDisable( GL_TEXTURE_2D );
203 } // end GlsFontRenderer::TermRendering
204
205#endif // GLES
206
207 //----------------------------------------
208 // Rendering Methods
209 //----------------------------------------
210
211#ifdef GLES
212 /** Draw a character by adding it into the supplied QuadStorage object
213 * \deprecated inverse no longer has any effect, use the other overload instead.
214 * \param emphasize Whether to draw with emphasize or not
215 * \param emphasisOffset If drawing with emphasize, the offset in logical units
216 * \param inverse Deprecated, has no effect
217 * \param quadStorage The quad storage object to render the characters into
218 * \param x1 lower left corner x coordinate of the polygon
219 * \param y1 lower left corner y coordinate of the polygon
220 * \param x2 upper right corner x coordinate of the polygon
221 * \param y2 upper right corner y coordinate of the polygon
222 */
223 DISTI_DEPRECATED( "This overload is deprecated because the clear text effect has been superseded. Use the DrawCharacter() overload without the 'inverse' parameter." )
224 void DrawCharacter(
225 const bool emphasize,
226 const float emphasisOffset,
227 const bool inverse,
228 GlsQuadListVCT_2D& quadStorage,
229 const GLfloat x1,
230 const GLfloat y1,
231 const GLfloat x2,
232 const GLfloat y2 ) const
233 {
234 DrawCharacter( emphasize, emphasisOffset, quadStorage, x1, y1, x2, y2 );
235 }
236
237 /** Draw a character by adding it into the supplied QuadStorage object
238 * \param emphasize Whether to draw with emphasize or not
239 * \param emphasisOffset If drawing with emphasize, the offset in logical units
240 * \param quadStorage The quad storage object to render the characters into
241 * \param x1 lower left corner x coordinate of the polygon
242 * \param y1 lower left corner y coordinate of the polygon
243 * \param x2 upper right corner x coordinate of the polygon
244 * \param y2 upper right corner y coordinate of the polygon
245 */
246 void DrawCharacter(
247 const bool emphasize,
248 const float emphasisOffset,
249 GlsQuadListVCT_2D& quadStorage,
250 const GLfloat x1,
251 const GLfloat y1,
252 const GLfloat x2,
253 const GLfloat y2 ) const
254 {
255 // character color
256 quadStorage.AddQuad2D( x1, y1, x2, y2 );
257
258 // Character emphasis. Draw two more cells offset a little so
259 // character appears bolded.
260 if( emphasize )
261 {
262 GLfloat offsetY1( y1 + emphasisOffset );
263 GLfloat offsetY2( y2 + emphasisOffset );
264
265 quadStorage.AddQuad2D( x1 - emphasisOffset, offsetY1, x2 - emphasisOffset, offsetY2 );
266 quadStorage.AddQuad2D( x1 + emphasisOffset, offsetY1, x2 + emphasisOffset, offsetY2 );
267 }
268
269 } // end GlsFontRenderer::DrawCharacter
270
271 /**
272 * Draws a halo effect for the given character.
273 *
274 * \param haloOffset Controls the size of the halo
275 * GlsTextGrid uses: (emphasize ? 0.05f : 0.03f) * (character_width) (x2 - x1)
276 * \param diagonalOffset The offset to use for the four diagonal directions.
277 * \param quadStorage A list containing 2D quads from the generated vertices.
278 * \param x1 lower left corner x coordinate of the polygon
279 * \param y1 lower left corner y coordinate of the polygon
280 * \param x2 upper right corner x coordinate of the polygon
281 * \param y2 upper right corner y coordinate of the polygon
282 */
283
284 void DrawHalo(
285 const float haloOffset,
286 const float diagonalOffset,
287 GlsQuadListVCT_2D& quadStorage,
288 const GLfloat x1,
289 const GLfloat y1,
290 const GLfloat x2,
291 const GLfloat y2 ) const
292 {
293 const GLfloat x1right( x1 + diagonalOffset );
294 const GLfloat x1left( x1 - diagonalOffset );
295 const GLfloat x2right( x2 + diagonalOffset );
296 const GLfloat x2left( x2 - diagonalOffset );
297 const GLfloat y1up( y1 + diagonalOffset );
298 const GLfloat y1down( y1 - diagonalOffset );
299 const GLfloat y2up( y2 + diagonalOffset );
300 const GLfloat y2down( y2 - diagonalOffset );
301
302 quadStorage.AddQuad2D( x1left, y1up, x2left, y2up );
303 quadStorage.AddQuad2D( x1left, y1down, x2left, y2down );
304 quadStorage.AddQuad2D( x1right, y1up, x2right, y2up );
305 quadStorage.AddQuad2D( x1right, y1down, x2right, y2down );
306 quadStorage.AddQuad2D( x1 - haloOffset, y1, x2 - haloOffset, y2 );
307 quadStorage.AddQuad2D( x1, y1 - haloOffset, x2, y2 - haloOffset );
308 quadStorage.AddQuad2D( x1 + haloOffset, y1, x2 + haloOffset, y2 );
309 quadStorage.AddQuad2D( x1, y1 + haloOffset, x2, y2 + haloOffset );
310 }
311
312#else // !GLES
313 /**
314 * Draws a character.
315 * \deprecated inverse no longer has any effect, use the other overload instead.
316 *
317 * \param emphasize true if the rendered character should be emphasized.
318 * This will essentially bold the character. If a bold
319 * font is being used, the character will appear even
320 * more bolded.
321 * \param emphasisOffset Magnitude of the emhpasis offset. A good value to try is (0.2 * character_width).
322 * \param inverse Deprecated, has no effect
323 * \param x1 lower left corner x coordinate of the polygon
324 * \param y1 lower left corner y coordinate of the polygon
325 * \param x2 upper right corner x coordinate of the polygon
326 * \param y2 upper right corner y coordinate of the polygon
327 * \param tx1 lower left corner x texture coordinate
328 * \param ty1 lower left corner y texture coordinate
329 * \param tx2 upper right corner x texture coordinate
330 * \param ty2 upper right corner y texture coordinate
331 */
332 DISTI_DEPRECATED( "This overload is deprecated because the clear text effect has been superseded. Use the DrawCharacter() overload without the 'inverse' parameter." )
333 void DrawCharacter(
334 const bool emphasize,
335 const float emphasisOffset,
336 const bool inverse,
337 const GLfloat x1,
338 const GLfloat y1,
339 const GLfloat x2,
340 const GLfloat y2,
341 const GLfloat tx1,
342 const GLfloat ty1,
343 const GLfloat tx2,
344 const GLfloat ty2 ) const
345 {
346 DrawCharacter( emphasize, emphasisOffset, x1, y1, x2, y2, tx1, ty1, tx2, ty2 );
347 }
348
349 /**
350 * Draws a character.
351 *
352 * \param emphasize true if the rendered character should be emphasized.
353 * This will essentially bold the character. If a bold
354 * font is being used, the character will appear even
355 * more bolded.
356 * \param emphasisOffset Magnitude of the emhpasis offset. A good value to try is (0.2 * character_width).
357 * \param x1 lower left corner x coordinate of the polygon
358 * \param y1 lower left corner y coordinate of the polygon
359 * \param x2 upper right corner x coordinate of the polygon
360 * \param y2 upper right corner y coordinate of the polygon
361 * \param tx1 lower left corner x texture coordinate
362 * \param ty1 lower left corner y texture coordinate
363 * \param tx2 upper right corner x texture coordinate
364 * \param ty2 upper right corner y texture coordinate
365 */
366 void DrawCharacter(
367 const bool emphasize,
368 const float emphasisOffset,
369 const GLfloat x1,
370 const GLfloat y1,
371 const GLfloat x2,
372 const GLfloat y2,
373 const GLfloat tx1,
374 const GLfloat ty1,
375 const GLfloat tx2,
376 const GLfloat ty2 ) const
377 {
378 glBegin( GL_QUADS );
379
380 MapTexture( x1, y1, x2, y2, tx1, ty1, tx2, ty2 );
381 // Character emphasis. Draw two more cells offset a little so
382 // character appears bolded.
383 if( emphasize )
384 {
385 GLfloat offsetY1( y1 + emphasisOffset );
386 GLfloat offsetY2( y2 + emphasisOffset );
387
388 MapTexture(
389 x1 - emphasisOffset, offsetY1, x2 - emphasisOffset, offsetY2,
390 tx1, ty1, tx2, ty2 );
391
392 MapTexture(
393 x1 + emphasisOffset, offsetY1, x2 + emphasisOffset, offsetY2,
394 tx1, ty1, tx2, ty2 );
395 }
396
397 glEnd();
398
399 } // end GlsFontRenderer::DrawCharacter
400
401 /// Draws a halo effect for the given character.
402 /// \param haloOffset Controls the size of the halo
403 /// GlsTextGrid uses: (emphasize ? 0.05f : 0.03f) * (character_width) (x2 - x1)
404 /// \param diagonalOffset The offset to use for the four diagonal directions.
405 /// \param x1 The lower left corner x coordinate of the polygon.
406 /// \param y1 The lower left corner y coordinate of the polygon.
407 /// \param x2 The upper right corner x coordinate of the polygon.
408 /// \param y2 The upper right corner y coordinate of the polygon.
409 /// \param tx1 The lower left corner x texture coordinate.
410 /// \param ty1 The lower left corner y texture coordinate.
411 /// \param tx2 The upper right corner x texture coordinate.
412 /// \param ty2 The upper right corner y texture coordinate.
413 void DrawHalo(
414 const float haloOffset,
415 const float diagonalOffset,
416 const GLfloat x1,
417 const GLfloat y1,
418 const GLfloat x2,
419 const GLfloat y2,
420 const GLfloat tx1,
421 const GLfloat ty1,
422 const GLfloat tx2,
423 const GLfloat ty2 ) const
424 {
425 // Halo effect.
426 GLfloat x1right( x1 + diagonalOffset );
427 GLfloat x1left( x1 - diagonalOffset );
428 GLfloat x2right( x2 + diagonalOffset );
429 GLfloat x2left( x2 - diagonalOffset );
430 GLfloat y1up( y1 + diagonalOffset );
431 GLfloat y1down( y1 - diagonalOffset );
432 GLfloat y2up( y2 + diagonalOffset );
433 GLfloat y2down( y2 - diagonalOffset );
434
435 glBegin( GL_QUADS );
436
437 // Shift left and up
438 MapTexture(
439 x1left, y1up, x2left, y2up,
440 tx1, ty1, tx2, ty2 );
441
442 // Shift left and down
443 MapTexture(
444 x1left, y1down, x2left, y2down,
445 tx1, ty1, tx2, ty2 );
446
447 // Shift right and up
448 MapTexture(
449 x1right, y1up, x2right, y2up,
450 tx1, ty1, tx2, ty2 );
451
452 // Shift right and down
453 MapTexture(
454 x1right, y1down, x2right, y2down,
455 tx1, ty1, tx2, ty2 );
456
457 // Shift left
458 MapTexture(
459 x1 - haloOffset, y1, x2 - haloOffset, y2,
460 tx1, ty1, tx2, ty2 );
461
462 // Shift down
463 MapTexture(
464 x1, y1 - haloOffset, x2, y2 - haloOffset,
465 tx1, ty1, tx2, ty2 );
466
467 // Shift right
468 MapTexture(
469 x1 + haloOffset, y1, x2 + haloOffset, y2,
470 tx1, ty1, tx2, ty2 );
471
472 // Shift up
473 MapTexture(
474 x1, y1 + haloOffset, x2, y2 + haloOffset,
475 tx1, ty1, tx2, ty2 );
476
477 glEnd();
478 } // end GlsFontRenderer::DrawHalo
479
480 /**
481 * Draws a drop shadow effect for a character.
482 * \param shadowOffset distance to offset the shadow from the character
483 * \param x1 lower left corner x coordinate of the polygon
484 * \param y1 lower left corner y coordinate of the polygon
485 * \param x2 upper right corner x coordinate of the polygon
486 * \param y2 upper right corner y coordinate of the polygon
487 * \param tx1 lower left corner x texture coordinate
488 * \param ty1 lower left corner y texture coordinate
489 * \param tx2 upper right corner x texture coordinate
490 * \param ty2 upper right corner y texture coordinate
491 */
492 void DrawShadow(
493 const float shadowOffset,
494 const GLfloat x1,
495 const GLfloat y1,
496 const GLfloat x2,
497 const GLfloat y2,
498 const GLfloat tx1,
499 const GLfloat ty1,
500 const GLfloat tx2,
501 const GLfloat ty2 ) const
502 {
503 // Shadow effect.
504 glBegin( GL_QUADS );
505
506 // Shift right and down
507 MapTexture(
508 x1 + shadowOffset,
509 y1 - shadowOffset,
510 x2 + shadowOffset,
511 y2 - shadowOffset,
512 tx1, ty1, tx2, ty2 );
513
514 glEnd();
515
516 } // end GlsFontRenderer::DrawShadow
517
518 /**
519 * Map a square piece of a texture onto a quad ( assumed to be called
520 between glBegin(GL_QUADS)...glEnd() pair )
521 * \param x1 the lower left corner x of the quad
522 * \param y1 the lower left corner y of the quad
523 * \param x2 the upper right corner x of the quad
524 * \param y2 the upper right corner of the quad
525 * \param tx1 lower left corner x texture coordinate
526 * \param ty1 lower left corner y texture coordinate
527 * \param tx2 upper right corner x texture coordinate
528 * \param ty2 upper right corner y texture coordinate
529 */
530 static void MapTexture(
531 const GLfloat x1,
532 const GLfloat y1,
533 const GLfloat x2,
534 const GLfloat y2,
535 const GLfloat tx1,
536 const GLfloat ty1,
537 const GLfloat tx2,
538 const GLfloat ty2 )
539 {
540 glTexCoord2f( tx1, ty1 );
541 glVertex2f( x1, y1 );
542 glTexCoord2f( tx2, ty1 );
543 glVertex2f( x2, y1 );
544 glTexCoord2f( tx2, ty2 );
545 glVertex2f( x2, y2 );
546 glTexCoord2f( tx1, ty2 );
547 glVertex2f( x1, y2 );
548 }
549
550#endif // GLES
551
552 /**
553 * Create a GlsFontRenderer with the default settings.
554 * \param font The font to use for rendering. This may be NULL on creation, but it must be set before rendering.
555 */
556 GlsFontRenderer( const GlsFontBase* font )
557 : _font( font )
558 , _textureMinFilter( TEXTURE_FILTER_LINEAR )
559 , _textureMagFilter( TEXTURE_FILTER_LINEAR )
560 {
561 }
562
563 protected:
564#ifndef GLES
565 /** Current drawing color is kept so we don't have to make an OpenGL call if the color is the same */
566 GlsColor _currentColor;
567#endif
568
569 /** Pointer to the font to use for rendering */
570 const GlsFontBase* _font;
571
572 /** Minification mode for the font texture */
573 unsigned char _textureMinFilter;
574
575 /** Magnification mode for the font texture */
576 unsigned char _textureMagFilter;
577
578#ifdef GLES
579
580 /// Helper method to set up Open GL texture modes, bind the font's texture,
581 /// set up minification and magnification filters, etc.
582 /// \param texture The font texture to bind.
583 /// \param stateManager The object responsible for rendering the texture.
584 void SetupTexture( IFontImage* texture, IGlsStateManager* stateManager )
585 {
586 const bool mipMap = ( ( TEXTURE_FILTER_NEAREST_MIPMAP_NEAREST == _textureMinFilter ) || ( TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR == _textureMinFilter ) || ( TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR == _textureMinFilter ) || ( TEXTURE_FILTER_LINEAR_MIPMAP_NEAREST == _textureMinFilter ) );
587 if( mipMap )
588 {
589 // This will force the image to create the mipmap images
590 texture->MipMap( true );
591 }
592
593 // Initialize the font texture
594 stateManager->Texture2DEnabled( true );
595 stateManager->BindTexture( texture );
596
597 // Set up mip mapping for magnification
598 if( _textureMagFilter == TEXTURE_FILTER_NEAREST )
599 {
600 stateManager->SetTextureMagFilter( GL_NEAREST );
601 }
602 else if( _textureMagFilter == TEXTURE_FILTER_LINEAR )
603 {
604 stateManager->SetTextureMagFilter( GL_LINEAR );
605 }
606
607 // Set up mip mapping for minification
608 switch( _textureMinFilter )
609 {
610 case TEXTURE_FILTER_NEAREST:
611 stateManager->SetTextureMinFilter( GL_NEAREST );
612 break;
613
614 case TEXTURE_FILTER_LINEAR:
615 stateManager->SetTextureMinFilter( GL_LINEAR );
616 break;
617
618 case TEXTURE_FILTER_NEAREST_MIPMAP_NEAREST:
619 stateManager->SetTextureMinFilter( GL_NEAREST_MIPMAP_NEAREST );
620 break;
621
622 case TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR:
623 stateManager->SetTextureMinFilter( GL_LINEAR_MIPMAP_LINEAR );
624 break;
625
626 case TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR:
627 stateManager->SetTextureMinFilter( GL_NEAREST_MIPMAP_LINEAR );
628 break;
629
630 case TEXTURE_FILTER_LINEAR_MIPMAP_NEAREST:
631 stateManager->SetTextureMinFilter( GL_LINEAR_MIPMAP_NEAREST );
632 break;
633 }
634
635 stateManager->SetTextureEnvMode( IGlsStateManager::GLS_TEXTURE_MAP_MODE_MODULATE );
636
637 } // end GlsFontRenderer::SetupTexture
638
639#else // !GLES
640
641 /// Helper method to set up Open GL texture modes, bind the font's texture,
642 /// set up minification and magnification filters, etc.
643 /// \param texture The font texture to bind.
644 void SetupTexture( IFontImage* texture )
645 {
646 const bool mipMap = ( ( TEXTURE_FILTER_NEAREST_MIPMAP_NEAREST == _textureMinFilter ) || ( TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR == _textureMinFilter ) || ( TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR == _textureMinFilter ) || ( TEXTURE_FILTER_LINEAR_MIPMAP_NEAREST == _textureMinFilter ) );
647 if( mipMap )
648 {
649 // This will force the image to create the mipmap images
650 texture->MipMap( true );
651 }
652
653 // Initialize the drawing color
654 glColor4ubv( _currentColor.RGBA() );
655
656 // Initialize the font texture
657 glEnable( GL_TEXTURE_2D );
658 texture->BindTexture();
659
660 // Set up mip mapping for magnification
661 if( _textureMagFilter == TEXTURE_FILTER_NEAREST )
662 {
663 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
664 }
665 else if( _textureMagFilter == TEXTURE_FILTER_LINEAR )
666 {
667 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
668 }
669
670 // Set up mip mapping for minification
671 switch( _textureMinFilter )
672 {
673 case TEXTURE_FILTER_NEAREST:
674 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
675 break;
676 case TEXTURE_FILTER_LINEAR:
677 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
678 break;
679 case TEXTURE_FILTER_NEAREST_MIPMAP_NEAREST:
680 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST );
681 break;
682 case TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR:
683 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
684 break;
685 case TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR:
686 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR );
687 break;
688 case TEXTURE_FILTER_LINEAR_MIPMAP_NEAREST:
689 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
690 break;
691 }
692
693 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
694
695 } // end GlsFontRenderer::SetupTexture
696
697#endif // GLES
698
699}; // end class GlsFontRenderer
700
701} // end namespace disti
702
703#endif
IFontImage.h
IFontImage.
disti::GlsColor
Definition: gls_color.h:54
disti::GlsColor::RGBA
void RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
Definition: gls_color.h:169
disti::GlsFontBase
Definition: gls_font_base.h:87
disti::GlsFontBase::Texture
Image * Texture() const
Definition: gls_font_base.h:331
disti::GlsFontBase::Char_t
GLuint Char_t
Define the character type to use.
Definition: gls_font_base.h:89
disti::GlsFontRenderer
Definition: gls_font_renderer.h:86
disti::GlsFontRenderer::DrawCharacter
void DrawCharacter(const bool emphasize, const float emphasisOffset, GlsQuadListVCT_2D &quadStorage, const GLfloat x1, const GLfloat y1, const GLfloat x2, const GLfloat y2) const
Definition: gls_font_renderer.h:246
disti::GlsFontRenderer::SetupTexture
void SetupTexture(IFontImage *texture, IGlsStateManager *stateManager)
Definition: gls_font_renderer.h:584
disti::GlsFontRenderer::InitRendering
void InitRendering(unsigned char textureMinFilter, unsigned char textureMagFilter, IGlsStateManager *stateManager)
Definition: gls_font_renderer.h:148
disti::GlsFontRenderer::TextureMagFilter
void TextureMagFilter(unsigned char val)
Definition: gls_font_renderer.h:116
disti::GlsFontRenderer::GlsFontRenderer
GlsFontRenderer(const GlsFontBase *font)
Definition: gls_font_renderer.h:556
disti::GlsFontRenderer::_font
const GlsFontBase * _font
Definition: gls_font_renderer.h:570
disti::GlsFontRenderer::GetFont
const GlsFontBase * GetFont()
Definition: gls_font_renderer.h:134
disti::GlsFontRenderer::TextureMinFilter
void TextureMinFilter(unsigned char val)
Definition: gls_font_renderer.h:103
disti::GlsFontRenderer::CharAttr_t
GlsFontBase::CharAttr_t CharAttr_t
Shorthand for GlsFontBase::CharAttr_t.
Definition: gls_font_renderer.h:89
disti::GlsFontRenderer::TextureMagFilter
unsigned char TextureMagFilter()
Definition: gls_font_renderer.h:109
disti::GlsFontRenderer::_textureMinFilter
unsigned char _textureMinFilter
Definition: gls_font_renderer.h:573
disti::GlsFontRenderer::TextureMinFilter
unsigned char TextureMinFilter()
Definition: gls_font_renderer.h:96
disti::GlsFontRenderer::DrawCharacter
void DrawCharacter(const bool emphasize, const float emphasisOffset, const bool inverse, GlsQuadListVCT_2D &quadStorage, const GLfloat x1, const GLfloat y1, const GLfloat x2, const GLfloat y2) const
Definition: gls_font_renderer.h:224
disti::GlsFontRenderer::_textureMagFilter
unsigned char _textureMagFilter
Definition: gls_font_renderer.h:576
disti::GlsFontRenderer::InitRendering
void InitRendering(IGlsStateManager *stateManager)
Definition: gls_font_renderer.h:163
disti::GlsFontRenderer::Char_t
GlsFontBase::Char_t Char_t
Shorthand for GlsFontBase::Char_t.
Definition: gls_font_renderer.h:88
disti::GlsFontRenderer::SetFont
void SetFont(const GlsFontBase *font)
Definition: gls_font_renderer.h:128
disti::GlsFontRenderer::DrawHalo
void DrawHalo(const float haloOffset, const float diagonalOffset, GlsQuadListVCT_2D &quadStorage, const GLfloat x1, const GLfloat y1, const GLfloat x2, const GLfloat y2) const
Definition: gls_font_renderer.h:284
disti::GlsQuadListVCT_2D
Definition: gls_quad_storage.h:160
disti::GlsQuadListVCT_2D::AddQuad2D
void AddQuad2D(const float x1, const float y1, const float x2, const float y2)
disti::IFontImage
Definition: IFontImage.h:54
disti::IFontImage::BindTexture
virtual void BindTexture()=0
disti::IFontImage::MipMap
virtual bool MipMap()=0
disti::IGlsStateManager
Definition: gls_state_manager_interface.h:69
disti::IGlsStateManager::SetTextureMagFilter
virtual void SetTextureMagFilter(GLenum mode)=0
disti::IGlsStateManager::BindTexture
virtual void BindTexture(IFontImage *texture)=0
disti::IGlsStateManager::SetTextureEnvMode
virtual void SetTextureEnvMode(GLenum mode)=0
disti::IGlsStateManager::SetTextureMinFilter
virtual void SetTextureMinFilter(GLenum mode)=0
disti::IGlsStateManager::Texture2DEnabled
virtual void Texture2DEnabled(bool val)=0
gls_color.h
The Color class: Implements a 4 component RGBA color.
gls_cpp_lang_support.h
Macros and helper code to determine what subset of C++11/14/17 is available.
DISTI_DEPRECATED
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:488
gls_font_base.h
The disti::GlsFontBase class and related classes.
gls_gl.h
The gls_gl.
gls_quad_storage.h
The disti::GlsQuadListVC_3D and GlsQuadListVCT_2D classes.
gls_state_manager.h
The disti::GlsStateManager factory class. Creates an instance of a state manager that manages the GL ...
image.h
The Image class. All textures are converted internally into Images.
disti
Definition: bmpimage.h:47
disti::TEXTURE_FILTER_NEAREST
@ TEXTURE_FILTER_NEAREST
Definition: display_types.h:63
disti::TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR
@ TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR
Definition: display_types.h:66
disti::TEXTURE_FILTER_NEAREST_MIPMAP_NEAREST
@ TEXTURE_FILTER_NEAREST_MIPMAP_NEAREST
Definition: display_types.h:65
disti::TEXTURE_FILTER_LINEAR_MIPMAP_NEAREST
@ TEXTURE_FILTER_LINEAR_MIPMAP_NEAREST
Definition: display_types.h:68
disti::TEXTURE_FILTER_LINEAR
@ TEXTURE_FILTER_LINEAR
Definition: display_types.h:64
disti::TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR
@ TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR
Definition: display_types.h:67
disti::Vector
VertexNoColor Vector
Definition: gls_font_base.h:69
disti::GlsFontBase::CharAttr_t
Character attributes. One item for each character in the set.
Definition: gls_font_base.h:125
vertex.h
The disti::Vertex class. A class for manipulating 3D vertices.