37 const char* fragmentShaderFileName,
38 const char* textureFileName,
88 GL_CHECK(glActiveTexture(GL_TEXTURE1));
93 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
94 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
95 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
96 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
102 GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 48, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData));
123 void Text::addString(
int xPosition,
int yPosition,
const char *
string,
int red,
int green,
int blue,
int alpha)
141 LOGE(
"Out of memory at %s:%i\n", __FILE__, __LINE__);
162 for(
int iChar = 0; iChar < (
signed int)strlen(
string); iChar ++)
164 char cChar =
string[iChar];
178 sBottom_left.x = iCharX;
179 sBottom_left.y = iCharY;
181 sBottom_right.y = iCharY;
182 sTop_left.x = iCharX;
188 textVertex[iVertexPos++] = xPosition + iChar * textureCharacterWidth *
scale;
192 textVertex[iVertexPos++] = xPosition + (iChar + 1) * textureCharacterWidth * scale;
194 textVertex[iVertexPos++] = 0;
196 textVertex[iVertexPos++] = xPosition + iChar * textureCharacterWidth *
scale;
197 textVertex[iVertexPos++] = yPosition + textureCharacterHeight *
scale;
198 textVertex[iVertexPos++] = 0;
200 textVertex[iVertexPos++] = xPosition + (iChar + 1) * textureCharacterWidth * scale;
201 textVertex[iVertexPos++] = yPosition + textureCharacterHeight *
scale;
202 textVertex[iVertexPos++] = 0;
218 color[iColorPos ++] = red / 255.0f;
219 color[iColorPos ++] = green / 255.0f;
220 color[iColorPos ++] = blue / 255.0f;
221 color[iColorPos ++] = alpha / 255.0f;
224 memcpy(&
color[iColorPos], &
color[iColorPos - 4], 4 *
sizeof(
float));
225 memcpy(&
color[iColorPos + 4], &
color[iColorPos], 4 *
sizeof(
float));
226 memcpy(&
color[iColorPos + 8], &
color[iColorPos + 4], 4 *
sizeof(
float));
234 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0));
236 if(numberOfCharacters == 0)
266 GL_CHECK(glActiveTexture(GL_TEXTURE0));
269 GL_CHECK(glDrawElements(GL_TRIANGLE_STRIP, numberOfCharacters * 6 - 2, GL_UNSIGNED_SHORT,
textIndex));
float * textTextureCoordinates
Text(const char *resourceDirectory, int windowWidth, int windowHeight)
Constructor for Text.
static const float scale
Scaling factor to use when rendering the text.
struct AstcTextures::Vec2 Vec2
Type representing texture coordinates.
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.
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.
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.