OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AstcTextures::Text Class Reference

Functions for drawing text in OpenGL ES. More...

#include <Text.h>

Public Member Functions

 Text (const char *resourceDirectory, int windowWidth, int windowHeight)
 Constructor for Text. More...
 
 Text (void)
 Overloaded default constructor. More...
 
 ~Text (void)
 Overloaded default destructor. More...
 
void clear (void)
 Removes the current string from the class. More...
 
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. More...
 
void draw (void)
 Draw the text to the screen. More...
 
 Text (const char *resourceDirectory, int windowWidth, int windowHeight)
 Constructor for Text. More...
 
 Text (void)
 Overloaded default constructor. More...
 
 ~Text (void)
 Overloaded default destructor. More...
 
void clear (void)
 Removes the current string from the class. More...
 
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. More...
 
void draw (void)
 Draw the text to the screen. More...
 
 Text (const char *resourceDirectory, int windowWidth, int windowHeight)
 Constructor for Text. More...
 
 Text (void)
 Overloaded default constructor. More...
 
 ~Text (void)
 Overloaded default destructor. More...
 
void clear (void)
 Removes the current string from the class. More...
 
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. More...
 
void draw (void)
 Draw the text to the screen. More...
 

Static Public Attributes

static const int textureCharacterWidth = 8
 The width (in pixels) of the characters in the text texture. More...
 
static const int textureCharacterHeight = 16
 The height (in pixels) of the characters in the text texture. More...
 

Private Attributes

Matrix projectionMatrix
 
int numberOfCharacters
 
floattextVertex
 
floattextTextureCoordinates
 
floatcolor
 
GLshort * textIndex
 
int m_iLocPosition
 
int m_iLocProjection
 
int m_iLocTextColor
 
int m_iLocTexCoord
 
int m_iLocTexture
 
GLuint vertexShaderID
 
GLuint fragmentShaderID
 
GLuint programID
 
GLuint textureID
 

Static Private Attributes

static const char textureFilename [] = "font.raw"
 
static const char vertexShaderFilename []
 
static const char fragmentShaderFilename []
 
static const float scale = 1.0f
 Scaling factor to use when rendering the text. More...
 

Detailed Description

Functions for drawing text in OpenGL ES.

Uses a texture with images of alphanumeric and punctuation symbols. The class converts strings into texture coordinates in order to render the correct symbol from the texture for each character of the string.

Definition at line 89 of file Text.h.

Constructor & Destructor Documentation

AstcTextures::Text::Text ( const char *  resourceDirectory,
int  windowWidth,
int  windowHeight 
)

Constructor for Text.

Parameters
[in]resourceDirectoryPath to the resources. Where the textures and shaders are located.
[in]windowWidthThe width of the window (in pixles) that the text is being used in.
[in]windowHeightThe height of the window (in pixles) that the text is being used in.

Definition at line 73 of file Text.cpp.

AstcTextures::Text::Text ( void  )

Overloaded default constructor.

Definition at line 310 of file Text.cpp.

AstcTextures::Text::~Text ( void  )

Overloaded default destructor.

Definition at line 325 of file Text.cpp.

AstcTextures::Text::Text ( const char *  resourceDirectory,
int  windowWidth,
int  windowHeight 
)

Constructor for Text.

Parameters
[in]resourceDirectoryPath to the resources. Where the textures and shaders are located.
[in]windowWidthThe width of the window (in pixles) that the text is being used in.
[in]windowHeightThe height of the window (in pixles) that the text is being used in.
AstcTextures::Text::Text ( void  )

Overloaded default constructor.

AstcTextures::Text::~Text ( void  )

Overloaded default destructor.

AstcTextures::Text::Text ( const char *  resourceDirectory,
int  windowWidth,
int  windowHeight 
)

Constructor for Text.

Parameters
[in]resourceDirectoryPath to the resources. Where the textures and shaders are located.
[in]windowWidthThe width of the window (in pixles) that the text is being used in.
[in]windowHeightThe height of the window (in pixles) that the text is being used in.
AstcTextures::Text::Text ( void  )

Overloaded default constructor.

AstcTextures::Text::~Text ( void  )

Overloaded default destructor.

Member Function Documentation

void AstcTextures::Text::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.

Parameters
[in]xPositionThe X position (in pixels) to start drawing the text. Measured from the left of the screen.
[in]yPositionThe Y position (in pixels) to start drawing the text. Measured from the bottom of the screen.
[in]stringThe string to be rendered on the screen.
[in]redThe red component of the text colour (accepts values 0-255).
[in]greenThe green component of the text colour (accepts values 0-255).
[in]blueThe blue component of the text colour (accepts values 0-255).
[in]alphaThe alpha component of the text colour (accepts values 0-255). Affects the transparency of the text.

