[solved] how to use font textures in material script?

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
cyrfer
Orc
Posts: 424
Joined: Wed Aug 01, 2007 8:13 pm
Location: Venice, CA, USA
x 7

[solved] how to use font textures in material script?

Post by cyrfer »

Hello,
I would like to update text on objects in my scene, e.g. a L.E.D. display for a business. How can I make a material for my 3D object that uses a texture generated by a font file? I expect I will need a shader uniform to update the characters, but I'm still stuck on how to use define a material which uses a font-texture at all. I am using OGRE 1.6.5 right now, but will upgrade to the development branch if necessary.

Thanks!
Last edited by cyrfer on Sun Apr 25, 2010 11:22 pm, edited 2 times in total.
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 50

Re: how to use font textures in scene?

Post by madmarx »

You just need to use the texture already generated by the font if its a ttf.
I think it called the name of your font file.
Anyway you can check this name through Font::getMaterial ().
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
cyrfer
Orc
Posts: 424
Joined: Wed Aug 01, 2007 8:13 pm
Location: Venice, CA, USA
x 7

Re: how to use font textures in scene?

Post by cyrfer »

I tried using a texture based on a font definition in my material script with no luck. I don't see any documentation that it is even possible. However, the material script supports loading images for texture animation, cube map sides, etc. If the feature existed, I think they would have documented it. If the texture is already being created, it seems that adding support for this in the material script language would be an easy addition for the right person. Here is what I'm trying:

Here's the font script:

Code: Select all

font_arial
{
    type truetype
    source arial.ttf
    size 16
    resolution 96
}
Here's the mateial:

Code: Select all

material text_character
{
	receive_shadows off
	technique
	{
		pass
		{
		lighting off

		texture_unit
		{
			// I've tried a few names, like 'arial.ttf' or just 'arial'
			texture font_arial 2d 0
			binding_type fragment
			filtering none
		}
		}
	}
}
And here is the error:
OGRE EXCEPTION(6:FileNotFoundException): Cannot locate resource font_arial in resource group Example_Text or any other group.
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 50

Re: how to use font textures in material script?

Post by madmarx »

I use regularly fonts texture on meshes so there is something funny here :wink: .

Here is what I would do if I were you :
1/ make sure you create + load the fonts first. Access its name (check that you got the right texture name). Use the font manager.
2/ add the resource location to the material script and then load the corresponding resourcegroup (or parse directly the script to add the resource).
3/ you can use the material.
"If the feature existed, I think they would have documented it."
The feature exists. But I suspect there is not so much a need for a documentation on this subject, since this is pretty straight forward/easy to use.
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
cyrfer
Orc
Posts: 424
Joined: Wed Aug 01, 2007 8:13 pm
Location: Venice, CA, USA
x 7

Re: how to use font textures in material script?

Post by cyrfer »

madmarx wrote: 1/ make sure you create + load the fonts first.
Hey madmarx, I think this is the step I need to add to my code...

I was not sure where to add it because I would like to use the material scripts for my mesh. When I load a mesh using this material, I would like to guarantee that the font-texture has already been created. Can I register a resource listener for .fontdef files that will make textures for me? I was hoping the texture would already exist if I have a .fontdef file. Is this true? Do I even need a listener if the texture is created by the .fontdef?

As I was saying before, it would be really nice if we could do all this with just a material script. OGRE would only need to make the script parsing support a new texture "source" (they already support like 'anim_texture' and 'cubic_texture' in the 'texture_unit' section). I don't know that code or else I would try to patch OGRE right now.
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 50

Re: how to use font textures in material script?

Post by madmarx »

Code: Select all

material TESTFontMaterial
{
	technique
	{
		pass 
		{
			scene_blend alpha_blend
			
			texture_unit
			{
				texture BlueHighwayTexture
			}
		}
	}
}
works without problem by me (BlueHighway is the name of a ogre font of ttf type).
Tested on Ogre1.6 on the Environment sample. I only updated the .cpp with :

Code: Select all

