1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2020 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "nel/misc/types_nl.h"
19 #include "nel/misc/event_emitter.h"
20 #include "nel/misc/event_listener.h"
21 #include "nel/misc/path.h"
22 #include "nel/misc/random.h"
24 // look at 3dinit example
25 #include "nel/3d/nelu.h"
27 // used for font management
28 #include "nel/3d/font_manager.h"
29 #include "nel/3d/computed_string.h"
30 #include "nel/3d/text_context.h"
31 #include "nel/3d/driver_user.h"
38 #endif // NL_OS_WINDOWS
46 using namespace NLMISC
;
48 int main(int argc
, char **argv
)
50 // look at 3dinit example
51 CNELU::init (800, 600, CViewport(), 32, true, 0, false, false);
53 NLMISC::CPath::addSearchPath(FONT_DIR
);
55 // create a font manager
56 CFontManager fontManager
;
58 // set the font cache to 2 megabytes (default is 1mb)
59 fontManager
.setMaxMemory(2000000);
63 tc
.init (CNELU::Driver
, &fontManager
);
65 // The first param is the font name (could be ttf, pfb, fon, etc...). The
66 // second one is optional, it's the font kerning file
67 tc
.setFontGenerator (NLMISC::CPath::lookup("beteckna.ttf"));
71 uint nbCount
= 100000;
72 TTicks startTick
= CTime::getPerformanceTime();
74 for(uint i
= 0; i
< nbCount
; ++i
)
76 uint fontSize
= rnd
.rand(200);
77 bool embolden
= rnd
.rand(1) == 1;
78 bool oblique
= rnd
.rand(1) == 1;
79 txt
= toString("Lorem ipsum %03d", fontSize
);
82 fontManager
.computeString(txt
, tc
.getFontGenerator(), CRGBA::White
, fontSize
, embolden
, oblique
, CNELU::Driver
, cs
);
85 TTicks endTick
= CTime::getPerformanceTime();
87 double deltaTime
= CTime::ticksToSecond(endTick
-startTick
);
88 std::string msg
= toString("Generated %d strings in %.2fs\n", nbCount
, deltaTime
);
90 nlinfo("%s", msg
.c_str());
91 printf("%s", msg
.c_str());
93 fontManager
.dumpCache ("font_pref_cache_dump.tga");
95 // look at 3dinit example