Definition at line 153 of file Text.cpp.

void AstcTextures::Text::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.

Parameters
[in]xPositionThe X position (in pixels) to start drawing the text. Measured from the left of the screen.
[in]yPositionThe Y position (in pixels) to start drawing the text. Measured from the bottom of the screen.
[in]stringThe string to be rendered on the screen.
[in]redThe red component of the text colour (accepts values 0-255).
[in]greenThe green component of the text colour (accepts values 0-255).
[in]blueThe blue component of the text colour (accepts values 0-255).
[in]alphaThe alpha component of the text colour (accepts values 0-255). Affects the transparency of the text.
void AstcTextures::Text::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.

Parameters
[in]xPositionThe X position (in pixels) to start drawing the text. Measured from the left of the screen.
[in]yPositionThe Y position (in pixels) to start drawing the text. Measured from the bottom of the screen.
[in]stringThe string to be rendered on the screen.
[in]redThe red component of the text colour (accepts values 0-255).
[in]greenThe green component of the text colour (accepts values 0-255).
[in]blueThe blue component of the text colour (accepts values 0-255).
[in]alphaThe alpha component of the text colour (accepts values 0-255). Affects the transparency of the text.
void AstcTextures::Text::clear ( void  )

Removes the current string from the class.

Should be called before adding a new string to render using addString().

void AstcTextures::Text::clear ( void  )

Removes the current string from the class.

Should be called before adding a new string to render using addString().

Definition at line 142 of file Text.cpp.

void AstcTextures::Text::clear ( void  )

Removes the current string from the class.

Should be called before adding a new string to render using addString().

void AstcTextures::Text::draw ( void  )

Draw the text to the screen.

Should be called each time through the render loop so that the text is drawn every frame.

void AstcTextures::Text::draw ( void  )

Draw the text to the screen.

Should be called each time through the render loop so that the text is drawn every frame.

Definition at line 257 of file Text.cpp.

void AstcTextures::Text::draw ( void  )

Draw the text to the screen.

Should be called each time through the render loop so that the text is drawn every frame.

Member Data Documentation

float * AstcTextures::Text::color
private

Definition at line 108 of file Text.h.

static const char AstcTextures::Text::fragmentShaderFilename
staticprivate

Definition at line 94 of file Text.h.

GLuint AstcTextures::Text::fragmentShaderID
private

Definition at line 116 of file Text.h.

int AstcTextures::Text::m_iLocPosition
private

Definition at line 110 of file Text.h.

int AstcTextures::Text::m_iLocProjection
private

Definition at line 111 of file Text.h.

int AstcTextures::Text::m_iLocTexCoord
private

Definition at line 113 of file Text.h.

int AstcTextures::Text::m_iLocTextColor
private

Definition at line 112 of file Text.h.

int AstcTextures::Text::m_iLocTexture
private

Definition at line 114 of file Text.h.

int AstcTextures::Text::numberOfCharacters
private

Definition at line 105 of file Text.h.

GLuint AstcTextures::Text::programID
private

Definition at line 117 of file Text.h.

Matrix AstcTextures::Text::projectionMatrix
private

Definition at line 104 of file Text.h.

static const float AstcTextures::Text::scale = 1.0f
staticprivate

Scaling factor to use when rendering the text.

Warning
Experimental: allows drawing characters bigger than the texture was. Range 0.75-3.0 seems to work reasonably.

Definition at line 102 of file Text.h.

GLshort * AstcTextures::Text::textIndex
private

Definition at line 109 of file Text.h.

float * AstcTextures::Text::textTextureCoordinates
private

Definition at line 107 of file Text.h.

static const int AstcTextures::Text::textureCharacterHeight = 16
static

The height (in pixels) of the characters in the text texture.

Warning
Change only if the text texture is changed and the height of the characters is different.

Definition at line 131 of file Text.h.

static const int AstcTextures::Text::textureCharacterWidth = 8
static

The width (in pixels) of the characters in the text texture.

Warning
Change only if the text texture is changed and the width of the characters is different.

Definition at line 125 of file Text.h.

static const char AstcTextures::Text::textureFilename = "font.raw"
staticprivate

Definition at line 92 of file Text.h.

GLuint AstcTextures::Text::textureID
private

Definition at line 118 of file Text.h.

float * AstcTextures::Text::textVertex
private

Definition at line 106 of file Text.h.

static const char AstcTextures::Text::vertexShaderFilename
staticprivate

Definition at line 93 of file Text.h.

GLuint AstcTextures::Text::vertexShaderID
private

Definition at line 115 of file Text.h.


The documentation for this class was generated from the following files: