OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Skybox::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...
 

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 107 of file Text.h.

Constructor & Destructor Documentation

Skybox::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 101 of file Text.cpp.

Skybox::Text::Text ( void  )

Overloaded default constructor.

Definition at line 338 of file Text.cpp.

Skybox::Text::~Text ( void  )

Overloaded default destructor.

Definition at line 353 of file Text.cpp.

Member Function Documentation

void Skybox::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 181 of file Text.cpp.

void Skybox::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 170 of file Text.cpp.

void Skybox::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 285 of file Text.cpp.

Member Data Documentation

float* Skybox::Text::color
private

Definition at line 126 of file Text.h.

const char Skybox::Text::fragmentShaderFilename[]
staticprivate

Definition at line 112 of file Text.h.

GLuint Skybox::Text::fragmentShaderID
private

Definition at line 134 of file Text.h.

int Skybox::Text::m_iLocPosition
private

Definition at line 128 of file Text.h.

int Skybox::Text::m_iLocProjection
private

Definition at line 129 of file Text.h.

int Skybox::Text::m_iLocTexCoord
private

Definition at line 131 of file Text.h.

int Skybox::Text::m_iLocTextColor
private

Definition at line 130 of file Text.h.

int Skybox::Text::m_iLocTexture
private

Definition at line 132 of file Text.h.

int Skybox::Text::numberOfCharacters
private

Definition at line 123 of file Text.h.

GLuint Skybox::Text::programID
private

Definition at line 135 of file Text.h.

Matrix Skybox::Text::projectionMatrix
private

Definition at line 122 of file Text.h.

const float Skybox::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 120 of file Text.h.

GLshort* Skybox::Text::textIndex
private

Definition at line 127 of file Text.h.

float* Skybox::Text::textTextureCoordinates
private

Definition at line 125 of file Text.h.

const int Skybox::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 149 of file Text.h.

const int Skybox::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 143 of file Text.h.

const char Skybox::Text::textureFilename = "font.raw"
staticprivate

Definition at line 110 of file Text.h.

GLuint Skybox::Text::textureID
private

Definition at line 136 of file Text.h.

float* Skybox::Text::textVertex
private

Definition at line 124 of file Text.h.

const char Skybox::Text::vertexShaderFilename[]
staticprivate

Definition at line 111 of file Text.h.

GLuint Skybox::Text::vertexShaderID
private

Definition at line 133 of file Text.h.


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