PDA

View Full Version : Text as Textures


INOVxDev
11-20-2009, 11:57 PM
Is there a way to place text on objects. This would be much like that of a texture. The only way I can think to achieve this is to create on the fly bitmaps of text, and apply them as a texture.

Perhaps I am missing a simpler way to do this?

Thank you.

mikeheck
11-23-2009, 05:50 AM
Is there a way to place text on objects. This would be much like that of a texture. The only way I can think to achieve this is to create on the fly bitmaps of text, and apply them as a texture.
Perhaps I am missing a simpler way to do this?

That is the way to do it, but it's much simpler than it sounds, because we've automated the process in Open Inventor. Take a look at the SoRenderToTextureProperty (http://www.vsg3d.com/support/oiv_doc/ReferenceManual/html/class_so_render_to_texture_property.html) node. You can plug this into an SoTexture2 (http://www.vsg3d.com/support/oiv_doc/ReferenceManual/html/class_so_texture2.html) node in place of a static image (see the renderToTextureProperty field). The render to texture node takes any scene graph in its node field, renders that scene graph as-needed and provides the resulting image to the texture node. In .iv file format pseudo-code the texture node might look like this:

Texture2 {
renderToTextureProperty
RenderToTextureProperty {
size 128 128
component RGB_TRANSPARENCY
node Separator {
DirectionalLight {}
Material { diffuseColor 0.5 1 0.5 }
Font {
size 1.2
renderStyle TEXTURE
}
Text3 {
string "text!"
justification CENTER
}
}
}
}

Looking at the SoRenderToTextureProperty node:
The size field specifies the dimensions of the resulting image in pixels. It's somewhat arbitrary but a larger image size allows a higher quality image.

The component field specifies an RGB or (as in the above example) RGBA image. For an RGB image you can specify the background color. For an RGBA image the background is transparent. That makes sense here because we want to blend the text onto some geometry.

The node field contains the scene graph. Note this scene graph is completely separate from the scene graph being rendered, so it needs its own camera and light. In this case for simplicity we're using the default camera, which is an orthographic volume spanning -1 to 1. If your text string doesn't fit in this view volume you'll need to provide an explicit camera node (see SoOrthographicCamera). Then we provide a default directional light, set the material color, the text size and the string to render.


If we slap that on a cube using DECAL, CLAMP_TO_BORDER, etc. it looks like this:
http://www.mc3dviz.com/openinventor-forum/attachment.php?attachmentid=94&stc=1&d=1258958663