OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MaliSDK::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...
 
virtual ~Text (void)
 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 *vertexShaderFileName, const char *fragmentShaderFileName, const char *textureFileName, int windowWidth, int windowHeight)
 Constructor for Text. More...
 
virtual ~Text (void)
 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 text 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...
 
virtual ~Text (void)
 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 std::string textureFilename = "font.raw"
 
static const std::string vertexShaderFilename = "font.vert"
 
static const std::string fragmentShaderFilename = "font.frag"
 
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 44 of file Text.h.

Constructor & Destructor Documentation

MaliSDK::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 43 of file Text.cpp.

MaliSDK::Text::~Text ( void  )
virtual

Default destructor.

Definition at line 322 of file Text.cpp.

MaliSDK::Text::Text ( const char *  vertexShaderFileName,
const char *  fragmentShaderFileName,
const char *  textureFileName,
int  windowWidth,
int  windowHeight 
)

Constructor for Text.

Parameters
[in]vertexShaderFileNameName of a vertex shader file.
[in]fragmentShaderFileNameName of a fragment shader file.
[in]textureFileNameName of a font texture file.
[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 36 of file Text.cpp.

virtual MaliSDK::Text::~Text ( void  )
virtual

Default destructor.

MaliSDK::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.
virtual MaliSDK::Text::~Text ( void  )
virtual

Default destructor.

Member Function Documentation

void MaliSDK::Text::addString ( int  xPosition,
int  yPosition,
const char *  string,
int  red,
int  green,
int  blue,
int  alpha 
)

Add a text 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 MaliSDK::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 MaliSDK::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 157 of file Text.cpp.

void MaliSDK::Text::clear ( void  )

Removes the current string from the class.

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

void MaliSDK::Text::clear ( void  )

Removes the current string from the class.

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

void MaliSDK::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 MaliSDK::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 MaliSDK::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 MaliSDK::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 265 of file Text.cpp.

Member Data Documentation

float * MaliSDK::Text::color
private

Definition at line 65 of file Text.h.

static const std::string MaliSDK::Text::fragmentShaderFilename = "font.frag"
staticprivate

Definition at line 49 of file Text.h.

GLuint MaliSDK::Text::fragmentShaderID
private

Definition at line 73 of file Text.h.

int MaliSDK::Text::m_iLocPosition
private

Definition at line 67 of file Text.h.

int MaliSDK::Text::m_iLocProjection
private

Definition at line 68 of file Text.h.

int MaliSDK::Text::m_iLocTexCoord
private

Definition at line 70 of file Text.h.

int MaliSDK::Text::m_iLocTextColor
private

Definition at line 69 of file Text.h.

int MaliSDK::Text::m_iLocTexture
private

Definition at line 71 of file Text.h.

int MaliSDK::Text::numberOfCharacters
private

Definition at line 62 of file Text.h.

GLuint MaliSDK::Text::programID
private

Definition at line 74 of file Text.h.

Matrix MaliSDK::Text::projectionMatrix
private

Definition at line 61 of file Text.h.

static const float MaliSDK::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 57 of file Text.h.

GLshort * MaliSDK::Text::textIndex
private

Definition at line 66 of file Text.h.

float * MaliSDK::Text::textTextureCoordinates
private

Definition at line 64 of file Text.h.

static const int MaliSDK::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 89 of file Text.h.

static const int MaliSDK::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 83 of file Text.h.

static const std::string MaliSDK::Text::textureFilename = "font.raw"
staticprivate

Definition at line 47 of file Text.h.

GLuint MaliSDK::Text::textureID
private

Definition at line 75 of file Text.h.

float * MaliSDK::Text::textVertex
private

Definition at line 63 of file Text.h.

static const std::string MaliSDK::Text::vertexShaderFilename = "font.vert"
staticprivate

Definition at line 48 of file Text.h.

GLuint MaliSDK::Text::vertexShaderID
private

Definition at line 72 of file Text.h.


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