[SOLVED] Using Chinese font & crash under OpenGL mode

Rscorpiox

11-07-2009 06:17:05

HI guys.

I am using the chinese font , it's worked fine under the D3D mode , but crash at OpenGL mode.

Here's my code.


class MyOwnGUI : public Ogre::FrameListener, public OIS::MouseListener
{
public:
MyOwnGUI()
{
button = mGUI->createWidget<MyGUI::Button>("Button", 10,10, 300, 80, MyGUI::Align::Bottom, "Main");
button->setFontName("mingliu.38");
button->setCaption(L"退出");
button->eventMouseButtonClick = MyGUI::delegates::newDelegate(this,&MyOwnGUI::exit);
button->eventMouseButtonClick = MyGUI::delegates::newDelegate(this,&MyOwnGUI::exit);
}

void MyOwnGUI::exit(MyGUI::WidgetPtr _widget)
{
button->hide();
}

private:
MyGUI::ButtonPtr button;
};


And my core_font.xml define like this.


<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Font">
.....
.....
<Font name="mingliu.38" default_height="38" source="mingliu.ttc" size="19" resolution="90" antialias_colour="false" space_width="4" tab_width="8" cursor_width="2" distance="5" offset_height="-2">
<Code range="33 126"/>
<Code range="19968 39999"/>
</Font>
</MyGUI>


The log shows

......
13:28:58: Texture: Default_Texture: Loading 1 faces(PF_BYTE_LA,1024x128x1) with 0 generated mipmaps from Image. Internal format is PF_BYTE_LA,1024x128x1.
13:29:05: OGRE EXCEPTION(3:RenderingAPIException): Zero sized texture surface on texture mingliu.38_Texture face 0 mipmap 0. Probably, the GL driver refused to create the texture. in GLTexture::_createSurfaceList at ..\src\OgreGLTexture.cpp (line 380)
13:29:05: Unregistering ResourceManager for type BspLevel
......


Don't know if it caused by myGUI .

But hope can find way to solve it here.

Thx for the reading .

Altren

11-07-2009 12:36:59

Actually MyGUI generate texture with fonts, that's why we provide ranged of characters to font. You use 20000 characters, so Ogre create really big texture and probably OpenGL can't create so big one. Look at MyGUI.log and show how big your texture is - there's something like
04:11:11 | Core | Info | TrueTypeFont 'Default' using texture size 1024 x 128 | .\src\MyGUI_TrueTypeFont.cpp | 167 with your font name.

Rscorpiox

11-07-2009 13:57:46

Oooh , so that's the reason !

Here's my texture size...


21:06:08 | General | Info | Font 'mingliu.38' using texture size 1024 x 16384 | .\src\MyGUI_Font.cpp | 205
21:06:08 | General | Info | Font 'mingliu.38' using real height 18 pixels | .\src\MyGUI_Font.cpp | 206


I think it's really a little bit huge size xD.

So.. the only way I can do is to set the exactly range on the font I wanna use?

Or change the font file (.ttf or .ttc) ??

Or there's other way to solve it..??

Thx for the reply!

Rscorpiox

11-07-2009 19:02:32

Sorry , but I wanna to ask another new question ^^".

Why my fonts seems so blur on the widget.

I search the Forum , and found it may be caused by the texture size setting is different form the font's size .

And the solve way says that "You'll get best font quality if font size in *.font and size in widgets are same."

But I don't find any MyGui's *.font file , it seems all my *.font file are in CEGUI system.

I don't know how to fix this, so plz help me around.

I've try the resolution and other parameter for more than one day.

Any advices are welcome.

Here's the screenshot



And thx for reading this.

Altren

12-07-2009 23:57:29

You using <Font name="mingliu.38" default_height="38" source="mingliu.ttc" size="19" ...
Open Demo_Font - you can play with different settings there and generate xml file with your font too (it aslo save texture into png file - just ignore it).

About *.font - we called xml files with font description such way long time ago, now all files usually called like *_font.xml .

Rscorpiox

13-07-2009 15:42:49

I got that!

Sorry post so many question in such a short time.

And thx for the patient and reply^^.

I've tried the Font_Demo before , but can't make it show chinese.

Maybe tried in wrong way. I'll try figure it out now.

Thanks a lot !!

Altren

13-07-2009 16:42:43

Oh, Demo_Font use hard coded ranges for Russian and English characters only. I'll fix it now.

Altren

13-07-2009 17:14:50

Done - update form svn.

Rscorpiox

14-07-2009 10:10:14

Thanks for the fast reply.

I've already update form the svn.

The Demo works just perfect !!

The Chinese character shows clear no matter what the size it is.

But the I set the same parameter as the demos in my project , the character still blur in my project .

Trying to work it out .

Thanks for the reply and solution .

It's really help a lot!!

Thanks again!

Rscorpiox

14-07-2009 12:27:35

I found the reason why the character seems so blur on my widget!

It's because the texture's size can't contain too many character ( range setting ).

The Demo_Font and my project shows perfect character when the range is small enough.

Once the range more than about 10000 character , the character became blur.

When in demo_font , I noticed the Texture_View's texture became rectangle (height > width) , that cause the blur.

Here's the result when range involve only 3 characters.


Here's the result when range involve more than 1000 characters.


Maybe there's some way to setting the texture's height and width?

Maybe it's a noob question xD.

Thx for reading.

Altren

14-07-2009 13:23:50

Problem not in setting width and height - problem that generated texture is too big. I see two ways how to make generated font texture smaller:
1) Use smaller size for your fonts: if you need all characters then it's probably something that may use all characters and I'm almost sure that in big texts or chats you need so big characters.
2) Reduce range of generated characters: if you need big characters then probably it is something like captions, headers, etc. and then you probably don't need all Chinese characters since there's not so many different characters used.

Rscorpiox

14-07-2009 14:53:21

Yeah , I think I would choose the solve way 2 !

Cause I'm not tring to make a chat room function , just for the caption or title.

But choose the exact range may take a while xD.

I'll mark this solved.

And thanks for the help , reply and advice ^^.

Have a nice day!! :D