[SOLVED]Creating image from text

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
xirtamatrix
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

[SOLVED]Creating image from text

Post by xirtamatrix »

Hi,

Say I have a wall with a name-plate on it. User can enter text from the application GUI. I want to display that text on the name-plate (which is a simple plane mesh). I'm lookin for ideas/suggestions how this could be achieved.

One way it could work is, to create an image from the text which user entered, and then apply that as texture to the plane mesh. This should work, only I dont know how to convert user-enterd text into an image. Is it possible?

Thanks in advance!

/regards
Last edited by xirtamatrix on Thu Apr 28, 2011 4:40 pm, edited 1 time in total.
to live, is natural; to die, is not!
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Re: Creating image from text

Post by Sylence »

xirtamatrix wrote:One way it could work is, to create an image from the text which user entered, and then apply that as texture to the plane mesh. This should work, only I dont know how to convert user-enterd text into an image. Is it possible?
Yes that would be the way I would implement such a feature.

Take a look at the Render To Texture Tutorial. There you will find everything you need. Instead of drawing the whole scene you would just use an IGUIFont to draw the string :)
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
xirtamatrix
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Re: Creating image from text

Post by xirtamatrix »

Sylence wrote:Take a look at the Render To Texture Tutorial. There you will find everything you need. Instead of drawing the whole scene you would just use an IGUIFont to draw the string :)
Thank You Sylence, but sorry I'm nor understanding.
In case of rendering the scene to texture, we set a camera to look at the scene, and then draw to render target.

In our case, what is the camera supposed to look at? How and where do we draw the text?

I also cant understand where does the IGUIFont()->draw() supposed to draw the text?

Thanks.
to live, is natural; to die, is not!
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

If you need just to draw the text in 3d, you can use (or check the source how its done):
scene::ITextSceneNode
http://irrlicht.sourceforge.net/docu/cl ... _node.html
xirtamatrix
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Post by xirtamatrix »

greenya wrote:If you need just to draw the text in 3d, you can use (or check the source how its done):
scene::ITextSceneNode
http://irrlicht.sourceforge.net/docu/cl ... _node.html
No, thank you, ITextSceneNode is not what I need. I mentioned explicitly that I need to show user-entered text on top of a plane mesh. What part of it is hard to understand?
to live, is natural; to die, is not!
xirtamatrix
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Post by xirtamatrix »

Never mind, I think I can use the code from this topic with some modifications.

Thanks to everyone who tried to help!
to live, is natural; to die, is not!
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

You don't need any camera. Just do the following (pseudo code. Haven't worked with irrlicht since ages):

Code: Select all

ITexture* renderTarget = driver->addRenderTargetTexture();

driver->setRenderTarget( renderTarget );
font->draw( L"Hello World" );
driver->setRenderTarget( 0 );

plane->setTexture( renderTarget );

smgr->drawAll();
IGUIFont (or the whole GUI system) doesn't care about cameras since it's supposed to be a 2D overlay.

After the call to draw() the texture "renderTarget" will be a texture that has the rendered text in it. After that you can use the texture just like a texture that you loaded from a file.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
xirtamatrix
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Post by xirtamatrix »

Sylence wrote:You don't need any camera. Just do the following (pseudo code. Haven't worked with irrlicht since ages):

Code: Select all

ITexture* renderTarget = driver->addRenderTargetTexture();

driver->setRenderTarget( renderTarget );
font->draw( L"Hello World" );
driver->setRenderTarget( 0 );

plane->setTexture( renderTarget );

smgr->drawAll();
IGUIFont (or the whole GUI system) doesn't care about cameras since it's supposed to be a 2D overlay.

After the call to draw() the texture "renderTarget" will be a texture that has the rendered text in it. After that you can use the texture just like a texture that you loaded from a file.
Wow, I did'nt see this before, that simplifies my task a lot!

Thanks a LOT Sylence :)
to live, is natural; to die, is not!
Post Reply