TrueType font Support by FreeType Library

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

Post by CuteAlien »

Yes, I've updated the gui_freetype_font files recently so they should work now with 1.6
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
stefbuet
Competition winner
Posts: 495
Joined: Sun Dec 09, 2007 4:13 pm
Location: france

Post by stefbuet »

Well, I tryed you code and I get a runtime error (error repport...) :?

Code: Select all



CGUITTFace face;
face.load("GameData/showcard.ttf");
CGUIFreetypeFont *font=new CGUIFreetypeFont(device->getVideoDriver());
font->grab();
font->attach(&face, 12); //runtime error here
font->AntiAlias=true;



Edit : the error occurs when calling the "attach" function.
CuteAlien
Admin
Posts: 9674
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Probably because you allocate face on the stack. Try it with face = new CGUITTFace;
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
stefbuet
Competition winner
Posts: 495
Joined: Sun Dec 09, 2007 4:13 pm
Location: france

Post by stefbuet »

Ok, I made it working.

I had a problem with the attach function call. I was sending the value of my face variable instead of its memory adress. So it's now working, however I got a problem as this is getting more and more time to attach faces to font... Morover there're some bad values comming from getWidth/getHeight functions. All there problems are not in the original version I modified to fit in Irrlicht 1.6 however your version don't make some letters desapearing randomly when using the attach function :shock:
Also my version wasn't making chars desapearing randomly when used with Irrlicht 1.4.2, so there must be something I changed which do that strange stuff.

I'll try to mix both versions :)

EDIT : I think characters are not rendering randomly because of a bug in FreeType.
Thanks.
CuteAlien
Admin
Posts: 9674
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

The original version had several memory bugs, so I wouldn't be too surprised on some random behaviour. I don't think I changed the width, but the height is more or less wrong in both versions. My latest workaround does return as height the largest height of any single characters used so far - which is why I initialize in CGUIFreetypeFont::attach a bunch of characters which formerly caused trouble. If some more cause problems please tell me which ones. There is possibly a better solution as TrueType actually knows the correct height itself but I found no way to access it without doing some calculations for which I didn't manage to find all necessary values (but I only invested a few hours before I gave and used my workaround).

edit: If you have an example which compiles and can be used to reproduce any problems ... I'm always glad to get those.
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
t0rt0r0
Posts: 76
Joined: Fri May 22, 2009 11:02 am

Post by t0rt0r0 »

To get memory back you should also remove the textures used to draw the font (tex && tex16 iirc) in the destructor ;)
CuteAlien
Admin
Posts: 9674
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Textures are not grab()'ed so no need to release them. Though they should probably be grab()'ed usually.
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
t0rt0r0
Posts: 76
Joined: Fri May 22, 2009 11:02 am

Post by t0rt0r0 »

I mean by calling driver->removeTexture()
But maybe I'm wrong ;)
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

I have recently gone through and made many changes to CGUITTFont, making it work for Irrlicht 1.6+.

Some changes I have made:
  • Compiles with Irrlicht 1.6 and up (added missing functionality).
  • You can turn hinting on or off.
  • Kerning.
  • Multi-line text.
  • Ability to specify font sizes in pixels or points.
  • Comments to the source files.
  • Various bug fixes.
You can download my changes here:
http://nalin.suckerfree.org/public/code ... _Nalin.zip

Update 11/23/2009:
I fixed a problem where a glyph's true height was not calculated correctly. Also, I added some code to work around Irrlicht's handling of text height. Irrlicht assumes you will be using bitmapped fonts with a set size. FreeType has a set glyph size, but the glyph may hang under the origin, giving it a larger "true" height. This fixes a problem where characters like 'j' and 'g' would get cut off in tooltip text, which calculates the text size based on the single character 'A', instead of the whole text string.
thespecial1
Posts: 135
Joined: Thu Oct 30, 2008 11:56 am
Location: UK
Contact:

Post by thespecial1 »

good work mate, just re enabled freetype with 1.6, had some errors, started to fix and then spotted your post, multi line is especially useful ;0)
CuteAlien
Admin
Posts: 9674
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I haven't found time yet to merge Nalin's changes, but I found a bug in my bugfix for the font-heights. I had cached the largest Glyph for a Face instead for the Font - so it was messed up if you used the same Font with different Sizes. An updated version is as usual on my website.

I've also put my fontmanager back on the website, as it allows using fonts easier without the need to patch the engine. So unless you need serialization that is easier to use.
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
tinhtoitrangtay
Posts: 70
Joined: Tue Oct 28, 2008 12:59 pm

Post by tinhtoitrangtay »

WOW very great
thank CuteAlien i hope next version support font unicode
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

thanks Nalin, looks very nice ingame 8)
Never take advice from someone who likes to give advice, so take my advice and don't take it.
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

I got an e-mail from a Mr. Hong about a crash issue he encountered with my modified class. I have fixed the issue he encountered as well as a separate crash issue and uploaded a fixed version.

The issue Mr. Hong discovered was a crash if you tried to delete a CGUITTFont object. CGUITTGlyph was improperly reference counted. The other issue is if you tried to delete a CGUITTFace object and create a new one (a class static variable wasn't being reset correctly on the first deletion.)

You can download my changes here:
http://nalin.suckerfree.org/public/code ... _Nalin.zip

---

Also, I made a version of my CGUITTFont class that works in conjunction with my UTF-16 string class, which can be found here:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=36406

You can download the class here:
http://nalin.suckerfree.org/public/code ... _Nalin.zip

Basically, this version will allow you to have proper multi-byte character support in Windows.
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Code: Select all

  myFace = new CGUITTFace;
  myFace->load("data/font.ttf");

  myFont = new CGUITTFont(guienv);
  myFont->attach(myFace, 8, true);
  myFont->AntiAlias    = true;
  myFont->Transparency = true;
  myFont->AutoHinting  = true;
  myFont->FontHinting  = true;

  mySkin->setFont(myFont);

  std::cout << myFont->getReferenceCount() << std::endl; // = 2
  std::cout << myFace->getReferenceCount() << std::endl; // = 1
There is still something mysterious to me :) Is there a reason why the refcount for myFont is 2? So, do I have to drop it twice? Also, "delete myFont" doesn't work for me (delete myFace does). It crashes in

IrrArray.h

Code: Select all

	//! Clears the array and deletes all allocated memory.
	void clear()
	{
		for (u32 i=0; i<used; ++i)
			allocator.destruct(&data[i]); // CRASH HERE

		allocator.deallocate(data); // delete [] data;
		data = 0;
		used = 0;
		allocated = 0;
		is_sorted = true;
	}
or is it my bad?
Never take advice from someone who likes to give advice, so take my advice and don't take it.
Post Reply