NGL  6.5
The NCCA Graphics Library
ngl::Text Class Reference

#include <Text.h>

+ Collaboration diagram for ngl::Text:

Public Member Functions

 Text (const QFont &_f) noexcept
 ctor must pass in a ready constructed QFont make sure the size and emphasis is set before doing this as you can't modify the font after construction and you will need a new Text class for each different type of text / font More...
 
 ~Text ()
 dtor will clean / remove textures and VAO's for the class More...
 
void renderText (float _x, float _y, const QString &_text) const noexcept
 render the text to the screen at _x,_y where 0,0 is top left of the screen all positioning is relative to the screen size set with the setScreenSize method so it is important that changes in screen size are updated. These value will be sent to the nglTextShader to be rendered (see source ) More...
 
void setScreenSize (int _w, int _h) noexcept
 set the size of the screen to scale our font to fit correctly this basically creates the orthographic projection needed for x/y assuming that the openGL window has 0,0 at the center and we use NDC co-ordinates -1 -> 1 in X and Y we then get x=(x*xScale)+xtran y=(y*yScale)+ytrans; to place the text in screen space More...
 
void setColour (const Colour &_c) noexcept
 set the colour of the font from an Colour More...
 
void setColour (Real _r, Real _g, Real _b) noexcept
 set the colour of the font from three floats as a convenience method More...
 
void setTransform (float _x, float _y) noexcept
 

Protected Attributes

QHash< char, FontCharm_characters
 a hash to store our FontChar data looked up by the char we want to render according to the Qt Docs a hash has faster lookups than QMap so using this More...
 

Detailed Description

Definition at line 65 of file Text.h.

Constructor & Destructor Documentation

ngl::Text::Text ( const QFont &  _f)
noexcept

ctor must pass in a ready constructed QFont make sure the size and emphasis is set before doing this as you can't modify the font after construction and you will need a new Text class for each different type of text / font

Parameters
[in]_fthe font to use for drawing the text

Definition at line 53 of file Text.cpp.

References ngl::AbstractVAO::bind(), ngl::VAOFactory::createVAO(), GL_FLOAT, GL_LINEAR, GL_NEAREST_MIPMAP_LINEAR, GL_RGBA, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_TRIANGLES, GL_UNSIGNED_BYTE, glBindTexture(), glGenerateMipmap, glGenTextures(), glTexImage2D(), glTexParameteri(), std::move(), ngl::nearestPowerOfTwo(), ngl::AbstractVAO::setData(), ngl::AbstractVAO::setNumIndices(), ngl::AbstractVAO::setVertexAttributePointer(), ngl::FontChar::textureID, ngl::AbstractVAO::unbind(), ngl::FontChar::vao, and ngl::FontChar::width.

+ Here is the call graph for this function:

ngl::Text::~Text ( )

dtor will clean / remove textures and VAO's for the class

Definition at line 250 of file Text.cpp.

References glDeleteTextures().

+ Here is the call graph for this function:

Member Function Documentation

void ngl::Text::renderText ( float  _x,
float  _y,
const QString &  _text 
) const
noexcept

render the text to the screen at _x,_y where 0,0 is top left of the screen all positioning is relative to the screen size set with the setScreenSize method so it is important that changes in screen size are updated. These value will be sent to the nglTextShader to be rendered (see source )

Note
font quad is drawn as 0,0 being bottom left so if we draw at 0,0 the font will not be visible, we need to add the offset of the font height to any y value (i.e. a 16pt font drawn at 0,16 will appear at top right of the screen)
Parameters
[in]_xthe x position of the text in screen space
[in]_ythe y position of the text in screen space
[in]_textthe text to draw (this is limited to ASCII chars ' '->'~' at present but unicode will be done soon

Definition at line 265 of file Text.cpp.

References ngl::AbstractVAO::bind(), ngl::AbstractVAO::draw(), GL_BLEND, GL_DEPTH_TEST, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_TEXTURE0, GL_TEXTURE_2D, glActiveTexture, glBindTexture(), glBlendFunc(), glDisable(), glEnable(), ngl::Singleton< ShaderLib >::instance(), ngl::ShaderLib::setRegisteredUniform1f(), ngl::FontChar::textureID, ngl::AbstractVAO::unbind(), ngl::FontChar::vao, and ngl::FontChar::width.

+ Here is the call graph for this function:

void ngl::Text::setColour ( const Colour _c)
noexcept

set the colour of the font from an Colour

Parameters
[in]_cthe colour to set for the font (alpha is overridden by the texture)

Definition at line 340 of file Text.cpp.

References ngl::Singleton< ShaderLib >::instance(), and ngl::ShaderLib::setRegisteredUniform3f().

+ Here is the call graph for this function:

void ngl::Text::setColour ( Real  _r,
Real  _g,
Real  _b 
)
noexcept

set the colour of the font from three floats as a convenience method

Parameters
[in]_rthe red component of the colour for the font
[in]_gthe green component of the colour for the font
[in]_bthe blue component of the colour for the font

Definition at line 352 of file Text.cpp.

References ngl::Singleton< ShaderLib >::instance(), and ngl::ShaderLib::setRegisteredUniform3f().

+ Here is the call graph for this function:

void ngl::Text::setScreenSize ( int  _w,
int  _h 
)
noexcept

set the size of the screen to scale our font to fit correctly this basically creates the orthographic projection needed for x/y assuming that the openGL window has 0,0 at the center and we use NDC co-ordinates -1 -> 1 in X and Y we then get x=(x*xScale)+xtran y=(y*yScale)+ytrans; to place the text in screen space

Parameters
[in]_wthe current width of the screen
[in]_hthe current height of the screen

Definition at line 314 of file Text.cpp.

References ngl::Singleton< ShaderLib >::instance(), and ngl::ShaderLib::setRegisteredUniform1f().

+ Here is the call graph for this function:

void ngl::Text::setTransform ( float  _x,
float  _y 
)
noexcept

Definition at line 361 of file Text.cpp.

References ngl::Singleton< ShaderLib >::instance(), and ngl::ShaderLib::setRegisteredUniform2f().

+ Here is the call graph for this function:

Member Data Documentation

QHash<char,FontChar> ngl::Text::m_characters
protected

a hash to store our FontChar data looked up by the char we want to render according to the Qt Docs a hash has faster lookups than QMap so using this

Definition at line 121 of file Text.h.


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