ent->setMaterialName("TESTFontMaterial"); // instead of ent->setMaterialName("Examples/EnvMappedRustySteel");
There is also a material already created at texture loading : "ent->setMaterialName("Fonts/BlueHighway");" which works too.

If you know already to load a mesh, then you know how to load anything (texture/ material etc...) since its the same. As a consequence, just load the fonts and textures first, and later the material, and later the mesh, and this will run.

This is extremely basic Ogre usage. I think you should check the tutorials if you got problem with that.
I suppose this feature is not documented because it is obvious :lol: .
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
cyrfer
Orc
Posts: 424
Joined: Wed Aug 01, 2007 8:13 pm
Location: Venice, CA, USA
x 7

Re: how to use font textures in material script?

Post by cyrfer »

Madmarx,
I added what you said to my C++ code like this:

Code: Select all

    Ogre::FontManager& fmgr = Ogre::FontManager::getSingleton();
    Ogre::ResourceManager::ResourceMapIterator rIter = fmgr.getResourceIterator();
    while( rIter.hasMoreElements() )
    {
        Ogre::ResourcePtr r = rIter.getNext();
        if( r->getLoadingState() != Ogre::Resource::LOADSTATE_LOADED )
        {
            r->load();
        }
    }
Now my log file says this:
Font font_arialusing texture size 512x256
Info: Freetype returned null for character 160 in font font_arial
Texture: font_arialTexture: Loading 1 faces(PF_BYTE_LA,512x256x1) with 0 generated mipmaps from Image. Internal format is PF_BYTE_LA,512x256x1.
Now I can see the magic name that is assigned to the texture resource (it adds "Texture" to the font name). I changed my material script to say this:

Code: Select all

material text_character
{
	receive_shadows off
	technique
	{
		pass
		{
			lighting off
            scene_blend alpha_blend

            texture_unit
            {
                texture font_arialTexture
                binding_type fragment
                filtering none
            }
		}
}
I am showing a rectangle on the screen with this material. The rectangle rendered completely black until I added the 'scene_blend alpha_blend'. Now I see the characters like I hoped. Thanks for all your help!
User avatar
edoardo
Kobold
Posts: 36
Joined: Thu Apr 28, 2011 8:44 am
Location: Torino, Italy

Re: how to use font textures in material script?

Post by edoardo »

madmarx wrote:

Code: Select all

material TESTFontMaterial
{
	technique
	{
		pass 
		{
			scene_blend alpha_blend
			
			texture_unit
			{
				texture BlueHighwayTexture
			}
		}
	}
}
works without problem by me (BlueHighway is the name of a ogre font of ttf type).
...
Hi Madmarx,
that's simple enough and works for me too :)

I'd like to use the font texture on a material created on the fly and with a texture unit that uses the Font Texture; for now is what I'm doing and it's just fine.

The problem for me is that I'd like to COLOUR the Font Texture characters (that are white) with the vertex color, mantaining the lighting disabled, like in this example material (I solved partially the problem enabling lighting, then put emissive = diffuse = vertexcolour, but naturally it's sensible to lights in scene... I don't want this).


Have you got any very basic/simple idea on how to use the vertex color (or put it by hand somewhere in the material) to color the white characters of the font texture?


I know this is basic material knowledge, but I lack it, sorry!

Thank you very much for any help

P.S.: I attach 3 screenshots of a 3D Label that I've done via ManualObject, each character is a TriangleStrip with 2 triangles (quad) and a color in each vertex.
In the colored example, I manually set Diffuse and Emissive to match the desired color, but that's not good because color is influenced from environment lights, and I don't want this to happen.
You do not have the required permissions to view the files attached to this post.
--
"Fatti non foste a viver come bruti, | ma per seguir virtute e canoscenza."
"You were not made to live your lives as brutes, | but to be followers of virtue and knowledge."
(Divina Commedia, Inferno, Canto XXVI, 119 – 120)
machineonpointer
Kobold
Posts: 35
Joined: Fri Dec 06, 2013 4:15 am

Re: [solved] how to use font textures in material script?

Post by machineonpointer »

I tried , it doesnot work...