TrueType font Support by FreeType Library

A forum to store posts deemed exceptionally wise and useful
Post Reply
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I don't think so. I have used a few fonts with 12pt (see here: http://www.michaelzeilfelder.de/Pics/fonts.png) and they are fine. But for good results I had to enable antialias and disable the transparency flag. Otherwise they didn't look nice.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
thespecial1
Posts: 135
Joined: Thu Oct 30, 2008 11:56 am
Location: UK
Contact:

Post by thespecial1 »

hi guys

I have used your TT library code successfully on win32 in VS2008 and am impressed with how easy that went compared to earlier implementations.

However

when I compile the project on linux (ubuntu intrepid) I am getting some weird errors on make, originally I was getting fails on "sprintf_s is not declared in the current scope", I have fixed this by using a C++ function to print the string. Now I am getting the following and am not sure if the above fix has really sorted out the underlying problem.

Code: Select all

Makefile:29: Building...
g++ -I./include -I/usr/X11R6/include -L/usr/lib/mqsql -lmysqlclient -O2 -ffast-math main.cpp murmuurFX.cpp murmuurGUI.cpp murmuurSQL.cpp murmuurBASE.cpp CGUITTFont.cpp cMirror.cpp -o ./bin/Linux/murmuur -L/usr/X11R6/lib -L./lib/Linux -lIrrlicht -lGL -lXxf86vm -lXext -lX11
main.cpp: In function ‘int main()’:
main.cpp:509: warning: deprecated conversion from string constant to ‘char*’
main.cpp:510: warning: deprecated conversion from string constant to ‘char*’
main.cpp:591: warning: deprecated conversion from string constant to ‘char*’
main.cpp:632: warning: deprecated conversion from string constant to ‘char*’
CGUITTFont.cpp: In member function ‘void irr::gui::CGUITTGlyph::cache(irr::u32, FT_FaceRec_*, irr::video::IVideoDriver*)’:
CGUITTFont.cpp:129: error: incompatible types in assignment of ‘std::basic_string<char, std::char_traits<char>, std::allocator<char> >’ to ‘irr::c8 [128]’
CGUITTFont.cpp:208: error: incompatible types in assignment of ‘std::basic_string<char, std::char_traits<char>, std::allocator<char> >’ to ‘irr::c8 [128]’
make: *** [all_linux] Error 1
anyone else got a similar issue??
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Not sure, but I updated now the version on my homepage. It contains a few bugfixes and compiles on a current debian system. Maybe it helps if you compare to that (or just use that version).

http://www.michaelzeilfelder.de/irrlicht.htm#TrueType
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
thespecial1
Posts: 135
Joined: Thu Oct 30, 2008 11:56 am
Location: UK
Contact:

Post by thespecial1 »

sweet, thanks for getting back to me, I have had a play with the version on your site, thou I have run into more interesting issues, again fine on win32 but on ubuntu i am getting a different set of errors

Code: Select all

