mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-18 06:55:48 +03:00
TextureFactory::bind fixed.
Added BMFont support. --HG-- branch : dev-2.1
This commit is contained in:
99
bin/assets/fonts/bmfont.fnt
Normal file
99
bin/assets/fonts/bmfont.fnt
Normal file
@@ -0,0 +1,99 @@
|
||||
info face="Arial Black" size=-32 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=2,2 outline=0
|
||||
common lineHeight=45 base=35 scaleW=512 scaleH=256 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4
|
||||
page id=0 file="bmfont.png"
|
||||
chars count=95
|
||||
char id=32 x=423 y=141 width=3 height=45 xoffset=-1 yoffset=0 xadvance=11 page=0 chnl=15
|
||||
char id=33 x=323 y=141 width=9 height=45 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=15
|
||||
char id=34 x=123 y=141 width=16 height=45 xoffset=0 yoffset=0 xadvance=16 page=0 chnl=15
|
||||
char id=35 x=221 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=36 x=244 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=37 x=70 y=0 width=30 height=45 xoffset=1 yoffset=0 xadvance=32 page=0 chnl=15
|
||||
char id=38 x=390 y=0 width=25 height=45 xoffset=2 yoffset=0 xadvance=28 page=0 chnl=15
|
||||
char id=39 x=378 y=141 width=8 height=45 xoffset=1 yoffset=0 xadvance=9 page=0 chnl=15
|
||||
char id=40 x=222 y=141 width=11 height=45 xoffset=1 yoffset=0 xadvance=12 page=0 chnl=15
|
||||
char id=41 x=499 y=94 width=11 height=45 xoffset=1 yoffset=0 xadvance=12 page=0 chnl=15
|
||||
char id=42 x=497 y=47 width=13 height=45 xoffset=2 yoffset=0 xadvance=18 page=0 chnl=15
|
||||
char id=43 x=394 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=44 x=367 y=141 width=9 height=45 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=15
|
||||
char id=45 x=261 y=141 width=11 height=45 xoffset=0 yoffset=0 xadvance=11 page=0 chnl=15
|
||||
char id=46 x=356 y=141 width=9 height=45 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=15
|
||||
char id=47 x=248 y=141 width=11 height=45 xoffset=-1 yoffset=0 xadvance=9 page=0 chnl=15
|
||||
char id=48 x=382 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=49 x=496 y=0 width=14 height=45 xoffset=2 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=50 x=134 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=51 x=359 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=52 x=313 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=53 x=336 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=54 x=178 y=94 width=20 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=55 x=478 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=56 x=290 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=57 x=90 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=58 x=345 y=141 width=9 height=45 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=15
|
||||
char id=59 x=334 y=141 width=9 height=45 xoffset=1 yoffset=0 xadvance=11 page=0 chnl=15
|
||||
char id=60 x=0 y=141 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=61 x=21 y=141 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=62 x=310 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=63 x=352 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=20 page=0 chnl=15
|
||||
char id=64 x=279 y=0 width=26 height=45 xoffset=-1 yoffset=0 xadvance=24 page=0 chnl=15
|
||||
char id=65 x=193 y=0 width=27 height=45 xoffset=-1 yoffset=0 xadvance=25 page=0 chnl=15
|
||||
char id=66 x=150 y=47 width=22 height=45 xoffset=2 yoffset=0 xadvance=25 page=0 chnl=15
|
||||
char id=67 x=444 y=0 width=24 height=45 xoffset=1 yoffset=0 xadvance=25 page=0 chnl=15
|
||||
char id=68 x=174 y=47 width=22 height=45 xoffset=2 yoffset=0 xadvance=25 page=0 chnl=15
|
||||
char id=69 x=156 y=94 width=20 height=45 xoffset=2 yoffset=0 xadvance=23 page=0 chnl=15
|
||||
char id=70 x=63 y=141 width=18 height=45 xoffset=2 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=71 x=417 y=0 width=25 height=45 xoffset=1 yoffset=0 xadvance=27 page=0 chnl=15
|
||||
char id=72 x=125 y=47 width=23 height=45 xoffset=2 yoffset=0 xadvance=27 page=0 chnl=15
|
||||
char id=73 x=388 y=141 width=8 height=45 xoffset=2 yoffset=0 xadvance=12 page=0 chnl=15
|
||||
char id=74 x=200 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=75 x=251 y=0 width=26 height=45 xoffset=2 yoffset=0 xadvance=27 page=0 chnl=15
|
||||
char id=76 x=373 y=94 width=19 height=45 xoffset=2 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=77 x=134 y=0 width=28 height=45 xoffset=1 yoffset=0 xadvance=30 page=0 chnl=15
|
||||
char id=78 x=100 y=47 width=23 height=45 xoffset=2 yoffset=0 xadvance=27 page=0 chnl=15
|
||||
char id=79 x=363 y=0 width=25 height=45 xoffset=1 yoffset=0 xadvance=27 page=0 chnl=15
|
||||
char id=80 x=112 y=94 width=20 height=45 xoffset=2 yoffset=0 xadvance=23 page=0 chnl=15
|
||||
char id=81 x=335 y=0 width=26 height=45 xoffset=1 yoffset=0 xadvance=27 page=0 chnl=15
|
||||
char id=82 x=470 y=0 width=24 height=45 xoffset=2 yoffset=0 xadvance=25 page=0 chnl=15
|
||||
char id=83 x=75 y=47 width=23 height=45 xoffset=0 yoffset=0 xadvance=23 page=0 chnl=15
|
||||
char id=84 x=50 y=47 width=23 height=45 xoffset=0 yoffset=0 xadvance=23 page=0 chnl=15
|
||||
char id=85 x=25 y=47 width=23 height=45 xoffset=2 yoffset=0 xadvance=27 page=0 chnl=15
|
||||
char id=86 x=307 y=0 width=26 height=45 xoffset=0 yoffset=0 xadvance=25 page=0 chnl=15
|
||||
char id=87 x=0 y=0 width=34 height=45 xoffset=-1 yoffset=0 xadvance=32 page=0 chnl=15
|
||||
char id=88 x=222 y=0 width=27 height=45 xoffset=-1 yoffset=0 xadvance=25 page=0 chnl=15
|
||||
char id=89 x=164 y=0 width=27 height=45 xoffset=-1 yoffset=0 xadvance=25 page=0 chnl=15
|
||||
char id=90 x=0 y=47 width=23 height=45 xoffset=0 yoffset=0 xadvance=23 page=0 chnl=15
|
||||
char id=91 x=274 y=141 width=11 height=45 xoffset=1 yoffset=0 xadvance=12 page=0 chnl=15
|
||||
char id=92 x=300 y=141 width=10 height=45 xoffset=-1 yoffset=0 xadvance=9 page=0 chnl=15
|
||||
char id=93 x=287 y=141 width=11 height=45 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
|
||||
char id=94 x=457 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=95 x=103 y=141 width=18 height=45 xoffset=-1 yoffset=0 xadvance=16 page=0 chnl=15
|
||||
char id=96 x=312 y=141 width=9 height=45 xoffset=0 yoffset=0 xadvance=11 page=0 chnl=15
|
||||
char id=97 x=474 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=98 x=68 y=94 width=20 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=99 x=267 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=100 x=46 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=101 x=198 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=102 x=141 y=141 width=15 height=45 xoffset=-1 yoffset=0 xadvance=12 page=0 chnl=15
|
||||
char id=103 x=222 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=104 x=415 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=105 x=398 y=141 width=7 height=45 xoffset=2 yoffset=0 xadvance=11 page=0 chnl=15
|
||||
char id=106 x=235 y=141 width=11 height=45 xoffset=-2 yoffset=0 xadvance=11 page=0 chnl=15
|
||||
char id=107 x=405 y=47 width=21 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=108 x=407 y=141 width=7 height=45 xoffset=2 yoffset=0 xadvance=11 page=0 chnl=15
|
||||
char id=109 x=102 y=0 width=30 height=45 xoffset=1 yoffset=0 xadvance=32 page=0 chnl=15
|
||||
char id=110 x=331 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=111 x=428 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=112 x=266 y=94 width=20 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=113 x=288 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=114 x=158 y=141 width=15 height=45 xoffset=1 yoffset=0 xadvance=14 page=0 chnl=15
|
||||
char id=115 x=244 y=94 width=20 height=45 xoffset=0 yoffset=0 xadvance=20 page=0 chnl=15
|
||||
char id=116 x=175 y=141 width=14 height=45 xoffset=0 yoffset=0 xadvance=14 page=0 chnl=15
|
||||
char id=117 x=436 y=94 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=118 x=451 y=47 width=21 height=45 xoffset=0 yoffset=0 xadvance=20 page=0 chnl=15
|
||||
char id=119 x=36 y=0 width=32 height=45 xoffset=-1 yoffset=0 xadvance=30 page=0 chnl=15
|
||||
char id=120 x=0 y=94 width=21 height=45 xoffset=0 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
char id=121 x=23 y=94 width=21 height=45 xoffset=0 yoffset=0 xadvance=20 page=0 chnl=15
|
||||
char id=122 x=83 y=141 width=18 height=45 xoffset=0 yoffset=0 xadvance=18 page=0 chnl=15
|
||||
char id=123 x=191 y=141 width=14 height=45 xoffset=-1 yoffset=0 xadvance=12 page=0 chnl=15
|
||||
char id=124 x=416 y=141 width=5 height=45 xoffset=2 yoffset=0 xadvance=9 page=0 chnl=15
|
||||
char id=125 x=207 y=141 width=13 height=45 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15
|
||||
char id=126 x=42 y=141 width=19 height=45 xoffset=1 yoffset=0 xadvance=21 page=0 chnl=15
|
||||
BIN
bin/assets/fonts/bmfont.png
Normal file
BIN
bin/assets/fonts/bmfont.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
@@ -25,6 +25,7 @@
|
||||
#include <eepp/graphics/fontstyleconfig.hpp>
|
||||
#include <eepp/graphics/font.hpp>
|
||||
#include <eepp/graphics/fonttruetype.hpp>
|
||||
#include <eepp/graphics/fontbmfont.hpp>
|
||||
#include <eepp/graphics/fonttruetypeloader.hpp>
|
||||
#include <eepp/graphics/fontmanager.hpp>
|
||||
#include <eepp/graphics/text.hpp>
|
||||
|
||||
71
include/eepp/graphics/fontbmfont.hpp
Normal file
71
include/eepp/graphics/fontbmfont.hpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#ifndef EE_GRAPHICS_FONTBMFONT_HPP
|
||||
#define EE_GRAPHICS_FONTBMFONT_HPP
|
||||
|
||||
#include <eepp/graphics/base.hpp>
|
||||
#include <eepp/graphics/texture.hpp>
|
||||
#include <eepp/graphics/font.hpp>
|
||||
|
||||
namespace EE { namespace System {
|
||||
class Pack;
|
||||
class IOStream;
|
||||
}}
|
||||
|
||||
namespace EE { namespace Graphics {
|
||||
|
||||
class EE_API FontBMFont : public Font {
|
||||
public:
|
||||
static FontBMFont * New( const std::string FontName ) ;
|
||||
|
||||
~FontBMFont();
|
||||
|
||||
bool loadFromFile(const std::string& filename);
|
||||
|
||||
bool loadFromMemory(const void* data, std::size_t sizeInBytes);
|
||||
|
||||
bool loadFromStream( IOStream& stream );
|
||||
|
||||
bool loadFromPack( Pack * pack, std::string filePackPath );
|
||||
|
||||
const Font::Info& getInfo() const;
|
||||
|
||||
const Glyph& getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, Float outlineThickness = 0) const;
|
||||
|
||||
Float getKerning(Uint32 first, Uint32 second, unsigned int characterSize) const;
|
||||
|
||||
Float getLineSpacing(unsigned int characterSize) const;
|
||||
|
||||
Uint32 getFontHeight( const Uint32& characterSize );
|
||||
|
||||
Float getUnderlinePosition(unsigned int characterSize) const;
|
||||
|
||||
Float getUnderlineThickness(unsigned int characterSize) const;
|
||||
|
||||
Texture * getTexture(unsigned int characterSize) const;
|
||||
|
||||
FontBMFont& operator =(const FontBMFont& right);
|
||||
protected:
|
||||
FontBMFont(const std::string FontName);
|
||||
|
||||
typedef std::map<Uint64, Glyph> GlyphTable; ///< Table mapping a codepoint to its glyph
|
||||
|
||||
struct Page
|
||||
{
|
||||
GlyphTable glyphs; ///< Table mapping code points to their corresponding glyph
|
||||
Texture * texture; ///< Texture containing the pixels of the glyphs
|
||||
};
|
||||
|
||||
void cleanup();
|
||||
|
||||
typedef std::map<unsigned int, Page> PageTable; ///< Table mapping a character size to its page (texture)
|
||||
|
||||
Font::Info mInfo; ///< Information about the font
|
||||
mutable PageTable mPages; ///< Table containing the glyphs pages by character size
|
||||
std::string mFilePath;
|
||||
Uint32 mFontSize;
|
||||
|
||||
Glyph loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, Float outlineThickness) const;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -5,7 +5,7 @@ namespace EE { namespace Graphics {
|
||||
|
||||
enum EE_FONT_TYPE {
|
||||
FONT_TYPE_TTF = 1,
|
||||
FONT_TYPE_TEX = 2
|
||||
FONT_TYPE_BMF = 2
|
||||
};
|
||||
|
||||
enum EE_FONT_HALIGN {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
../../include/eepp/graphics/font.hpp
|
||||
../../include/eepp/graphics/fontstyleconfig.hpp
|
||||
../../include/eepp/graphics/fonttruetype.hpp
|
||||
../../include/eepp/graphics/fontbmfont.hpp
|
||||
../../include/eepp/graphics/fonttruetypeloader.hpp
|
||||
../../include/eepp/graphics/ninepatch.hpp
|
||||
../../include/eepp/graphics/ninepatchmanager.hpp
|
||||
@@ -94,6 +95,7 @@
|
||||
../../src/eepp/graphics/drawablesearcher.cpp
|
||||
../../src/eepp/graphics/fonttruetype.cpp
|
||||
../../src/eepp/graphics/fonttruetypeloader.cpp
|
||||
../../src/eepp/graphics/fontbmfont.cpp
|
||||
../../src/eepp/graphics/globalbatchrenderer.cpp
|
||||
../../src/eepp/graphics/pixeldensity.cpp
|
||||
../../src/eepp/graphics/pixelperfect.cpp
|
||||
@@ -268,8 +270,6 @@
|
||||
../../include/eepp/graphics/vertexbufferogl.hpp
|
||||
../../src/eepp/graphics/vertexbuffermanager.hpp
|
||||
../../include/eepp/graphics/vertexbuffer.hpp
|
||||
../../include/eepp/graphics/ttffontloader.hpp
|
||||
../../include/eepp/graphics/ttffont.hpp
|
||||
../../src/eepp/graphics/texturepackertex.hpp
|
||||
../../src/eepp/graphics/texturepackernode.hpp
|
||||
../../include/eepp/graphics/texturepacker.hpp
|
||||
@@ -580,8 +580,6 @@
|
||||
../../src/eepp/graphics/vertexbufferogl.cpp
|
||||
../../src/eepp/graphics/vertexbuffermanager.cpp
|
||||
../../src/eepp/graphics/vertexbuffer.cpp
|
||||
../../src/eepp/graphics/ttffontloader.cpp
|
||||
../../src/eepp/graphics/ttffont.cpp
|
||||
../../src/eepp/graphics/texturepackertex.cpp
|
||||
../../src/eepp/graphics/texturepackernode.cpp
|
||||
../../src/eepp/graphics/texturepacker.cpp
|
||||
|
||||
218
src/eepp/graphics/fontbmfont.cpp
Normal file
218
src/eepp/graphics/fontbmfont.cpp
Normal file
@@ -0,0 +1,218 @@
|
||||
#include <eepp/graphics/fontbmfont.hpp>
|
||||
#include <eepp/system/iostream.hpp>
|
||||
#include <eepp/system/iostreamfile.hpp>
|
||||
#include <eepp/system/iostreammemory.hpp>
|
||||
#include <eepp/system/pack.hpp>
|
||||
#include <eepp/system/packmanager.hpp>
|
||||
#include <eepp/system/filesystem.hpp>
|
||||
#include <eepp/graphics/texturefactory.hpp>
|
||||
|
||||
namespace EE { namespace Graphics {
|
||||
|
||||
FontBMFont * FontBMFont::New( const std::string FontName ) {
|
||||
return eeNew( FontBMFont, ( FontName ) );
|
||||
}
|
||||
|
||||
FontBMFont::FontBMFont( const std::string FontName ) :
|
||||
Font( FONT_TYPE_BMF, FontName ),
|
||||
mInfo(),
|
||||
mFontSize(0)
|
||||
{}
|
||||
|
||||
void FontBMFont::cleanup() {
|
||||
Texture * texture = mPages[ mFontSize ].texture;
|
||||
|
||||
if ( NULL != texture && TextureFactory::existsSingleton() )
|
||||
TextureFactory::instance()->remove( texture->getId() );
|
||||
|
||||
mPages.clear();
|
||||
mFontSize = 0;
|
||||
mFilePath = "";
|
||||
}
|
||||
|
||||
FontBMFont::~FontBMFont() {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
bool FontBMFont::loadFromFile( const std::string& filename ) {
|
||||
cleanup();
|
||||
if ( FileSystem::fileExists( filename ) ) {
|
||||
mFilePath = FileSystem::fileRemoveFileName( filename );
|
||||
IOStreamFile stream( filename );
|
||||
return loadFromStream( stream );
|
||||
} else if ( PackManager::instance()->isFallbackToPacksActive() ) {
|
||||
std::string path( filename );
|
||||
Pack * pack = PackManager::instance()->exists( path );
|
||||
|
||||
if ( NULL != pack ) {
|
||||
eePRINTL( "Loading font from pack: %s", path.c_str() );
|
||||
|
||||
return loadFromPack( pack, path );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FontBMFont::loadFromMemory( const void * data, std::size_t sizeInBytes ) {
|
||||
cleanup();
|
||||
mFilePath = FileSystem::getCurrentWorkingDirectory();
|
||||
IOStreamMemory stream( (const char*)data, sizeInBytes );
|
||||
return loadFromStream( stream );
|
||||
}
|
||||
|
||||
bool FontBMFont::loadFromStream( IOStream& stream ) {
|
||||
if ( !stream.isOpen() )
|
||||
return false;
|
||||
|
||||
std::string myfile( (size_t)stream.getSize(), '\0' );
|
||||
|
||||
stream.read( (char*)&myfile[0], stream.getSize() );
|
||||
|
||||
std::vector<std::string> lines = String::split( myfile );
|
||||
|
||||
if ( lines.size() > 4 ) {
|
||||
const char *searchPoint = NULL;
|
||||
int fontSize; int base; int texWidth; int texHeight;
|
||||
char texFileName[128];
|
||||
int charsCount = 0;
|
||||
|
||||
searchPoint = strstr( lines[1].c_str(), "lineHeight" );
|
||||
sscanf(searchPoint, "lineHeight=%i base=%i scaleW=%i scaleH=%i", &fontSize, &base, &texWidth, &texHeight);
|
||||
|
||||
searchPoint = strstr( lines[2].c_str(), "file");
|
||||
sscanf(searchPoint, "file=\"%128[^\"]\"", texFileName);
|
||||
|
||||
searchPoint = strstr( lines[3].c_str(), "count");
|
||||
sscanf(searchPoint, "count=%i", &charsCount);
|
||||
|
||||
mFontSize = fontSize;
|
||||
|
||||
FileSystem::dirPathAddSlashAtEnd( mFilePath );
|
||||
|
||||
{
|
||||
TextureFactory * TF = TextureFactory::instance();
|
||||
|
||||
Image img( mFilePath + std::string( texFileName ) );
|
||||
|
||||
if ( img.getChannels() == 1 ) {
|
||||
Image rgbaImg( img.getWidth(), img.getHeight(), 4 );
|
||||
size_t w = img.getWidth(), h = img.getHeight();
|
||||
|
||||
for ( size_t y = 0; y < w; y++ ) {
|
||||
for ( size_t x = 0; x < h; x++ ) {
|
||||
rgbaImg.setPixel( x, y, Color( 255, 255, 255, img.getPixel( x, y ).r ) );
|
||||
}
|
||||
}
|
||||
|
||||
Uint32 texId = TF->loadFromPixels( rgbaImg.getPixelsPtr(), rgbaImg.getWidth(), rgbaImg.getHeight(), rgbaImg.getChannels() );
|
||||
|
||||
mPages[ mFontSize ].texture = TF->getTexture( texId );
|
||||
} else {
|
||||
Uint32 texId = TF->loadFromPixels( img.getPixelsPtr(), img.getWidth(), img.getHeight(), img.getChannels() );
|
||||
mPages[ mFontSize ].texture = TF->getTexture( texId );
|
||||
}
|
||||
|
||||
if ( NULL != mPages[ mFontSize ].texture )
|
||||
mPages[ mFontSize ].texture->setFilter( Texture::TextureFilter::Nearest );
|
||||
}
|
||||
|
||||
GlyphTable& glyphs = mPages[ mFontSize ].glyphs;
|
||||
|
||||
size_t firstLine = 4;
|
||||
size_t lastLine = firstLine + charsCount;
|
||||
|
||||
if ( lastLine > lines.size() )
|
||||
lastLine = lines.size();
|
||||
|
||||
int charId, charX, charY, charWidth, charHeight, charOffsetX, charOffsetY, charAdvanceX;
|
||||
|
||||
for ( size_t i = firstLine; i < lastLine; i++ ) {
|
||||
sscanf( lines[i].c_str(), "char id=%i x=%i y=%i width=%i height=%i xoffset=%i yoffset=%i xadvance=%i", &charId, &charX, &charY, &charWidth, &charHeight, &charOffsetX, &charOffsetY, &charAdvanceX);
|
||||
|
||||
Glyph& glyph = glyphs[ charId ];
|
||||
|
||||
glyph.advance = charAdvanceX;
|
||||
glyph.bounds = Rectf( charOffsetX, -fontSize + charOffsetY, charWidth, charHeight );
|
||||
glyph.textureRect = Rect( charX, charY, charWidth, charHeight );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FontBMFont::loadFromPack( Pack * pack, std::string filePackPath ) {
|
||||
cleanup();
|
||||
mFilePath = FileSystem::fileRemoveFileName( filePackPath );
|
||||
return loadFromStream( *pack->getFileStream( filePackPath ) );
|
||||
}
|
||||
|
||||
const FontBMFont::Info& FontBMFont::getInfo() const {
|
||||
return mInfo;
|
||||
}
|
||||
|
||||
const Glyph &FontBMFont::getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, Float outlineThickness) const {
|
||||
GlyphTable& glyphs = mPages[characterSize].glyphs;
|
||||
|
||||
GlyphTable::const_iterator it = glyphs.find(codePoint);
|
||||
|
||||
if (it != glyphs.end()) {
|
||||
return it->second;
|
||||
} else {
|
||||
glyphs[ characterSize ] = loadGlyph(codePoint, characterSize, bold, outlineThickness);
|
||||
return glyphs[ characterSize ];
|
||||
}
|
||||
}
|
||||
|
||||
Glyph FontBMFont::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, Float outlineThickness) const {
|
||||
Glyph glyph;
|
||||
|
||||
GlyphTable& glyphs = mPages[mFontSize].glyphs;
|
||||
GlyphTable::const_iterator it = glyphs.find(codePoint);
|
||||
|
||||
if (it != glyphs.end()) {
|
||||
const Glyph& oriGlyph = it->second;
|
||||
|
||||
Float scale = (Float)characterSize / (Float)mFontSize;
|
||||
|
||||
glyph.textureRect = oriGlyph.textureRect;
|
||||
glyph.bounds = oriGlyph.bounds * scale;
|
||||
glyph.advance = oriGlyph.advance * scale;
|
||||
}
|
||||
|
||||
return glyph;
|
||||
}
|
||||
|
||||
Float FontBMFont::getKerning(Uint32 first, Uint32 second, unsigned int characterSize) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Float FontBMFont::getLineSpacing(unsigned int characterSize) const {
|
||||
return ((Float)characterSize / mFontSize ) * mFontSize;
|
||||
}
|
||||
|
||||
Uint32 FontBMFont::getFontHeight(const Uint32 & characterSize) {
|
||||
return (Uint32)((Float)characterSize / mFontSize ) * mFontSize;
|
||||
}
|
||||
|
||||
Float FontBMFont::getUnderlinePosition(unsigned int characterSize) const {
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
Float FontBMFont::getUnderlineThickness(unsigned int characterSize) const {
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
Texture * FontBMFont::getTexture(unsigned int characterSize) const {
|
||||
return mPages[ mFontSize ].texture;
|
||||
}
|
||||
|
||||
FontBMFont& FontBMFont::operator =(const FontBMFont& right) {
|
||||
FontBMFont temp(right);
|
||||
std::swap(mInfo, temp.mInfo);
|
||||
std::swap(mPages, temp.mPages);
|
||||
std::swap(mFilePath, temp.mFilePath);
|
||||
std::swap(mFontSize, temp.mFontSize);
|
||||
return *this;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -111,18 +111,17 @@ Uint32 TextureFactory::findFreeSlot() {
|
||||
|
||||
void TextureFactory::bind( const Texture* texture, Texture::CoordinateType coordinateType, const Uint32& TextureUnit ) {
|
||||
if( NULL != texture ) {
|
||||
if ( mCurrentTexture[ TextureUnit ] == (Int32)texture->getHandle() )
|
||||
return;
|
||||
if ( mCurrentTexture[ TextureUnit ] != (Int32)texture->getHandle() ) {
|
||||
if ( TextureUnit && GLi->isExtension( EEGL_ARB_multitexture ) )
|
||||
setActiveTextureUnit( TextureUnit );
|
||||
|
||||
if ( TextureUnit && GLi->isExtension( EEGL_ARB_multitexture ) )
|
||||
setActiveTextureUnit( TextureUnit );
|
||||
GLi->bindTexture( GL_TEXTURE_2D, texture->getHandle() );
|
||||
|
||||
GLi->bindTexture( GL_TEXTURE_2D, texture->getHandle() );
|
||||
mCurrentTexture[ TextureUnit ] = texture->getHandle();
|
||||
|
||||
mCurrentTexture[ TextureUnit ] = texture->getHandle();
|
||||
|
||||
if ( TextureUnit && GLi->isExtension( EEGL_ARB_multitexture ) )
|
||||
setActiveTextureUnit( 0 );
|
||||
if ( TextureUnit && GLi->isExtension( EEGL_ARB_multitexture ) )
|
||||
setActiveTextureUnit( 0 );
|
||||
}
|
||||
|
||||
if ( coordinateType == Texture::CoordinateType::Pixels ) {
|
||||
GLfloat matrix[16] = {1.f, 0.f, 0.f, 0.f,
|
||||
@@ -141,6 +140,8 @@ void TextureFactory::bind( const Texture* texture, Texture::CoordinateType coord
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
mCurrentTexture[ TextureUnit ] = 0;
|
||||
}
|
||||
|
||||
if ( Texture::CoordinateType::Normalized != mLastCoordinateType ) {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include <eepp/ee.hpp>
|
||||
#include <eepp/graphics/fonttruetype.hpp>
|
||||
#include <eepp/graphics/text.hpp>
|
||||
|
||||
EE::Window::Window * win = NULL;
|
||||
FontTrueType * fontTest;
|
||||
FontTrueType * fontTest2;
|
||||
FontBMFont * fontBMFont;
|
||||
Text text;
|
||||
Text text2;
|
||||
Text text3;
|
||||
Text text4;
|
||||
|
||||
void mainLoop() {
|
||||
// Clear the screen buffer
|
||||
@@ -31,13 +31,15 @@ void mainLoop() {
|
||||
|
||||
text3.draw( ( win->getWidth() - text3.getTextWidth() ) * 0.5f, 560 );
|
||||
|
||||
text4.draw( ( win->getWidth() - text4.getTextWidth() ) * 0.5f, 590 );
|
||||
|
||||
// Draw frame
|
||||
win->display();
|
||||
}
|
||||
|
||||
EE_MAIN_FUNC int main (int argc, char * argv []) {
|
||||
// Create a new window
|
||||
win = Engine::instance()->createWindow( WindowSettings( 960, 640, "eepp - Fonts" ), ContextSettings( true ) );
|
||||
win = Engine::instance()->createWindow( WindowSettings( 1024, 768, "eepp - Fonts" ), ContextSettings( true ) );
|
||||
|
||||
// Set window background color
|
||||
win->setClearColor( RGB(230,230,230) );
|
||||
@@ -82,6 +84,14 @@ EE_MAIN_FUNC int main (int argc, char * argv []) {
|
||||
text3.setFillColor( Color(255,255,255,255) );
|
||||
text3.setOutlineColor( Color(0,0,0,255) );
|
||||
|
||||
fontBMFont = FontBMFont::New( "bmfont" );
|
||||
fontBMFont->loadFromFile( "assets/fonts/bmfont.fnt" );
|
||||
|
||||
text4.setFont( fontBMFont );
|
||||
text4.setString( "Lorem ipsum dolor sit amet, consectetur adipisicing elit." );
|
||||
text4.setCharacterSize( 45 );
|
||||
text4.setFillColor( Color::Black );
|
||||
|
||||
// Application loop
|
||||
win->runMainLoop( &mainLoop );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user