SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLTexFont.h
Go to the documentation of this file.
1 /**
2  * \file SLTexFont.h
3  * \date July 2014
4  * \authors Marcus Hudritsch, original author is Philippe Decaudin
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8 */
9 
10 #ifndef SLTEXFONT
11 #define SLTEXFONT
12 
13 #include <SLGLTexture.h>
14 
15 class SLGLProgram;
16 
17 //-----------------------------------------------------------------------------
18 //! Texture Font class inherits SLGLTexture for alpha blended font rendering.
19 /*!
20 This texture font class was originally inspired by the the font class of the
21 AntTweakBar library (http://www.antisphere.com/Wiki/tools:anttweakbar)
22 The source bitmap includes 224 characters starting from ascii char 32 (space) to
23 ascii char 255:
24 <PRE>
25  !"#$%&'()*+,-./0123456789:;<=>?
26 \@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
27 `abcdefghijklmnopqrstuvwxyz{|}~
28 ���������������������������������������������������������������
29 ��������������������������������
30 ��������������������������������
31 </PRE>
32 First column of a source bitmap is a delimiter with color=zero at the end of
33 each line of characters. Last row of a line of characters is a delimiter with
34 color=zero at the last pixel of each character.
35 The source bitmaps for the fonts are in the folder _data/fonts. The where used
36 for design only. Their data is directly included a binary array in the source
37 file SLTexFont.cpp.
38 */
39 class SLTexFont : public SLGLTexture
40 {
41 public:
43  SLTexFont(SLstring fontFilename, SLstring shaderDir);
44  ~SLTexFont();
45 
46  void create(SLstring fontFilename);
47  SLVec2f calcTextSize(const SLstring& text,
48  SLfloat maxWidth = 0.0f,
49  SLfloat lineHeightFactor = 1.5f);
51  SLfloat maxW);
53  const SLstring& text,
54  SLfloat maxWidth = 0.0f,
55  SLfloat lineHeight = 1.5f);
57 
58  //! Single Character info struct w. min. and max. texcoords.
59  typedef struct
60  {
61  SLfloat width; //!< Width of char. in tex-coord.
62  SLfloat tx1; //!< Min. Texture x-coord.
63  SLfloat ty1; //!< Max. Texture y-coord.
64  SLfloat tx2; //!< Max. Texture x-coord.
65  SLfloat ty2; //!< Min. Texture y-coord.
66  } SLTexFontChar;
67 
68  SLTexFontChar chars[256]; //<! array of character info structs
69  SLint charsHeight; //<! height of characters
70 
72  bool _deleteProgram = false;
73 };
74 //-----------------------------------------------------------------------------
75 #endif
float SLfloat
Definition: SL.h:173
vector< SLstring > SLVstring
Definition: SL.h:201
string SLstring
Definition: SL.h:158
int SLint
Definition: SL.h:170
Encapsulation of an OpenGL shader program object.
Definition: SLGLProgram.h:56
Texture object for OpenGL texturing.
Definition: SLGLTexture.h:110
SLGLVertexArray encapsulates the core OpenGL drawing.
Texture Font class inherits SLGLTexture for alpha blended font rendering.
Definition: SLTexFont.h:40
bool _deleteProgram
Definition: SLTexFont.h:72
SLTexFontChar chars[256]
Definition: SLTexFont.h:68
SLint charsHeight
Definition: SLTexFont.h:69
void buildTextBuffers(SLGLVertexArray &vao, const SLstring &text, SLfloat maxWidth=0.0f, SLfloat lineHeight=1.5f)
Definition: SLTexFont.cpp:345
void create(SLstring fontFilename)
Definition: SLTexFont.cpp:83
SLGLProgram * _fontTexProgram
Definition: SLTexFont.h:71
SLGLProgram * fontTexProgram()
Definition: SLTexFont.h:56
SLVstring wrapTextToLines(SLstring text, SLfloat maxW)
Definition: SLTexFont.cpp:277
SLVec2f calcTextSize(const SLstring &text, SLfloat maxWidth=0.0f, SLfloat lineHeightFactor=1.5f)
Definition: SLTexFont.cpp:243
SLTexFont(SLstring fontFilename, SLGLProgram *fontTexProgram)
Definition: SLTexFont.cpp:19
Single Character info struct w. min. and max. texcoords.
Definition: SLTexFont.h:60
SLfloat width
Width of char. in tex-coord.
Definition: SLTexFont.h:61
SLfloat ty1
Max. Texture y-coord.
Definition: SLTexFont.h:63
SLfloat ty2
Min. Texture y-coord.
Definition: SLTexFont.h:65
SLfloat tx1
Min. Texture x-coord.
Definition: SLTexFont.h:62
SLfloat tx2
Max. Texture x-coord.
Definition: SLTexFont.h:64