Save and delete texture from materialptr

Bady

04-09-2012 03:59:35

Hy!
I wrote a code what is load an image into a materialptr and give it to an entity.
Now I would like to save and delete an image from a materialptr, but I can't find anithing usable. (Maybe i search with wrong keywords)

Can you help me, how to solve this?

Bady

06-09-2012 03:53:27

Ok, if I put the code here, maybe will be more understandable:

private void texturamasol_Click(object sender, EventArgs e)
{
int lol;
for (int i = 1; i < ds.Falista.Rows.Count; i++)
{

lol = Convert.ToInt32(ds.Falista.Rows[i][0]);
if (lol == Convert.ToInt32(objtree.SelectedNode.Name))
{

if (2 == Convert.ToInt32(ds.Falista.Rows[i][2]))
{

se = ent.GetSubEntity(0);

MaterialPtr masolttextura = se.GetMaterial().Clone(aktobj.ToString() + ". - " + ds.Falista.Rows[i][1].ToString() + ":" + se.GetMaterial().Name);
MessageBox.Show(se.GetMaterial().Name);
//aktobj.ToString() + ". - " + ds.Falista.Rows[i][1].ToString() + ":" +

textúralista.Items.Add(aktobj.ToString() + ". - " + ds.Falista.Rows[i][1].ToString() + ":" + se.GetMaterial().Name);

}
}
}
}




here copy the object texture into the "masolttextura"
how can I save it as an image?
or it is impossible?

Tubulii

08-09-2012 22:15:47

A material is not a texture, i.e. you can not convert a material to a texture.

But of course, you can convert a texture to an image.

Bady

08-09-2012 23:48:19

A material is not a texture, i.e. you can not convert a material to a texture.

But of course, you can convert a texture to an image.


Ok, then... can you help me, how can I put the textureptr onto an entity,and copy the texture from an entity?

(texture: that image what you see on the loaded object)

Tubulii

09-09-2012 11:03:47

The material is a script that defines how a texture (e.g. from file) is drawn. Just thing of bump and normal maps. A material script for normal maps describes which images(diff and norm) and which shaders are used. You cannot simply "assign" an image (which is loaded by a texture class) to an entity. Instead you assign a material (script) to an entity. This offers a great flexibility. Material scripts also offer a fallback branch for unsupported shaders, e.g. you have one material (for normal mapping or similar) which has branches for both OpenGL and DirectX. On a system without Directx, the opengl branch would be used and vice versa.

I highly recommend to read both tutorials and, if there a still questions about materials and textures, this.
And converting a texture (the image in native memory, loaded by ogre) to an .Net image, should only be neccessary if you somehow modify it at runtime, otherwise you could simply "dive" into the material (class) at runtime and get the texture(ptr/ name) which has an "Origin" property with the filename of the loaded image.

Example:
You have a (very) basic material script (saved as a file on hard drive, with a propery name ;) ):
(note: this material has no shaders, copied from wiki)
material Template/texture_map
{
technique
{
pass
{
texture_unit
{
texture image.png
}
}
}
}

And you want to get the image name of the texture and load it into an bitmap:
Using resPtr = MaterialManager.Singleton.GetByName("Template/texture_map") '
Using m As Material = MaterialPtr.FromResourcePtr(resPtr)
Dim technique = m.GetTechnique(CUShort(0)) ' get first technique
Dim pass = technique.GetPass(CUShort(0)) ' get first pass
Dim state = pass.GetTextureUnitState(CUShort(0)) ' get first texture state
Dim filename as String
filename = state.TextureName ' get name of texture (i.e. the image name on hard drive)
' Or:
' Dim texture = state._GetTexturePtr() ' do not forget to dispose it! material and texture must be loaded!
' filename = texture.Origin
' do something with texture name, e.g. load it from file
Dim path = "" ' TODO: Get full path of 'filename'
Dim img = Drawing.Bitmap.FromFile(path)
End Using
End Using


If you compare the structure of the material script and the code snippet, you may notive that the material script is fully represented in ogre, i.e. you can create and modify any material script either in code or by an editor at development time.
Using this approach, you can get all informations about material scripts at runtime.

Ifi you still want to convert the texture to an .Net image, use TextureUnitState._GetTexturePtr() and read this.

Bady

13-09-2012 00:22:30

Thank you