Page 1 of 13

TrueType font Support by FreeType Library

Posted: Wed Sep 29, 2004 2:20 pm
by zgock
Hi,
I made Class CGUITTFonts. Subclass of IGUIFont that supports TrueType font.
Can Render TrueType Font and AntiAlias font supported.
and Can Render Asian MultiBytes fonts.
OPENGL,DirectX and Software Renderer ready.

Here is ScreenShot
Image
Image

And Here is Sample(Source and Win32 bin and Sample Japanese TTFont)
http://www.zgock-lab.net/IrrFreeType.zip

Under DirectX8,9 with AntiAlias seems slow :cry: .
Cos DirectX Driver cannot Render 32bit A8R8G8B8 Texture with Draw2DImage().
(Under OpenGL,It is fast enough :wink: )
Anyone has any Idea about it?

///////////////////////////////////////////////////////////////////
Zgock
Irrlicht A GoGo - Irrlicht Tutorial in Japanese http://www.zgock-lab.net/irrlicht/

Posted: Wed Sep 29, 2004 2:34 pm
by bal
Wow, this is great stuff!

Posted: Wed Sep 29, 2004 6:04 pm
by Tyn
The zip file seem corrupted, you didn't use the Windows zip thing did you?

Posted: Wed Sep 29, 2004 6:05 pm
by Tyn
The zip file seem corrupted, you didn't use the Windows zip thing did you?

Posted: Wed Sep 29, 2004 7:25 pm
by bal
The zip file works fine here. Just like the Japanse text and the antialiasing. But with your English TT fonts there are weird stripes:

Image

Without antialiasing, it's like the font got cutted :)

Image

Posted: Thu Sep 30, 2004 2:23 am
by cmoibenlepro
I tested it, great work! :D

the result:
1- the japanese font (with and without anti-aliasing) works perfectly (I think... in fact I don't know if it's ok because I'm not able to read it :wink: but it looks good)

2- the english font look bad when there is no anti-aliasing, for me it's worse that the bal's screenshots. With anti-alias I don't get those stange lines though.
Can you use another font for english (like arial or times new roman) so I could check if it fix the problems?


BTW, I think that it should be posted in the "project announcements" forum...

Posted: Thu Sep 30, 2004 1:39 pm
by zgock
Modified Source and Example. plz test with this.

My PC cannot occur that ploblem.
( Pentium-M 1.6G/RADEON 9000 Mobility/Catalyst 4.8 )

this example depends on Windows. cos loading english font from Windows System Directory.
http://www.zgock-lab.net/IrrFreeType.zip

Posted: Thu Sep 30, 2004 4:50 pm
by bal
Now it works perfect! Extremely nice work!

Posted: Fri Oct 01, 2004 3:42 pm
by cmoibenlepro (not logged)
Now it works! :D

Posted: Fri Oct 01, 2004 3:45 pm
by zgock
Fixed DirectX Problem. Even fast as OPENGL :D

(I was idiot, I forgot setTextureCreationFlag() :shock: )

http://www.zgock-lab.net/IrrFreeType.zip

On My PC (Pentium-M 1.6G/RADEON9000) these are FPS on sample.

OPENGL 950-1050 FPS
DirectX8 900-950 FPS
DirectX9 600-700 FPS
Software 90-150 FPS :wink:

Posted: Sat Oct 09, 2004 2:14 pm
by darkliquid
I tried this out under Linux, linking to my system freetype libraries but when it gets to the font.attach() bit, it crashes :(

Posted: Sat Oct 09, 2004 4:58 pm
by zgock
attach() will clash if true type file cannot be found.
ttf files are placed in right location?
can i see ur code?

Posted: Sat Oct 09, 2004 5:43 pm
by darkliquid
right, i built the demo you made, and that worked fine with whatever fonts I threw at it, loaded from the current directory.

Now I have another problem.

I have the exact same thing setup in my main app I'm writing, but when I call the font->draw(blah, blah, blah) it dies. I traced the fault down to when it calls 'FT_Get_Char_Index' in the 'getGlyphByChar' function.

I don't know why this is happening though. Here is the code for the class that has it in:

CDemoIntro.h

Code: Select all

#include <CDemoStage.h>
#include <irrlicht.h>
#include <CGUITTFont.h>

class CDemoIntroEvents;

class CDemoIntro : public CDemoStage {

	public:
		CDemoIntro(IrrlichtDevice * device);
		~CDemoIntro();
	
		// Methods
	
		int run();
		void quit();
	
		virtual bool OnEvent(irr::SEvent event);
	
	private:
		gui::CGUITTFont * font;
		video::ITexture* irrlichtLogo;
		video::ITexture* darkliquid;
		scene::IMesh * mesh;
		scene::IAnimatedMesh * hillplane;
};
and CDemoIntro.cpp

Code: Select all

#include <CDemoIntro.h>
#include <CGUITTFont.h>
#include <irrlicht.h>
#include <iostream>

using namespace irr;

CDemoIntro::CDemoIntro(IrrlichtDevice * device)
{

	//Initialise all the variables
	driver = device->getVideoDriver();
	timer = device->getTimer();
	smgr = device->getSceneManager();
	gui = device->getGUIEnvironment();
	fader = device->getGUIEnvironment()->addInOutFader(); // must come after gui init
	running=0; // tell the main app that the demo is now running (0 = true, 1 = false)
	quitting=false;
	scene::ISceneNode * root = smgr->getRootSceneNode();
	
	// Add a camera
	smgr->addCameraSceneNode(0,core::vector3df(-250,200,-250),core::vector3df(0,-400,0));
	
	// Load font
	//font = gui->getFont("../media/fonthaettenschweiler.bmp");
	font = new gui::CGUITTFont(driver);
	gui::CGUITTFace face;
	if(face.load("../media/battle3.ttf")) 
		std::cout << "Loaded font face..." << std::endl;
	font->attach(&face,24);
	//font->TransParency=true;
	//font->AntiAlias=true;
	std::cout << "Attached font face..." << std::endl;
	
	// Set start time for demo
	sceneStartTime = timer->getTime();
	timeForThisStage = 14000;

	// Load the textures
	irrlichtLogo = driver->getTexture("../media/irrlichtlogo.bmp");
	darkliquid = driver->getTexture("../media/darkliquid.bmp");
	driver->makeColorKeyTexture(darkliquid,core::position2d<int>(0,0));
	
	// Scene manager fancy stuff
	std::cout << "mesh..." << std::endl;
	hillplane = smgr->addHillPlaneMesh("myHill",
                core::dimension2d<f32>(20,20),
                core::dimension2d<s32>(40,40), 0, 0,
                core::dimension2d<f32>(0,0),
                core::dimension2d<f32>(10,10));
	std::cout << "mesh2..." << std::endl;
	mesh = smgr->getMesh("myHill")->getMesh(0);
	std::cout << "node..." << std::endl;
	scene::ISceneNode * node = smgr->addWaterSurfaceSceneNode(mesh, 3.0f, 300.0f, 30.0f,root);
	node->setPosition(core::vector3df(0,0,0));
	node->setMaterialTexture(0,driver->getTexture("../media/water.jpg"));
	node->setMaterialTexture(1,driver->getTexture("../media/stones.jpg"));
	node->setMaterialType(video::EMT_REFLECTION_2_LAYER);
	std::cout << "node2..." << std::endl;
	scene::ISceneNode * lightnode = smgr->addLightSceneNode(root,core::vector3df(0,0,0),video::SColorf(1.0f,0.6f,0.7f,1.0f),600.0f);
	scene::ISceneNodeAnimator* anim=0;
	anim=smgr->createFlyCircleAnimator(core::vector3df(0,150,0),200.0f);
	lightnode->addAnimator(anim);
	anim->drop();
	
	// Setup the InOutFader
    fader->setColor(video::SColor(0,0,0,0));
    fader->fadeIn(2000);
}


CDemoIntro::~CDemoIntro()
{
	// TODO: put destructor code here
	std::cout << "Deallocating resources..." << std::endl;
	smgr->getRootSceneNode()->removeAll();
	font->drop();
	fader->remove();
	irrlichtLogo->drop();
	darkliquid->drop();
	driver->removeAllTextures();
}

int CDemoIntro::run() {
	
	if(((timer->getTime()-sceneStartTime)>timeForThisStage) && timeForThisStage != -1 || quitting) {
		quit();
	}
	smgr->drawAll();
	driver->draw2DRectangle(video::SColor(128,255,255,255),core::rect<s32>(0,375,640,425));
	driver->draw2DImage(irrlichtLogo,core::position2d<int>(10,10));
	font->draw(L"Hello TrueType",core::rect<s32>(0,240,640,240),video::SColor(128,255,64,64),true);
	//driver->draw2DImage(darkliquid,core::position2d<int>(280,340),core::rect<s32>(0,0,360,140),0,video::SColor(128,32,255,32),false);
	gui->drawAll();
	
	return running;
}

void CDemoIntro::quit() {
	
	if(!quitting && fader->isReady()) {
		fader->fadeOut(2000);
		quitting=true;
	}
	
	if (fader->isReady()) {
		std::cout << "End of demo..." << std::endl;
		running=1;
	}
}

bool CDemoIntro::OnEvent(SEvent event) {
	
	if (event.EventType == EET_KEY_INPUT_EVENT &&
		event.KeyInput.Key == KEY_ESCAPE &&
		event.KeyInput.PressedDown == false)
	{
		// user wants to quit.
		quit();
	}
	return false;
}

Posted: Sat Oct 09, 2004 5:53 pm
by darkliquid
This is what GDB says, if it helps:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
0x40209bd3 in FT_Get_Char_Index (face=0x8195d50, charcode=72) at ftobjs.c:2302
2302    ftobjs.c: No such file or directory.
        in ftobjs.c
#0  0x40209bd3 in FT_Get_Char_Index (face=0x8195ff8, charcode=72) at ftobjs.c:2302
#1  0x0804e264 in irr::gui::CGUITTFont::getGlyphByChar (this=0x81991b0, c=72) at CGUITTFont.cpp:207
#2  0x0804ec24 in irr::gui::CGUITTFont::getWidthFromCharacter (this=0x81991b0, c=72) at CGUITTFont.cpp:229
#3  0x0804e334 in irr::gui::CGUITTFont::getDimension (this=0x81991b0, text=0x80e6160) at CGUITTFont.cpp:220
#4  0x0804e455 in irr::gui::CGUITTFont::draw (this=0x81991b0, text=0x80e6160, position=@0xbffff980, color={color = -2130755520}, hcenter=true,
    vcenter=false, clip=0x0) at CGUITTFont.cpp:264
#5  0x0804d0be in CDemoIntro::run (this=0x8198ee8) at CDemoIntro.cc:98
#6  0x0804b5d4 in CDemo::runDemo (this=0x810e590) at CDemo.cc:66
#7  0x0804af1a in main () at main.cc:13

Posted: Sat Oct 09, 2004 7:32 pm
by zgock
u r placing CGUITTFace instance as Local variable.
it will purge when constructor is done.
on drawing, CGUITTFont needs "Living" CGUITTFace too.
u have to place CGUITTFace as class variable same as ur CGUITTFont.

thx