25 #include "VectorTypes.h"
55 LOGD(
"Text initialization started...\n");
78 LOGE(
"Attribute not found at %s:%i\n", __FILE__, __LINE__);
86 LOGE(
"Attribute not found at %s:%i\n", __FILE__, __LINE__);
94 LOGE(
"Attribute not found at %s:%i\n", __FILE__, __LINE__);
102 LOGD(
"Warning: Uniform not found at %s:%i\n", __FILE__, __LINE__);
114 LOGD(
"Warning: Uniform not found at %s:%i\n", __FILE__, __LINE__);
122 GL_CHECK(glActiveTexture(GL_TEXTURE0));
126 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
127 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
128 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
129 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
135 GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 48, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData));
139 LOGD(
"Text initialization done.\n");
157 void Text::addString(
int xPosition,
int yPosition,
const char *
string,
int red,
int green,
int blue,
int alpha)
159 int length = strlen(
string);
175 LOGE(
"Out of memory at %s:%i\n", __FILE__, __LINE__);
196 for(
int iChar = 0; iChar < (
signed int)strlen(
string); iChar ++)
198 char cChar =
string[iChar];
212 sBottom_left.
x = iCharX;
213 sBottom_left.
y = iCharY;
215 sBottom_right.
y = iCharY;
216 sTop_left.
x = iCharX;
222 textVertex[iVertexPos++] = xPosition + iChar * textureCharacterWidth *
scale;
226 textVertex[iVertexPos++] = xPosition + (iChar + 1) * textureCharacterWidth * scale;
228 textVertex[iVertexPos++] = 0;
230 textVertex[iVertexPos++] = xPosition + iChar * textureCharacterWidth *
scale;
231 textVertex[iVertexPos++] = yPosition + textureCharacterHeight *
scale;
232 textVertex[iVertexPos++] = 0;
234 textVertex[iVertexPos++] = xPosition + (iChar + 1) * textureCharacterWidth * scale;
235 textVertex[iVertexPos++] = yPosition + textureCharacterHeight *
scale;
236 textVertex[iVertexPos++] = 0;
252 color[iColorPos ++] = red / 255.0f;
253 color[iColorPos ++] = green / 255.0f;
254 color[iColorPos ++] = blue / 255.0f;
255 color[iColorPos ++] = alpha / 255.0f;
258 memcpy(&
color[iColorPos], &
color[iColorPos - 4], 4 *
sizeof(
float));
259 memcpy(&
color[iColorPos + 4], &
color[iColorPos], 4 *
sizeof(
float));
260 memcpy(&
color[iColorPos + 8], &
color[iColorPos + 4], 4 *
sizeof(
float));
267 #if GLES_VERSION == 3
269 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0));
301 GL_CHECK(glActiveTexture(GL_TEXTURE0));
float * textTextureCoordinates
Text(const char *resourceDirectory, int windowWidth, int windowHeight)
Constructor for Text.
static const std::string textureFilename
static const float scale
Scaling factor to use when rendering the text.
void clear(void)
Removes the current string from the class.
static Matrix matrixOrthographic(float left, float right, float bottom, float top, float zNear, float zFar)
Create and return an orthographic projection matrix.
static const std::string vertexShaderFilename
float * getAsArray(void)
Get the matrix elements as a column major order array.
static const int textureCharacterHeight
The height (in pixels) of the characters in the text texture.
virtual ~Text(void)
Default destructor.
static const int textureCharacterWidth
The width (in pixels) of the characters in the text texture.
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.
unsigned char * textureData
static void loadData(const char *filename, unsigned char **textureData)
Load texture data from a file into memory.
static const std::string fragmentShaderFilename
GLenum GLuint GLenum GLsizei length
static void processShader(GLuint *shader, const char *filename, GLint shaderType)
Create shader, load in source, compile, and dump debug as necessary.
void draw(void)
Draw the text to the screen.