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
:
42
SLTexFont
(
SLstring
fontFilename,
SLGLProgram
*
fontTexProgram
);
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);
50
SLVstring
wrapTextToLines
(
SLstring
text,
51
SLfloat
maxW);
52
void
buildTextBuffers
(
SLGLVertexArray
& vao,
53
const
SLstring
& text,
54
SLfloat
maxWidth = 0.0f,
55
SLfloat
lineHeight = 1.5f);
56
SLGLProgram
*
fontTexProgram
() {
return
_fontTexProgram
; }
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
71
SLGLProgram
*
_fontTexProgram
=
nullptr
;
72
bool
_deleteProgram
=
false
;
73
};
74
//-----------------------------------------------------------------------------
75
#endif
SLfloat
float SLfloat
Definition:
SL.h:173
SLVstring
vector< SLstring > SLVstring
Definition:
SL.h:201
SLstring
string SLstring
Definition:
SL.h:158
SLint
int SLint
Definition:
SL.h:170
SLGLTexture.h
SLGLProgram
Encapsulation of an OpenGL shader program object.
Definition:
SLGLProgram.h:56
SLGLTexture
Texture object for OpenGL texturing.
Definition:
SLGLTexture.h:110
SLGLVertexArray
SLGLVertexArray encapsulates the core OpenGL drawing.
Definition:
SLGLVertexArray.h:40
SLTexFont
Texture Font class inherits SLGLTexture for alpha blended font rendering.
Definition:
SLTexFont.h:40
SLTexFont::~SLTexFont
~SLTexFont()
Definition:
SLTexFont.cpp:70
SLTexFont::_deleteProgram
bool _deleteProgram
Definition:
SLTexFont.h:72
SLTexFont::chars
SLTexFontChar chars[256]
Definition:
SLTexFont.h:68
SLTexFont::charsHeight
SLint charsHeight
Definition:
SLTexFont.h:69
SLTexFont::buildTextBuffers
void buildTextBuffers(SLGLVertexArray &vao, const SLstring &text, SLfloat maxWidth=0.0f, SLfloat lineHeight=1.5f)
Definition:
SLTexFont.cpp:345
SLTexFont::create
void create(SLstring fontFilename)
Definition:
SLTexFont.cpp:83
SLTexFont::_fontTexProgram
SLGLProgram * _fontTexProgram
Definition:
SLTexFont.h:71
SLTexFont::fontTexProgram
SLGLProgram * fontTexProgram()
Definition:
SLTexFont.h:56
SLTexFont::wrapTextToLines
SLVstring wrapTextToLines(SLstring text, SLfloat maxW)
Definition:
SLTexFont.cpp:277
SLTexFont::calcTextSize
SLVec2f calcTextSize(const SLstring &text, SLfloat maxWidth=0.0f, SLfloat lineHeightFactor=1.5f)
Definition:
SLTexFont.cpp:243
SLTexFont::SLTexFont
SLTexFont(SLstring fontFilename, SLGLProgram *fontTexProgram)
Definition:
SLTexFont.cpp:19
SLVec2< SLfloat >
SLTexFont::SLTexFontChar
Single Character info struct w. min. and max. texcoords.
Definition:
SLTexFont.h:60
SLTexFont::SLTexFontChar::width
SLfloat width
Width of char. in tex-coord.
Definition:
SLTexFont.h:61
SLTexFont::SLTexFontChar::ty1
SLfloat ty1
Max. Texture y-coord.
Definition:
SLTexFont.h:63
SLTexFont::SLTexFontChar::ty2
SLfloat ty2
Min. Texture y-coord.
Definition:
SLTexFont.h:65
SLTexFont::SLTexFontChar::tx1
SLfloat tx1
Min. Texture x-coord.
Definition:
SLTexFont.h:62
SLTexFont::SLTexFontChar::tx2
SLfloat tx2
Max. Texture x-coord.
Definition:
SLTexFont.h:64
modules
sl
source
SLTexFont.h
Generated by
1.9.1