1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-08 03:42:35 +01:00
openrw/rwengine/include/render/TextRenderer.hpp

76 lines
1.4 KiB
C++
Raw Normal View History

2015-02-07 23:55:06 +01:00
#pragma once
#include <engine/GameData.hpp>
#include "OpenGLRenderer.hpp"
#define GAME_FONTS 3
#define GAME_GLYPHS 192
2015-02-07 23:55:06 +01:00
class GameRenderer;
/**
* @brief Handles rendering of bitmap font textures.
*
* In future, strings textures might be cached to improve performance, but
* for now, we just render each glyph on it's own quad
*/
class TextRenderer
{
public:
/**
* @todo Can this be merged with the gamestate text entries?
*/
struct TextInfo
{
enum TextAlignemnt
{
Left = 0,
Right = 1,
Center = 2
};
2015-02-07 23:55:06 +01:00
/// Font index @see TextRenderer::setFontTexture
int font;
/// Message to be displayed (including markup)
std::string text;
/// On screen position
glm::vec2 screenPosition;
/// font size
float size;
/// Base colour
glm::u8vec3 baseColour;
/// Background colour
glm::u8vec4 backgroundColour;
/// Horizontal Alignment
TextAlignemnt align;
/// Wrap width
int wrapX;
2015-02-07 23:55:06 +01:00
TextInfo();
};
/**
* Stores the information for kerning a glyph
*/
struct GlyphInfo
{
float widthFrac;
};
TextRenderer(GameRenderer* renderer);
2015-02-07 23:55:06 +01:00
~TextRenderer();
void setFontTexture( int index, const std::string& font );
void renderText( const TextInfo& ti, bool forceColour = false );
2015-02-07 23:55:06 +01:00
private:
std::string fonts[GAME_FONTS];
GlyphInfo glyphData[GAME_GLYPHS];
2015-02-07 23:55:06 +01:00
GameRenderer* renderer;
Renderer::ShaderProgram* textShader;
GeometryBuffer gb;
DrawBuffer db;
};