OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Text.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 #ifndef TEXT_H
22 #define TEXT_H
23 
24 #include "Matrix.h"
25 
26 #include <GLES3/gl3.h>
27 
28 namespace AstcTextures
29 {
33  const char fontVertexShaderSource[] =
34  {
35  "#version 300 es\n"
36  "uniform mat4 u_m4Projection;\n"
37  "in vec4 a_v4Position;\n"
38  "in vec4 a_v4FontColor;\n"
39  "in vec2 a_v2TexCoord;\n"
40  "out vec4 v_v4FontColor;\n"
41  "out vec2 v_v2TexCoord;\n"
42  "void main() {\n"
43  " v_v4FontColor = a_v4FontColor;\n"
44  " v_v2TexCoord = a_v2TexCoord;\n"
45  " gl_Position = u_m4Projection * a_v4Position;\n"
46  "}\n"
47  };
48 
52  const char fontFragmentShaderSource[] =
53  {
54  "#version 300 es\n"
55  "precision mediump float;\n"
56  "uniform sampler2D u_s2dTexture;\n"
57  "in vec2 v_v2TexCoord;\n"
58  "in vec4 v_v4FontColor;\n"
59  "out vec4 color;\n"
60  "void main() {\n"
61  " vec4 v4Texel = texture(u_s2dTexture, v_v2TexCoord);\n"
62  " color = v_v4FontColor * v4Texel;\n"
63  "}\n"
64  };
65 
72  void loadData(const char* filename, unsigned char** textureData);
73 
77  typedef struct Vec2
78  {
79  int x;
80  int y;
81  } Vec2;
82 
89  class Text
90  {
91  private:
92  static const char textureFilename[];
93  static const char vertexShaderFilename[];
94  static const char fragmentShaderFilename[];
95 
102  static const float scale;
103 
106  float* textVertex;
108  float* color;
109  GLshort* textIndex;
119 
120  public:
125  static const int textureCharacterWidth;
126 
131  static const int textureCharacterHeight;
132 
140  Text(const char* resourceDirectory, int windowWidth, int windowHeight);
141 
145  Text(void);
146 
150  ~Text(void);
151 
157  void clear(void);
158 
170  void addString(int xPosition, int yPosition, const char* string, int red, int green, int blue, int alpha);
171 
177  void draw(void);
178  };
179 }
180 #endif /* TEXT_H */
static const char vertexShaderFilename[]
Definition: Text.h:93
const char fontFragmentShaderSource[]
Fragment shader source code for text rendering.
Definition: Text.h:52
void loadData(const char *filename, unsigned char **textureData)
Load texture data from a file into memory.
Definition: Text.cpp:38
float * textVertex
Definition: Text.h:106
int windowWidth
Definition: Cube.cpp:56
Functions for drawing text in OpenGL ES.
Definition: Text.h:89
int m_iLocProjection
Definition: Text.h:111
const char fontVertexShaderSource[]
Vertex shader source code for text rendering.
Definition: Text.h:33
float * textTextureCoordinates
Definition: Text.h:107
Type representing texture coordinates.
Definition: Text.h:77
static const int textureCharacterHeight
The height (in pixels) of the characters in the text texture.
Definition: Text.h:131
void clear(void)
Removes the current string from the class.
Definition: Text.cpp:142
Matrix projectionMatrix
Definition: Text.h:104
Text(void)
Overloaded default constructor.
Definition: Text.cpp:310
struct AstcTextures::Vec2 Vec2
Type representing texture coordinates.
float * color
Definition: Text.h:108
int m_iLocTexCoord
Definition: Text.h:113
static const char textureFilename[]
Definition: Text.h:92
Functions for manipulating matrices.
Definition: Matrix.h:29
int windowHeight
Definition: Cube.cpp:57
int m_iLocTexture
Definition: Text.h:114
int m_iLocPosition
Definition: Text.h:110
GLuint textureID
Definition: Text.h:118
static const int textureCharacterWidth
The width (in pixels) of the characters in the text texture.
Definition: Text.h:125
~Text(void)
Overloaded default destructor.
Definition: Text.cpp:325
GLuint fragmentShaderID
Definition: Text.h:116
int m_iLocTextColor
Definition: Text.h:112
unsigned char * textureData
Definition: ThreadSync.cpp:109
string resourceDirectory
Definition: AntiAlias.cpp:55
static const char fragmentShaderFilename[]
Definition: Text.h:94
GLuint programID
Definition: Text.h:117
static const float scale
Scaling factor to use when rendering the text.
Definition: Text.h:102
void draw(void)
Draw the text to the screen.
Definition: Text.cpp:257
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
GLshort * textIndex
Definition: Text.h:109
GLuint vertexShaderID
Definition: Text.h:115
void addString(int xPosition, int yPosition, const char *string, int red, int green, int blue, int alpha)
Add a std::string to be drawn to the screen.
Definition: Text.cpp:153
int numberOfCharacters
Definition: Text.h:105