Makefile:26: Building...
g++ -I./include -I/usr/X11R6/include -L/usr/lib/mqsql -lmysqlclient -L/usr/lib/libfreetype.a -O2 -ffast-math main.cpp murmuurFX.cpp murmuurGUI.cpp murmuurSQL.cpp murmuurBASE.cpp gui_freetype_font.cpp cMirror.cpp -o ./bin/Linux/murmuur -L/usr/X11R6/lib -L./lib/Linux -lIrrlicht -lGL -lXxf86vm -lXext -lX11
main.cpp: In function ‘int main()’:
main.cpp:509: warning: deprecated conversion from string constant to ‘char*’
main.cpp:600: warning: deprecated conversion from string constant to ‘char*’
main.cpp:641: warning: deprecated conversion from string constant to ‘char*’
/tmp/ccoslGEU.o: In function `CGUITTFace::load(char const*)':
gui_freetype_font.cpp:(.text+0x49f): undefined reference to `FT_New_Face'
gui_freetype_font.cpp:(.text+0x4c6): undefined reference to `FT_Init_FreeType'
/tmp/ccoslGEU.o: In function `CGUITTFace::~CGUITTFace()':
gui_freetype_font.cpp:(.text+0x4f5): undefined reference to `FT_Done_Face'
gui_freetype_font.cpp:(.text+0x51c): undefined reference to `FT_Done_FreeType'
/tmp/ccoslGEU.o: In function `CGUITTFace::~CGUITTFace()':
gui_freetype_font.cpp:(.text+0x585): undefined reference to `FT_Done_Face'
gui_freetype_font.cpp:(.text+0x5ac): undefined reference to `FT_Done_FreeType'
/tmp/ccoslGEU.o: In function `CGUITTFace::~CGUITTFace()':
gui_freetype_font.cpp:(.text+0x605): undefined reference to `FT_Done_Face'
gui_freetype_font.cpp:(.text+0x62c): undefined reference to `FT_Done_FreeType'
/tmp/ccoslGEU.o: In function `CGUITTGlyph::cache(unsigned int, FT_FaceRec_*, irr::video::IVideoDriver*)':
gui_freetype_font.cpp:(.text+0xa4b): undefined reference to `FT_Set_Pixel_Sizes'
gui_freetype_font.cpp:(.text+0xa5c): undefined reference to `FT_Load_Glyph'
gui_freetype_font.cpp:(.text+0xa88): undefined reference to `FT_Load_Glyph'
gui_freetype_font.cpp:(.text+0xcb5): undefined reference to `FT_Render_Glyph'
/tmp/ccoslGEU.o: In function `CGUIFreetypeFont::getGlyphByChar(wchar_t) const':
gui_freetype_font.cpp:(.text+0xf3d): undefined reference to `FT_Get_Char_Index'
collect2: ld returned 1 exit status
make: *** [all_linux] Error 1
am curious thou, I am using freetype v2.3.7 where as you were using an earlier version, do you think that would account for the issues above??

hmmmm

after looking into it abit more (and having the thought that it cant be the wrong version of freetype as this runs fine against the same version on win32) I am wondering if I am missing a library, considering that i have the two packages libfreetype6 and libfreetype6-dev installed via synaptic package manager on ubuntu. Was wondering if their is another package that i need, another possibility is that my make file isnt quite right, I have directly included the freetypelib.a (and checked that is is in /usr/lib) but am not used to these make files as Viz2008 usually shields me from such things.

Code: Select all

Target = murmuur

Sources = main.cpp murmuurFX.cpp murmuurGUI.cpp murmuurSQL.cpp murmuurBASE.cpp gui_freetype_font.cpp cMirror.cpp

# general compiler settings

CPPFLAGS = -I./include -I/usr/X11R6/include -L/usr/lib/mqsql -lmysqlclient -L/usr/lib/libfreetype.a

CXXFLAGS = -O2 -ffast-math

#CXXFLAGS = -g -Wall

#default target is Linux

all: all_linux


ifeq ($(HOSTTYPE), x86_64)

LIBSELECT=64

endif

# target specific settings

all_linux: LDFLAGS = -L/usr/X11R6/lib$(LIBSELECT) -L./lib/Linux -lIrrlicht -lGL -lXxf86vm -lXext -lX11

all_linux clean_linux: SYSTEM=Linux

all_win32: LDFLAGS = -L./lib/Win32-gcc -lIrrlicht -lopengl32 -lm

all_win32 clean_win32: SYSTEM=Win32-gcc

all_win32 clean_win32: SUF=.exe

# name of the binary - only valid for targets which set SYSTEM

DESTPATH = ./bin/$(SYSTEM)/$(Target)$(SUF)



all_linux all_win32:

	$(warning Building...)

	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(Sources) -o $(DESTPATH) $(LDFLAGS)



clean: clean_linux clean_win32

	$(warning Cleaning...)



clean_linux clean_win32:

	@$(RM) $(DESTPATH)



.PHONY: all all_win32 clean clean_linux clean_win32

FIXED, for anyone with the same issue to fix I needed to add -lfreetype onto the end of the CPPFLAGS line of the makefile
thespecial1
Posts: 135
Joined: Thu Oct 30, 2008 11:56 am
Location: UK
Contact:

Post by thespecial1 »

i have a new question however, while it is perfectly clear how to make the GUI elements use the TTFont I am struggling to get font output to display alongside the meshes.

I have tried to use addBillboardTextSceneNode, which does compile but crashes the program.

I have also tried to use font->print which does compile but isnt printing anything, besides I really need text as a node so that i can manipulate it.

ideazz anyone?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Does it also crash if you use one of the usual bitmap fonts?
In that case you should create an own forum thread for that problem. Anyway - we usually can't help fixing crashes without seeing some source.

There is a textscenenode - it sounds like you want to use that one.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
netpipe
Posts: 670
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Post by netpipe »

http://www.mediafire.com/?d31gdtshrec

linux version with CB file for 1.5 -- kudos and thanks
Fice
Posts: 5
Joined: Tue Jun 20, 2006 7:01 pm

Post by Fice »

Great work, thx

But i had problems with either memory leaks (not calling drop on the fonts) or exceptions (calling drop on every font).

Here's the code that produced it:

Code: Select all

irr::core::stringc str = fontFactory.makeFontName(TrueTypeFontParameters(L"./data/ariblk.ttf", 12, true, true));
	irr::gui::IGUIFont* fontDefault = fontFactory.addGUIFont(str.c_str());
	g_guienv->getSkin()->setFont(fontDefault, irr::gui::EGDF_DEFAULT);

	str = fontFactory.makeFontName(TrueTypeFontParameters(L"./data/ariblk.ttf", 12, true, true));
	irr::gui::IGUIFont* fontWindow = fontFactory.addGUIFont(str.c_str());
	g_guienv->getSkin()->setFont(fontWindow, irr::gui::EGDF_WINDOW);
And freeing everything:

Code: Select all

SAFE_DROP(fontDefault);
	SAFE_DROP(fontWindow);
The problem was, that you need to call "drop" for a font, but the font manager "forgot" to call "grab()" on a font when it was already there.


I changed (in gui_font_factory.cpp):

Code: Select all

  if  (itFont != mFontMap.end() )
        return itFont->second;
to:

Code: Select all

if  (itFont != mFontMap.end() ) {
		itFont->second->grab();
        return itFont->second;
	}
and everything works fine!

Hope that helps

lg
Fice
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Fice wrote: The problem was, that you need to call "drop" for a font, but the font manager "forgot" to call "grab()" on a font when it was already there.
Hm, I wont guarantee it, but I don't think that change is necessary. You should never call "drop" in Irrlicht for objects which you got by "add". You only call "drop" for objects which got from a "create" function or if you made a "grab" yourself. "add" basically means that it is handled by the manager and he drops all the object when he closes down.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Fice
Posts: 5
Joined: Tue Jun 20, 2006 7:01 pm

Post by Fice »

Then there is another problem, because i got a lot of memory leaks right after adding the fonts.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Do you have some small example where the memory leak can be reproduced? I did run some tests in valgrind yesterday, but I couldn't produce any leaks so far.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
knuck
Posts: 1
Joined: Mon Jun 01, 2009 9:47 pm

Post by knuck »

I've been using CuteAlien's version of this and everything works great, except for the dot character. I can't get it to output in any font.
Any ideas on what could be going wrong?

EDIT: So, while I was trying to change something else I noticed this in line 466:

Code: Select all

core::rect<s32>(0,0,imgw-1,imgh-1),
I removed the -1 part, and now the dots appear correctly. I just wonder if this will screw up something else in the code. So far everything has been working fine.
Jookia
Posts: 170
Joined: Wed Nov 19, 2008 1:11 am

Post by Jookia »

Code: Select all

	gui::CGUITTFace face;
	face.load("arial.ttf");
	
	gui::CGUITTFont font(driver);
	font.attach(&face, 12);
	
	guiEnv->getSkin()->setFont(&font);
CRASH

Code: Select all

Glyphs.reallocate(tt_face->face->num_glyphs);
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

@knuck: Thanks, that looks like a good change. As Irrlicht is usually using units and not pixels to describe rects your solution sounds correct to me. I've updated my patch.

@Jookia: Maybe "face" is going out of scope?

But also the font-interface has changed some more in the meantime. I plan to make adding ttf easier soon, but so far I haven't found time for that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Jookia
Posts: 170
Joined: Wed Nov 19, 2008 1:11 am

Post by Jookia »

I don't know. :S
Post Reply