|
libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
|
Render SDL_ttf text into an OpenGL texture and display it on screen. More...
#include <gl.hpp>
Public Member Functions | |
| GLText () | |
| Default constructor. | |
| void | init (int w, int h) |
| Initialise internal state with the viewport dimensions. | |
| GLuint | createText (const std::string &text, TTF_Font *font, SDL_Color color, int &textWidth, int &textHeight, bool solid=true) |
| Rasterise a string to an OpenGL texture. | |
| void | renderText (GLuint texture, float x, float y, int textWidth, int textHeight, int screenWidth, int screenHeight) |
| Draw a pre-created text texture at a given position. | |
| void | printText_Solid (const mx::Font &f, float x, float y, const std::string &text) |
| Convenience: create and immediately draw solid text. | |
| void | printText_Blended (const mx::Font &f, float x, float y, const std::string &text) |
| Convenience: create and immediately draw blended (anti-aliased) text. | |
| void | setColor (SDL_Color col) |
| Set the colour used for subsequent printText calls. | |
Private Attributes | |
| ShaderProgram | textShader |
| Internal text quad shader. | |
| SDL_Color | color = {255,255,255,255} |
| Current text colour. | |
| int | w = 0 |
| int | h = 0 |
| Viewport dimensions. | |
Render SDL_ttf text into an OpenGL texture and display it on screen.
Manages a simple text shader and provides helpers that rasterise a string to an SDL_Surface, upload it as an OpenGL texture, and draw a screen-space quad at the specified position.
| GLuint gl::GLText::createText | ( | const std::string & | text, |
| TTF_Font * | font, | ||
| SDL_Color | color, | ||
| int & | textWidth, | ||
| int & | textHeight, | ||
| bool | solid = true ) |
Rasterise a string to an OpenGL texture.
| text | String to render. |
| font | SDL_ttf font handle. |
| color | Text colour. |
| textWidth | Output: texture pixel width. |
| textHeight | Output: texture pixel height. |
| solid | If true, use solid (fast) rendering; otherwise blended. |
Definition at line 898 of file gl.cpp.
References color, mx::Texture::flipSurface(), and mx::system_err.
Referenced by printText_Blended(), and printText_Solid().
| void gl::GLText::init | ( | int | w, |
| int | h ) |
Initialise internal state with the viewport dimensions.
Definition at line 885 of file gl.cpp.
References gl::ftSource, h, textShader, gl::vSource, and w.
| void gl::GLText::printText_Blended | ( | const mx::Font & | f, |
| float | x, | ||
| float | y, | ||
| const std::string & | text ) |
Convenience: create and immediately draw blended (anti-aliased) text.
| f | mx::Font reference. |
| x | X position. |
| y | Y position. |
| text | String to render. |
Definition at line 984 of file gl.cpp.
References color, createText(), h, renderText(), textShader, w, and mx::Font::wrapper().
| void gl::GLText::printText_Solid | ( | const mx::Font & | f, |
| float | x, | ||
| float | y, | ||
| const std::string & | text ) |
Convenience: create and immediately draw solid text.
| f | mx::Font reference. |
| x | X position. |
| y | Y position. |
| text | String to render. |
Definition at line 970 of file gl.cpp.
References color, createText(), h, renderText(), textShader, w, and mx::Font::wrapper().
| void gl::GLText::renderText | ( | GLuint | texture, |
| float | x, | ||
| float | y, | ||
| int | textWidth, | ||
| int | textHeight, | ||
| int | screenWidth, | ||
| int | screenHeight ) |
Draw a pre-created text texture at a given position.
| texture | GL texture ID from createText(). |
| x | Destination X (pixels). |
| y | Destination Y (pixels). |
| textWidth | Texture pixel width. |
| textHeight | Texture pixel height. |
| screenWidth | Current viewport width. |
| screenHeight | Current viewport height. |
Definition at line 939 of file gl.cpp.
References h, textShader, and w.
Referenced by printText_Blended(), and printText_Solid().
| void gl::GLText::setColor | ( | SDL_Color | col | ) |
|
private |
Current text colour.
Definition at line 242 of file gl.hpp.
Referenced by createText(), printText_Blended(), printText_Solid(), and setColor().
|
private |
Viewport dimensions.
Definition at line 243 of file gl.hpp.
Referenced by init(), printText_Blended(), printText_Solid(), and renderText().
|
private |
Internal text quad shader.
Definition at line 241 of file gl.hpp.
Referenced by init(), printText_Blended(), printText_Solid(), and renderText().
|
private |
Definition at line 243 of file gl.hpp.
Referenced by init(), printText_Blended(), printText_Solid(), and renderText().