73 LOGE(
"Attribute not found at %s:%i\n", __FILE__, __LINE__);
81 LOGE(
"Attribute not found at %s:%i\n", __FILE__, __LINE__);
89 LOGE(
"Attribute not found at %s:%i\n", __FILE__, __LINE__);
97 LOGE(
"Warning: Uniform not found at %s:%i\n", __FILE__, __LINE__);
109 LOGE(
"Warning: Uniform not found at %s:%i\n", __FILE__, __LINE__);
117 GL_CHECK(glActiveTexture(GL_TEXTURE0));
121 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
122 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
123 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
124 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
130 GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 48, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData));
150 void Text::addString(
int xPosition,
int yPosition,
const char *
string,
int red,
int green,
int blue,
int alpha)
168 LOGE(
"Out of memory at %s:%i\n", __FILE__, __LINE__);
189 for(
int iChar = 0; iChar < (
signed int)strlen(
string); iChar ++)
191 char cChar =
string[iChar];
205 sBottom_left.x = iCharX;
206 sBottom_left.y = iCharY;
208 sBottom_right.y = iCharY;
209 sTop_left.x = iCharX;
215 textVertex[iVertexPos++] = xPosition + iChar * textureCharacterWidth *
scale;
219 textVertex[iVertexPos++] = xPosition + (iChar + 1) * textureCharacterWidth * scale;
221 textVertex[iVertexPos++] = 0;
223 textVertex[iVertexPos++] = xPosition + iChar * textureCharacterWidth *
scale;
224 textVertex[iVertexPos++] = yPosition + textureCharacterHeight *
scale;
225 textVertex[iVertexPos++] = 0;
227 textVertex[iVertexPos++] = xPosition + (iChar + 1) * textureCharacterWidth * scale;
228 textVertex[iVertexPos++] = yPosition + textureCharacterHeight *
scale;
229 textVertex[iVertexPos++] = 0;
245 color[iColorPos ++] = red / 255.0f;
246 color[iColorPos ++] = green / 255.0f;
247 color[iColorPos ++] = blue / 255.0f;
248 color[iColorPos ++] = alpha / 255.0f;
251 memcpy(&
color[iColorPos], &
color[iColorPos - 4], 4 *
sizeof(
float));
252 memcpy(&
color[iColorPos + 4], &
color[iColorPos], 4 *
sizeof(
float));
253 memcpy(&
color[iColorPos + 8], &
color[iColorPos + 4], 4 *
sizeof(
float));
261 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0));
263 if(numberOfCharacters == 0)
293 GL_CHECK(glActiveTexture(GL_TEXTURE0));
296 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 std::string textureFilename
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.
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.