draw text to an image or a texture?

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
ayman
Posts: 51
Joined: Sat Feb 05, 2005 7:33 pm
Location: Piefke State

draw text to an image or a texture?

Post by ayman »

Hi there,

in order to avoid drawing a text every frame to the screen again and again I want to draw text to a texture and display this texture instead. So I have to redraw that texture only if the text changes.

But I have no idea how to draw text to an image or a texture with Irrlicht.

I suppose I have to ...
#1. create an image in memory,
#2. draw the text to it
#3. convert the image to a texture (or copy the image's pixel-buffer to the texture's pixel/image-buffer) and
#4. tell an already displayed quad or billboard to use this texture or tell the system that the texture has been changed.

Problems:
regarding #1:
No CImage- or CTexture class found.

regarding #2:
Today I draw text with font->draw() to the screen, where font is of type gui::IGUIFont*. But this "draw" method has no parameter to indicate a target image buffer. So I suppose it is set somewhere in this strange guienvironment-thingy, but I realy have no clue how that works. Maybe it's in the video driver? (Thats the problem with a class library in c++: things that belong to each other are never easy to find using the API-docs ...)
However: Found an IImage and an ITexture. But while looking into the API docs, both seem to have no pixel- or graphicsbuffer to hold the actual image. Well, they are just interfaces. So where is the image buffer?

regarding #3:
absolutely no idea. I thought there should be a constructor to create a texture from an image ... wouldn't that be a likely approach?

regarding #4:
Well, I hoped I could find something like it in the 13.RenderToTexture example, but no, I didn't.

Any hint to solve any of my four problems is most welcome.

Ayman
sp00n
Posts: 114
Joined: Wed Sep 13, 2006 9:39 am

Post by sp00n »

and there is also IGUIImage :)
search the forum and API, there is a method:

Code: Select all

virtual IImage* irr::video::IVideoDriver::createImageFromData  (  ECOLOR_FORMAT  format,  
  const core::dimension2d< s32 > &  size,  
  void *  data,  
  bool  ownForeignMemory = false,  
  bool  deleteMemory = true 
 ) 
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

The render to texture example is all you really need... render the text into the texture and then display the texture in the text's place, when the text changes, update the displayed texture.
Image Image Image
ayman
Posts: 51
Joined: Sat Feb 05, 2005 7:33 pm
Location: Piefke State

Post by ayman »

Hi again

thanks for the answers.

@sp00n: I will look into createImageFromData()

@JP: I have no clue how to render a text into a texture. Do you have an example?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

You have an example.

It's cunningly hidden in your Irrlicht sdk

examples/13.RenderToTexture

The examples should be your first port of call for any "how do I?" question.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
ayman
Posts: 51
Joined: Sat Feb 05, 2005 7:33 pm
Location: Piefke State

Post by ayman »

Hi

@rogerborg: Thanks for you ironical hint.
I was under the impression that it should be possible to draw a font to an image or texture and use just 2D-methods to acomplish this task.
I still can't believe that I have to use a camera to take a 2d-picture of a 3d-world to move a 2d-graphic (some text drawn using a font) into a 2d-texture. That sounds like overkill for a rather simple task to me. You're realy implying that?
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

No one is implying that, you can use the GUI functions on the render target texture just as anything else eg.

driver->setRenderTarget(MyRenderTargetTexture);
guienviroment->drawAll();

And you're done! (Make sure to do it inside a beginScene/endScene area).

Cheers
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

If you use any of Irrlicht's '2D' methods, then they'll render a textured quad anyway.

Getting the text into the texture could be easier though. Ideally we'd want something like a IGUIFont::drawToTexture() method that just blits the font bitmaps into the target texture, but I suffered an EPIC FAIL trying to hack one up over lunch. Sorry. :(
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply