How to render text?

Problems building or running the engine, queries about how to use features etc.
User avatar
myak
Halfling
Posts: 40
Joined: Fri May 23, 2003 10:46 pm
Location: Warsaw, Poland

How to render text?

Post by myak »

My question is (I think) quite simple to answer: how to render text using a specified font to a texture?
Marcin Jakubowski
jabber://myak@chrome.pl
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67

Post by sinbad »

You can either use TextAreaOverlayElement and render to a texture, or you could FreeType directly, like we do.
User avatar
myak
Halfling
Posts: 40
Joined: Fri May 23, 2003 10:46 pm
Location: Warsaw, Poland

Post by myak »

sinbad wrote:you could FreeType directly, like we do.
Can you please point me where to look for the example? I guess it's somewhere in the GUI/Overlay-related code but I can't find it.

The closest match I've found is TextAreaOverlayElement::updateGeometry() but it's not really what I'm looking for. I want to have Texture object which I can use in TextureUnitState to define new Material.

PS. Reading the documentation online is not nice because of messed CSS styles.. :/
Marcin Jakubowski
jabber://myak@chrome.pl
User avatar
DWORD
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 1365
Joined: Tue Sep 07, 2004 12:43 pm
Location: Aalborg, Denmark

Post by DWORD »

Font::loadResource() may be a guess.
User avatar
myak
Halfling
Posts: 40
Joined: Fri May 23, 2003 10:46 pm
Location: Warsaw, Poland

Post by myak »

Thanks :) I think it will really help me.. at least when I finally understand it :))
Marcin Jakubowski
jabber://myak@chrome.pl
User avatar
myak
Halfling
Posts: 40
Joined: Fri May 23, 2003 10:46 pm
Location: Warsaw, Poland

Post by myak »

Ok, using FreeType gives me an extra dependency in my project and I can't use it..

So what I have left is RenderTexture, which I really have no idea how to use. I looked at RenderToTexture sample and here's what my doubts are:

1. RenderTexture is updated every frame, am I right? I need it to render once at the loading stage of my game and then I want to assign that texture to a entity. And that's all :) How to set it up that way?

2. On the viewport I created for the camera I'm using for RenderTexture I have to show an overlay with my text fitting entire viewport, right? So I have to create an overlay and call showOverlays(false) on my main viewport and showOverlays(true) on that I'm using for rendertexture, right?

3. And I have to repeat these things N times if I want to create N textures?

There has to be an easier way :) I'm not very familiar with RenderTextures. Ok, I'm not at all familiar with them.. so if anyone has a better idea, please share :)
Marcin Jakubowski
jabber://myak@chrome.pl
User avatar
DWORD
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 1365
Joined: Tue Sep 07, 2004 12:43 pm
Location: Aalborg, Denmark

Post by DWORD »

myak wrote:Ok, using FreeType gives me an extra dependency in my project and I can't use it..
Why can't you use it? Ogre already does, but I think it's statically linked.

Edit:
myak wrote:I need it to render once at the loading stage of my game and then I want to assign that texture to a entity. And that's all :) How to set it up that way?
This doesn't sound like it needs to be dynamic, but I guess it's not the same text every time you start the game, or...? Otherwise you could just make a texture with the text on it in Gimp or something. But you probably thought about that.
User avatar
myak
Halfling
Posts: 40
Joined: Fri May 23, 2003 10:46 pm
Location: Warsaw, Poland

Post by myak »

DWORD wrote:Why can't you use it? Ogre already does, but I think it's statically linked.
Hmm, that sounds like a good idea :) Have to check it out.

[EDIT]
Checked. Doesn't work :( Adding those lines to my code:

Code: Select all

		FT_Library ftLibrary;
		FT_Init_FreeType( &ftLibrary );
		FT_Done_FreeType(ftLibrary);
Resulted in 2 unresolved externals. When I compiled and added freetype 2.1.9 my exe was 321 kb bigger than before.

[/EDIT]
DWORD wrote: Otherwise you could just make a texture with the text on it in Gimp or something. But you probably thought about that.
Yeah, I thought about that. But including 200 textures would dramatically increase download size. What I want is when user runs the game for the first time textures are generated and saved to disk. When the user runs the game for the second time textures are read from the disk.
Marcin Jakubowski
jabber://myak@chrome.pl
User avatar
DWORD
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 1365
Joined: Tue Sep 07, 2004 12:43 pm
Location: Aalborg, Denmark

Post by DWORD »

myak wrote:Yeah, I thought about that. But including 200 textures would dramatically increase download size. What I want is when user runs the game for the first time textures are generated and saved to disk. When the user runs the game for the second time textures are read from the disk.
I see your point, and of course it's good to keep down the download size, so I really like your idea. Just keep in mind that Ogre's binaries already take up around 5 MB (unpacked). I just made a quick test: 200 textures with large text (512x64x32bit PNG) uses around 1 MB (unpacked). Of course it's probably easier to generate the text automatically, instead of manually 'painting' 200 textures, though, but it takes more code.
User avatar
myak
Halfling
Posts: 40
Joined: Fri May 23, 2003 10:46 pm
Location: Warsaw, Poland

Post by myak »

DWORD wrote:I just made a quick test: 200 textures with large text (512x64x32bit PNG) uses around 1 MB (unpacked). Of course it's probably easier to generate the text automatically, instead of manually 'painting' 200 textures, though, but it takes more code.
Hmm.. you're right! It uses 1MB :) I just automatically thought that 200 textures would use too much space so I started thinking about a work around. Long time ago, when I was using Allegro library, I wrote a program which was generating text to an image, so that's not the problem :)

But it would be nice to know how to do it anyway.
I just got another idea. If it was possible to get Image or even raw uchar* from Texture (I haven't found the way to do it yet) I could blit glyphs from the texture created by font to my texture.
Marcin Jakubowski
jabber://myak@chrome.pl
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67

Post by sinbad »

You can do it in Azathoth, direct texture access has been made possible through HardwarePixelBuffer.