The material is a script that defines how
(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.
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)
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)
' 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)
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
and read this