mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 10:35:43 -05:00
Remove namespace from font utility classes
This commit is contained in:
parent
1f44b65ef6
commit
7f3fb10f2a
8 changed files with 29 additions and 66 deletions
|
@ -61,17 +61,16 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
}
|
||||
|
||||
//init the text rendering system
|
||||
bgfx_font::FontManager* fontManager = new bgfx_font::FontManager(512);
|
||||
bgfx_font::TextBufferManager* textBufferManager = new bgfx_font::TextBufferManager(fontManager);
|
||||
FontManager* fontManager = new FontManager(512);
|
||||
TextBufferManager* textBufferManager = new TextBufferManager(fontManager);
|
||||
textBufferManager->init(s_shaderPath);
|
||||
|
||||
|
||||
|
||||
//load some truetype files
|
||||
bgfx_font::TrueTypeHandle times_tt = fontManager->loadTrueTypeFromFile("c:/windows/fonts/times.ttf");
|
||||
bgfx_font::TrueTypeHandle consola_tt = fontManager->loadTrueTypeFromFile("c:/windows/fonts/consola.ttf");
|
||||
TrueTypeHandle times_tt = fontManager->loadTrueTypeFromFile("c:/windows/fonts/times.ttf");
|
||||
TrueTypeHandle consola_tt = fontManager->loadTrueTypeFromFile("c:/windows/fonts/consola.ttf");
|
||||
|
||||
//create some usable font with of a specific size
|
||||
bgfx_font::FontHandle times_24 = fontManager->createFontByPixelSize(times_tt, 0, 24);
|
||||
FontHandle times_24 = fontManager->createFontByPixelSize(times_tt, 0, 24);
|
||||
|
||||
//preload glyphs and blit them to atlas
|
||||
fontManager->preloadGlyph(times_24, L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. \n");
|
||||
|
@ -81,11 +80,11 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
|
||||
//this font doesn't have any preloaded glyph's but the truetype file is loaded
|
||||
//so glyph will be generated as needed
|
||||
bgfx_font::FontHandle consola_16 = fontManager->createFontByPixelSize(consola_tt, 0, 16);
|
||||
FontHandle consola_16 = fontManager->createFontByPixelSize(consola_tt, 0, 16);
|
||||
|
||||
//create a static text buffer compatible with alpha font
|
||||
//a static text buffer content cannot be modified after its first submit.
|
||||
bgfx_font::TextBufferHandle staticText = textBufferManager->createTextBuffer(bgfx_font::FONT_TYPE_ALPHA, bgfx_font::STATIC);
|
||||
TextBufferHandle staticText = textBufferManager->createTextBuffer(FONT_TYPE_ALPHA, STATIC);
|
||||
|
||||
//the pen position represent the top left of the box of the first line of text
|
||||
textBufferManager->setPenPosition(staticText, 20.0f, 100.0f);
|
||||
|
@ -102,28 +101,28 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
|
||||
|
||||
//text + bkg
|
||||
textBufferManager->setStyle(staticText, bgfx_font::STYLE_BACKGROUND);
|
||||
textBufferManager->setStyle(staticText, STYLE_BACKGROUND);
|
||||
textBufferManager->appendText(staticText, times_24, L"The quick brown fox jumps over the lazy dog\n");
|
||||
|
||||
//text + strike-through
|
||||
textBufferManager->setStyle(staticText, bgfx_font::STYLE_STRIKE_THROUGH);
|
||||
textBufferManager->setStyle(staticText, STYLE_STRIKE_THROUGH);
|
||||
textBufferManager->appendText(staticText, times_24, L"The quick brown fox jumps over the lazy dog\n");
|
||||
|
||||
//text + overline
|
||||
textBufferManager->setStyle(staticText, bgfx_font::STYLE_OVERLINE);
|
||||
textBufferManager->setStyle(staticText, STYLE_OVERLINE);
|
||||
textBufferManager->appendText(staticText, times_24, L"The quick brown fox jumps over the lazy dog\n");
|
||||
|
||||
//text + underline
|
||||
textBufferManager->setStyle(staticText, bgfx_font::STYLE_UNDERLINE);
|
||||
textBufferManager->setStyle(staticText, STYLE_UNDERLINE);
|
||||
textBufferManager->appendText(staticText, times_24, L"The quick brown fox jumps over the lazy dog\n");
|
||||
|
||||
|
||||
//text + bkg + strike-through
|
||||
textBufferManager->setStyle(staticText, bgfx_font::STYLE_BACKGROUND|bgfx_font::STYLE_STRIKE_THROUGH);
|
||||
textBufferManager->setStyle(staticText, STYLE_BACKGROUND|STYLE_STRIKE_THROUGH);
|
||||
textBufferManager->appendText(staticText, times_24, L"The quick brown fox jumps over the lazy dog\n");
|
||||
|
||||
//create a transient buffer for realtime data
|
||||
bgfx_font::TextBufferHandle transientText = textBufferManager->createTextBuffer(bgfx_font::FONT_TYPE_ALPHA, bgfx_font::TRANSIENT);
|
||||
TextBufferHandle transientText = textBufferManager->createTextBuffer(FONT_TYPE_ALPHA, TRANSIENT);
|
||||
|
||||
|
||||
uint32_t w = 0,h = 0;
|
||||
|
|
|
@ -62,18 +62,18 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
}
|
||||
|
||||
//init the text rendering system
|
||||
bgfx_font::FontManager* fontManager = new bgfx_font::FontManager(512);
|
||||
bgfx_font::TextBufferManager* textBufferManager = new bgfx_font::TextBufferManager(fontManager);
|
||||
FontManager* fontManager = new FontManager(512);
|
||||
TextBufferManager* textBufferManager = new TextBufferManager(fontManager);
|
||||
textBufferManager->init(s_shaderPath);
|
||||
|
||||
//load a truetype files
|
||||
bgfx_font::TrueTypeHandle times_tt = fontManager->loadTrueTypeFromFile("c:/windows/fonts/times.ttf");
|
||||
bgfx_font::FontHandle distance_font = fontManager->createFontByPixelSize(times_tt, 0, 48, bgfx_font::FONT_TYPE_DISTANCE);
|
||||
TrueTypeHandle times_tt = fontManager->loadTrueTypeFromFile("c:/windows/fonts/times.ttf");
|
||||
FontHandle distance_font = fontManager->createFontByPixelSize(times_tt, 0, 48, FONT_TYPE_DISTANCE);
|
||||
//preload glyph and generate (generate bitmap's)
|
||||
fontManager->preloadGlyph(distance_font, L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. \n");
|
||||
|
||||
uint32_t fontsCount = 0;
|
||||
bgfx_font::FontHandle fonts[64];
|
||||
FontHandle fonts[64];
|
||||
fonts[fontsCount++] = distance_font;
|
||||
//generate various sub distance field fonts at various size
|
||||
int step=4;
|
||||
|
@ -81,13 +81,13 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
{
|
||||
if(i<32) step = 2;
|
||||
//instantiate a usable font
|
||||
bgfx_font::FontHandle font = fontManager->createScaledFontToPixelSize(distance_font, i);
|
||||
FontHandle font = fontManager->createScaledFontToPixelSize(distance_font, i);
|
||||
fonts[fontsCount++] = font;
|
||||
}
|
||||
//You can unload the truetype files at this stage, but in that case, the set of glyph's will be limited to the set of preloaded glyph
|
||||
fontManager->unloadTrueType(times_tt);
|
||||
|
||||
bgfx_font::TextBufferHandle staticText = textBufferManager->createTextBuffer(bgfx_font::FONT_TYPE_DISTANCE, bgfx_font::STATIC);
|
||||
TextBufferHandle staticText = textBufferManager->createTextBuffer(FONT_TYPE_DISTANCE, STATIC);
|
||||
|
||||
textBufferManager->setPenPosition(staticText, 10.0f, 70.0f);
|
||||
textBufferManager->setTextColor(staticText, 0xFFFFFFFF);
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
#include <vector>
|
||||
#include "cube_atlas.h"
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
|
||||
//********** Rectangle packer implementation ************
|
||||
class RectanglePacker
|
||||
{
|
||||
|
@ -479,5 +476,3 @@ void Atlas::packUV( const AtlasRegion& region, uint8_t* vertexBuffer, uint32_t o
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -14,9 +14,6 @@
|
|||
|
||||
#include <bgfx.h>
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
|
||||
struct AtlasRegion
|
||||
{
|
||||
enum Type
|
||||
|
@ -133,4 +130,4 @@ private:
|
|||
AtlasRegion* m_regions;
|
||||
uint8_t* m_textureBuffer;
|
||||
|
||||
};}
|
||||
};
|
|
@ -40,12 +40,6 @@ namespace stl {
|
|||
}
|
||||
#endif // BGFX_CONFIG_USE_TINYSTL
|
||||
|
||||
|
||||
#define BGFX_FONT_ASSERT(cond, message) assert((cond) && (message));
|
||||
|
||||
namespace bgfx_font
|
||||
{
|
||||
|
||||
class FontManager::TrueTypeFont
|
||||
{
|
||||
public:
|
||||
|
@ -445,7 +439,7 @@ const uint16_t MAX_OPENED_FILES = 64;
|
|||
const uint16_t MAX_OPENED_FONT = 64;
|
||||
const uint32_t MAX_FONT_BUFFER_SIZE = 512*512*4;
|
||||
|
||||
FontManager::FontManager(bgfx::Atlas* atlas):m_filesHandles(MAX_OPENED_FILES), m_fontHandles(MAX_OPENED_FONT)
|
||||
FontManager::FontManager(Atlas* atlas):m_filesHandles(MAX_OPENED_FILES), m_fontHandles(MAX_OPENED_FONT)
|
||||
{
|
||||
m_atlas = atlas;
|
||||
m_ownAtlas = false;
|
||||
|
@ -454,7 +448,7 @@ FontManager::FontManager(bgfx::Atlas* atlas):m_filesHandles(MAX_OPENED_FILES), m
|
|||
|
||||
FontManager::FontManager(uint32_t textureSideWidth):m_filesHandles(MAX_OPENED_FILES), m_fontHandles(MAX_OPENED_FONT)
|
||||
{
|
||||
m_atlas = new bgfx::Atlas(textureSideWidth);
|
||||
m_atlas = new Atlas(textureSideWidth);
|
||||
m_ownAtlas = true;
|
||||
init();
|
||||
}
|
||||
|
@ -781,12 +775,6 @@ bool FontManager::getGlyphInfo(FontHandle fontHandle, CodePoint_t codePoint, Gly
|
|||
|
||||
bool FontManager::addBitmap(GlyphInfo& glyphInfo, const uint8_t* data)
|
||||
{
|
||||
glyphInfo.regionIndex = m_atlas->addRegion((uint16_t) ceil(glyphInfo.width),(uint16_t) ceil(glyphInfo.height), data, bgfx::AtlasRegion::TYPE_GRAY);
|
||||
glyphInfo.regionIndex = m_atlas->addRegion((uint16_t) ceil(glyphInfo.width),(uint16_t) ceil(glyphInfo.height), data, AtlasRegion::TYPE_GRAY);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,11 +5,7 @@
|
|||
#include <bgfx.h>
|
||||
#include <bx/handlealloc.h>
|
||||
|
||||
namespace bgfx{ class Atlas; }
|
||||
|
||||
namespace bgfx_font
|
||||
{
|
||||
|
||||
class Atlas;
|
||||
enum FontType
|
||||
{
|
||||
FONT_TYPE_ALPHA = 0x00000100 , // L8
|
||||
|
@ -116,14 +112,14 @@ class FontManager
|
|||
{
|
||||
public:
|
||||
/// create the font manager using an external cube atlas (doesn't take ownership of the atlas)
|
||||
FontManager(bgfx::Atlas* atlas);
|
||||
FontManager(Atlas* atlas);
|
||||
/// create the font manager and create the texture cube as BGRA8 with linear filtering
|
||||
FontManager(uint32_t textureSideWidth = 512);
|
||||
|
||||
~FontManager();
|
||||
|
||||
/// retrieve the atlas used by the font manager (e.g. to add stuff to it)
|
||||
bgfx::Atlas* getAtlas() { return m_atlas; }
|
||||
Atlas* getAtlas() { return m_atlas; }
|
||||
|
||||
/// load a TrueType font from a file path
|
||||
/// @return invalid handle if the loading fail
|
||||
|
@ -191,7 +187,7 @@ private:
|
|||
bool addBitmap(GlyphInfo& glyphInfo, const uint8_t* data);
|
||||
|
||||
bool m_ownAtlas;
|
||||
(bgfx::Atlas* m_atlas;
|
||||
(Atlas* m_atlas;
|
||||
|
||||
bx::HandleAlloc m_fontHandles;
|
||||
CachedFont* m_cachedFonts;
|
||||
|
@ -204,5 +200,3 @@ private:
|
|||
//temporary buffer to raster glyph
|
||||
uint8_t* m_buffer;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -10,9 +10,6 @@
|
|||
#include <math.h>
|
||||
#include <stddef.h> /* offsetof */
|
||||
|
||||
namespace bgfx_font
|
||||
{
|
||||
|
||||
const uint16_t MAX_TEXT_BUFFER_COUNT = 64;
|
||||
|
||||
long int fsize(FILE* _file)
|
||||
|
@ -808,5 +805,3 @@ void TextBufferManager::clearTextBuffer(TextBufferHandle _handle)
|
|||
BufferCache& bc = m_textBuffers[_handle.idx];
|
||||
bc.textBuffer->clearTextBuffer();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
#pragma once
|
||||
#include "font_manager.h"
|
||||
|
||||
namespace bgfx_font
|
||||
{
|
||||
|
||||
BGFX_HANDLE(TextBufferHandle);
|
||||
|
||||
/// type of vertex and index buffer to use with a TextBuffer
|
||||
|
@ -86,5 +83,3 @@ private:
|
|||
bgfx::ProgramHandle m_distanceProgram;
|
||||
bgfx::ProgramHandle m_distanceSubpixelProgram;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue