Posted: Wed Jul 08, 2009 2:02 am
I'm talking about TrueType fonts, since the TrueType library doesn't want to load from zips.
Official forum of the Irrlicht Engine
https://irrlicht.sourceforge.io/forum/
Why essential? Just don't put fonts in a zip. This is something that might be solved one day, but there's a lot of work to be done before that makes sense (like cleaning up the font-factory patch enough to include it in the engine as first step).Jookia wrote:Well it's kind of essential for this wrapper.
Well, you should definitely update to Irrlicht 1.5, or the SVN. Then you can read up more on the C2259 error here: http://msdn.microsoft.com/en-us/library/zxt206sk.aspx if the problem persists.amrit36 wrote:hello frnds.. I am compiling Irrlicht1.3 and FREETYPE library.
Everytime i got this ERROR
error C2259: 'irr::gui::CGUITTFont' : cannot instantiate abstract class
help me out of this.
No problem, but it's recommended that you know C++ programming before you attempt anything with Irrlicht. It's generally not a fun experience to learn Irrlicht and C++ at the same time.amrit36 wrote:thanks a lot. I have never done C++ programming before. But i have managed to do this. Thank you very much for your support.
Code: Select all
bool CGUITTFace::load(io::IReadFile* file)
{
if ( !library )
{
if (FT_Init_FreeType( &library ))
{
return false;
}
}
void* buffer;
file->read(&buffer, file->getSize());
// typedef unsigned char FT_Byte;
if(FT_New_Memory_Face(library, (FT_Byte*)buffer, sizeof(buffer), 0, &face) == true)
return false;
//if (FT_New_Face( library,filename,0,&face ))
//{
// return false;
//}
return true;
}
Code: Select all
IGUIFont* CGUIEnvironment::getFont(const c8* filename, u32 size, bool AA, bool TP)
{
// search existing font
SFont f;
IGUIFont* ifont=0;
if (!filename)
f.Filename = "";
else
f.Filename = filename;
f.Filename.make_lower();
core::stringc oldName = f.Filename;
f.Filename.append(":");
f.Filename.append(size);
s32 index = Fonts.binary_search(f);
if (index != -1)
{
if(Fonts[index].Font->getType() != EGFT_FREETYPE)
return Fonts[index].Font;
// We have to edit the AA and TP on the
// TrueType fonts.
CGUITTFont* font = (CGUITTFont*)Fonts[index].Font;
font->AntiAlias = AA;
font->TransParency = TP;
return (IGUIFont*)font;
}
f.Filename = oldName;
// font doesn't exist, attempt to load it
// does the file exist?
if (!FileSystem->existFile(filename))
{
os::Printer::log("Could not load font because the file does not exist", f.Filename.c_str(), ELL_ERROR);
return 0;
}
io::IXMLReader *xml = FileSystem->createXMLReader(filename);
if (xml)
{
// this is an XML font, but we need to know what type
EGUI_FONT_TYPE t = EGFT_CUSTOM;
bool found=false;
while(xml->read() && !found)
{
if (xml->getNodeType() == io::EXN_ELEMENT)
{
if (core::stringw(L"font") == xml->getNodeName())
{
if (core::stringw(L"bitmap") == xml->getAttributeValue(L"type"))
{
t = EGFT_BITMAP;
found=true;
}
else found=true;
}
}
}
if (t==EGFT_BITMAP)
{
CGUIFont* font = new CGUIFont(this, filename);
ifont = (IGUIFont*)font;
// change working directory, for loading textures
core::stringc workingDir = FileSystem->getWorkingDirectory();
FileSystem->changeWorkingDirectoryTo(FileSystem->getFileDir(f.Filename).c_str());
// load the font
if (!font->load(xml))
{
font->drop();
font = 0;
ifont = 0;
}
// change working dir back again
FileSystem->changeWorkingDirectoryTo(workingDir.c_str());
}
xml->drop();
}
if (!ifont)
{
// The FreeType library is great.
core::stringc name = FileSystem->getAbsolutePath(filename);
CGUITTFace* face = new CGUITTFace;
if(FileSystem->existFile(name.c_str()) == true)
{
io::IReadFile* file = FileSystem->createAndOpenFile(name.c_str());
if(face->load(file) == true)
{
CGUITTFont* font = new CGUITTFont(Driver);
if(font->attach(face, size) == false)
{
font->drop();
face->drop();
return 0;
}
else
{
font->AntiAlias = AA;
font->TransParency = TP;
ifont = (IGUIFont*)font;
}
}
else
{
face->drop();
file->drop();
}
}
else
{
face->drop();
CGUIFont* font = new CGUIFont(this, f.Filename.c_str());
ifont = (IGUIFont*)font;
if (!font->load(f.Filename.c_str()))
{
font->drop();
return 0;
}
}
}
// add to fonts.
f.Filename.append(":");
f.Filename.append(size);
f.Font = ifont;
Fonts.push_back(f);
return ifont;
}
Code: Select all
#include <irrlicht.h>
using namespace irr;
#define FONT "C:\\Documents and Settings\\Administrator\\My Documents\\My Projects\\C++\\Vox\\PeerState\\bin\\data\\font.ttf"
int main(void)
{
IrrlichtDevice* device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480), 32, false, false, false, 0);
device->setWindowCaption(core::stringw("PeerState").c_str());
device->getFileSystem()->addFolderFileArchive("data");
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* guiEnv = device->getGUIEnvironment();
guiEnv->getSkin()->setFont(guiEnv->getFont(FONT));
scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS();
cam->setPosition(core::vector3df(0, 0, 0));
device->getCursorControl()->setVisible(false);
guiEnv->addStaticText(L"This is an example of <font:font.ttf:18:FF0000>BIG RED TEXT <font:font.ttf:12:000000>and little black text.",
core::rect<s32>(10,10, 630, 470), true);
int fps = -1;
core::stringw string;
while(device->run() == true)
{
if(driver->getFPS() != fps)
{
fps = driver->getFPS();
string = core::stringw("PeerState - ");
string += fps;
string += " FPS";
device->setWindowCaption(string.c_str());
}
driver->beginScene(true, true, video::SColor(255, 128, 25, 25));
smgr->drawAll();
guiEnv->drawAll();
driver->endScene();
}
device->drop();
}
Code: Select all
void CGUITTFont::draw(const core::stringw& text2,.....) {
const wchar_t* text=text2.c_str();
//...........
}