Elaztek Developer Hub
Blamite Game Engine - blam!  00453.06.08.26.0624.blamite
The core library for the Blamite Game Engine.
fonts.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <d2d1.h>
4 #include <map>
5 #include <Windows.h>
6 #include <string>
7 #include <OGRE/OgreTextureGpu.h>
8 #include <OGRE/Overlay/OgreFont.h>
9 #include <bgfx/bgfx.h>
10 #include <Strings/components/classes/map/map.h>
11 #include <Strings/components/classes/vector/vector.h>
12 #include <Strings/components/diagnostics/errors/errors.h>
13 #include <Strings/components/resources/color/BlamColor.h>
14 
15 #ifndef BLAM
16 #define BLAM
17 #endif
18 
19 #define FONT_TABLE_FILE "font_table.txt"
20 
21 #define FONTINFO_FILENAME "fontinfo.xml"
22 #define FONT_PACKAGE_EXTENSION ".bin"
23 #define FONT_PACKAGE_VERSION 2
24 
25 
29 {
30  Unknown,
31  Bitmap,
32  BitmapAtlas,
33  TrueType,
34  XMLBitmap,
36  XMLTruetype,
37 };
38 
45 {
46 public:
47  char character = 0x00;
48 
49  bool override_filtering = false;
50 
54  bool use_point_filtering = false;
55 
58 
61 
62  BlamVector4 uv = { 0, 0, 0, 0 };
63 
64  bgfx::TextureHandle glyph_texture_bgfx = { bgfx::kInvalidHandle };
65 
66  Ogre::TextureGpu* glyph_texture = nullptr;
67  Ogre::HlmsDatablock* glyph_datablock = nullptr;
68 
80  Ogre::HlmsDatablock* CreateCopiedDatablock();
81 };
82 
90 {
91 public:
92  std::string name = "";
93  std::string file_path = "";
95  BlamMap<char, BlamFontGlyph*> glyphs = BlamMap<char, BlamFontGlyph*>();
96 
97  bool monospace = false;
98  int monospace_width = 0;
99  int charspacing = 0;
100  int line_height = 0;
101  int space_width = 0;
102  bool use_point_filtering = false;
103 
106 
107  bgfx::TextureHandle font_atlas_bgfx = { bgfx::kInvalidHandle };
108 
109  Ogre::TextureGpu* font_atlas = nullptr;
110  Ogre::HlmsDatablock* font_datablock = nullptr;
111  Ogre::FontPtr ttf_font;
112 
118  BlamFontPackage();
119 
124 
133  BlamFontGlyph* GetGlyph(char character);
134 
146  Ogre::HlmsDatablock* CreateCopiedDatablock();
147 };
148 
155 {
159  BLAM void LoadAllFonts();
160 
168  BLAM BlamResult LoadFontDirectory(std::string directory);
169 
179  BLAM BlamResult LoadFontPackage(std::string file);
180 
184  BLAM BlamResult LoadFont(std::string font_name);
185 
193  BLAM BlamMap<std::string, BlamFontPackage*> GetFontList();
194 
202  BLAM bool FontExists(std::string id);
203 
211  BLAM BlamFontPackage* GetFont(std::string id);
212 
216  BLAM void Cleanup();
217 }
218 
Blam::Rendering::Materials::CreateDefaultUnlitDatablockForPrimitives
BLAM Ogre::HlmsUnlitDatablock * CreateDefaultUnlitDatablockForPrimitives(std::string id)
Creates a default Unlit datablock for use with 2D and 3D primitives.
Definition: materials.cpp:1032
Blam::Settings::Paths::GetDefaultEngineDataPath
BLAM std::string GetDefaultEngineDataPath(BlamEngineDataFolder folder)
Retrieves a default value of a given engine data directory.
Definition: paths.cpp:142
BlamFontPackage::BlamFontPackage
BlamFontPackage()
Constructor.
Definition: BlamFontPackage.cpp:7
Blam::Logger::LogEvent
BLAM void LogEvent(std::string message)
Logs a message to the log and/or console.
Definition: aliases.cpp:130
Blam::Rendering::Materials::CreateDefaultUnlitDatablock
BLAM Ogre::HlmsUnlitDatablock * CreateDefaultUnlitDatablock(std::string id)
Creates a default Unlit datablock.
Definition: materials.cpp:1021
Blam::Content::Fonts::FontExists
BLAM bool FontExists(std::string id)
Checks if a font package exists with a given name.
Definition: fonts.cpp:803
BlamFontPackageType::TrueType
@ TrueType
Indicates that the font package stores a TrueType (or similar) font directly.
BlamFontPackage::use_point_filtering
bool use_point_filtering
Whether or not glyphs in this font package should use point filtering or not.
Definition: fonts.h:102
logger.h
BlamFontGlyph::glyph_texture
Ogre::TextureGpu * glyph_texture
The texture for the glyph. Only used in non-atlas bitmap fonts.
Definition: fonts.h:66
BlamFontPackage::name
std::string name
The name/ID of the font. Must be unique.
Definition: fonts.h:92
BlamFontPackage
Class representing a Blamite font package.
Definition: fonts.h:89
BlamFontGlyph::index_y
uint16_t index_y
The Y index of the glyph within the font atlas texture.
Definition: fonts.h:60
BlamFontGlyph::glyph_datablock
Ogre::HlmsDatablock * glyph_datablock
The datablock for the glyph. Only used in non-atlas bitmap fonts.
Definition: fonts.h:67
BlamFontPackageType::Unknown
@ Unknown
Indicates the font package has an unknown type. Should generally be considered an error.
BLAM
#define BLAM
Definition: fonts.h:16
BlamFontPackage::file_path
std::string file_path
The file path of the font information or package file.
Definition: fonts.h:93
UsingBgfx
bool UsingBgfx()
Definition: bgfx.cpp:63
Blam::Content::Fonts::LoadFont
BLAM BlamResult LoadFont(std::string font_name)
Definition: fonts.cpp:793
BlamFontPackage::GetGlyph
BlamFontGlyph * GetGlyph(char character)
Retrieves font glyph information from a character.
Definition: BlamFontPackage.cpp:23
BlamFontPackage::~BlamFontPackage
~BlamFontPackage()
Destructor.
Definition: BlamFontPackage.cpp:12
Blam::Content::Fonts::Cleanup
BLAM void Cleanup()
Releases all font package data from memory.
Definition: fonts.cpp:818
BlamFontGlyph::use_point_filtering
bool use_point_filtering
Whether or not this glyph should use point filtering.
Definition: fonts.h:54
glyph_attribute_test_int
int glyph_attribute_test_int(bool *out_result, std::string glyph_name, std::string font_name, std::string attribute_name, rapidxml::xml_attribute<> *attribute)
A helper function used to check if a glyph attribute's value is an integer or not.
Definition: fonts.cpp:73
glyph_attribute_test_float
float glyph_attribute_test_float(bool *out_result, std::string glyph_name, std::string font_name, std::string attribute_name, rapidxml::xml_attribute<> *attribute)
A helper function used to check if a glyph attribute's value is a float or not.
Definition: fonts.cpp:106
BlamEngineDataFolder::Fonts
@ Fonts
Directory used for game engine fonts. Defaults to ./maps/fonts/
BlamFontPackage::glyphs
BlamMap< char, BlamFontGlyph * > glyphs
Map containing all glyphs within the font package.
Definition: fonts.h:95
Blam::Content::Fonts::GetFont
BLAM BlamFontPackage * GetFont(std::string id)
Retrieves a font package from its name.
Definition: fonts.cpp:808
rendering.h
BlamFontPackage::glyphs_per_column
uint32_t glyphs_per_column
The number of glyphs per column within the texture atlas. Only used in fonts that use a texture atlas...
Definition: fonts.h:105
BlamFontGlyph::height
uint32_t height
The height of the glyph texture.
Definition: fonts.h:57
BlamFontGlyph::glyph_texture_bgfx
bgfx::TextureHandle glyph_texture_bgfx
Definition: fonts.h:64
BlamFontPackage::monospace_width
int monospace_width
The monospaced width of each character. Only used when monospace is set to true.
Definition: fonts.h:98
BlamFontGlyph::width
uint32_t width
The width of the glyph texture.
Definition: fonts.h:56
BlamFontPackageType
BlamFontPackageType
Enumerator listing all possible font package types.
Definition: fonts.h:28
BlamFontPackage::CreateCopiedDatablock
Ogre::HlmsDatablock * CreateCopiedDatablock()
Creates a copy of this glyph's datablock, intended to allow for it to be recolored on a per-instance ...
Definition: BlamFontPackage.cpp:33
uint64_t
unsigned long long uint64_t
Definition: stdint.h:18
Blam::Rendering::Textures::LoadTexture2D
BLAM Ogre::TextureGpu * LoadTexture2D(std::string id, void *pixel_data, int width, int height, Ogre::PixelFormatGpu format, int bytes_per_line)
Loads a 2D texture from data in memory.
Definition: textures.cpp:156
BlamFontPackage::font_datablock
Ogre::HlmsDatablock * font_datablock
The font atlas datablock. Only used in fonts that use a texture atlas.
Definition: fonts.h:110
BlamFontGlyph
Class representing a font glyph.
Definition: fonts.h:44
Blam::RenderingBGFX::Textures::LoadTexture2D
BLAM bgfx::TextureHandle LoadTexture2D(std::string id, void *pixel_data, int width, int height, bgfx::TextureFormat::Enum format, int bytes_per_line, uint64_t flags=0)
Loads a 2D texture from data in memory.
Definition: bitmaps.cpp:515
Blam::Content::Fonts::LoadFontPackage
BLAM BlamResult LoadFontPackage(std::string file)
Attempts to load a font package from a file.
Definition: fonts.cpp:162
ENGINE_DATA_PATH
#define ENGINE_DATA_PATH(path)
Macro to quickly access a game engine data folder.
Definition: config.h:34
font_map
BlamMap< std::string, BlamFontPackage * > font_map
Definition: fonts.cpp:18
BlamFontPackageType::XMLBitmapAtlas
@ XMLBitmapAtlas
Identical to #BitmapAtlas, but indicates that the font package is unpacked.
BlamFontPackage::type
BlamFontPackageType type
The format of the font pacakge. See BlamFontPackageType for details.
Definition: fonts.h:94
BlamFontPackage::line_height
int line_height
The height of each line of text, in pixels.
Definition: fonts.h:100
BlamFontPackage::font_atlas
Ogre::TextureGpu * font_atlas
The font atlas texture. Only used in fonts that use a texture atlas.
Definition: fonts.h:109
BlamFontPackageType::XMLBitmap
@ XMLBitmap
Identical to #Bitmap, but indicates that the font package is unpacked.
Blam::Content::Fonts::GetFontList
BLAM BlamMap< std::string, BlamFontPackage * > GetFontList()
Retrieves the map of all available fonts.
Definition: fonts.cpp:798
BlamFontGlyph::character
char character
The character that this glyph represents.
Definition: fonts.h:47
uint32_t
unsigned int uint32_t
Definition: stdint.h:17
BlamFontPackage::monospace
bool monospace
Whether or not the font is monospaced.
Definition: fonts.h:97
BlamFontGlyph::uv
BlamVector4 uv
The UV coordinates of the font glyph.
Definition: fonts.h:62
file
sock planetquake com All rights reserved Quake III Arena is a registered trademark of id Inc This level may be electronically distributed only at NO CHARGE to the recipient in its current MUST include this txt file
Definition: chiropteraDM.txt:95
BlamFontPackage::font_atlas_bgfx
bgfx::TextureHandle font_atlas_bgfx
Definition: fonts.h:107
BlamFontGlyph::CreateCopiedDatablock
Ogre::HlmsDatablock * CreateCopiedDatablock()
Creates a copy of this glyph's datablock, intended to allow for it to be recolored on a per-instance ...
Definition: BlamFontGlyph.cpp:7
BlamFontGlyph::index_x
uint16_t index_x
The X index of the glyph within the font atlas texture.
Definition: fonts.h:59
resolve_glyph_character
bool resolve_glyph_character(std::string xml_glyph, char *character)
Identify the character of the font glyph from the XML attribute.
Definition: fonts.cpp:28
BlamFontPackageType::XMLTruetype
@ XMLTruetype
Identical to #Truetype, but indicates that the font package is unpacked.
Blam::Content::Fonts::LoadFontDirectory
BLAM BlamResult LoadFontDirectory(std::string directory)
Attempts to load an unpackaged (XML) font from a directory.
Definition: fonts.cpp:167
BlamFontPackageType::Bitmap
@ Bitmap
Indicates that the font package stores glyphs in separate bitmaps.
config.h
BlamFontPackage::ttf_font
Ogre::FontPtr ttf_font
Unused.
Definition: fonts.h:111
fonts.h
BlamFontPackage::glyphs_per_row
uint32_t glyphs_per_row
The number of glyphs per row within the texture atlas. Only used in fonts that use a texture atlas.
Definition: fonts.h:104
Blam::Content::Fonts
Namespace containing functions for interacting with font packages.
Definition: fonts.h:154
BlamFontGlyph::override_filtering
bool override_filtering
Whether or not to override the font package texture filtering mode.
Definition: fonts.h:49
BlamFontPackage::charspacing
int charspacing
The amount of spacing between each character, in pixels.
Definition: fonts.h:99
uint16_t
unsigned short uint16_t
Definition: stdint.h:16
font
io.Fonts->AddFontFromMemoryCompressedTTF(compressed_data, compressed_data_size, size_pixels,...) font
Definition: README.txt:86
BlamFontPackage::space_width
int space_width
The width of the space character, in pixels. Only used when monospace is false.
Definition: fonts.h:101
FONTINFO_FILENAME
#define FONTINFO_FILENAME
The default filename for XML (unpacked) font information.
Definition: fonts.h:21
Blam::Content::Fonts::LoadAllFonts
BLAM void LoadAllFonts()
Loads all available font packages within the fonts directory.
Definition: fonts.cpp:127
BlamFontPackageType::BitmapAtlas
@ BitmapAtlas
Indicates that the font package stores glyphs in a texture atlas bitmap.