It must be said that I am a lazy.ProgramA common Lazy habit is to create a tool or find a convenient way to serve your work.
Recently, I felt that the resources (textures, mesh, shaderfile, etc.) in the program were too messy and I wanted to sort them out, so I wanted to strip the Ogre Resource Manager for my use.
Initial results stripped the resourcegroupmanager class.
//------------------------------------------------------------------------------
// Initialize root ogre: Root * mroot;
//------------------------------------------------------------------------------
Mroot = new ogre: Root ();
//------------------------------------------------------------------------------
// Load the resource file
//------------------------------------------------------------------------------
// Load resource paths from config file
Ogre: configfile CF;
Cf. Load (resfilename );
// Go through all sections & settings in the file
Ogre: configfile: sectioniterator SECI = Cf. getsectioniterator ();
Ogre: String secname, typename, archname;
While (SECI. hasmoreelements ())
{
Secname = SECI. peeknextkey ();
Ogre: configfile: settingsmultimap * settings = SECI. getnext ();
Ogre: configfile: settingsmultimap: iterator I;
For (I = settings-> begin (); I! = Settings-> end (); ++ I)
{
Typename = I-> first;
Archname = I-> second;
Ogre: resourcegroupmanager: getsingleton (). addresourcelocation (
Archname, typename, secname );
}
}
//------------------------
1. After the above settings, the image class of Ogre can be used by us, because the internal resourcegroupmanager has been initialized, for example:
Ogre: image;
Image. Load ("Terrain/heightmap.png", "Tex ");
Why do we emphasize the use of the image class. Because it can load almost all 2D image resources, and the color of all pixels is saved in the image, it is very convenient to process the image, because the color of each pixel on the image can be freely accessed and modified. After modification, call image. Save ("fileimage.png") to save the modified image.
2. Use the following method to obtain the stream of a file
Datastreamptr dstream = resourcegroupmanager: getsingleton (). openresource ("Terrain/heightmap.png", "Tex", true );
Memorydatastream stream (dstream );
Then, you can use the d3dxcreatetexturefromfileinmemoryex function in d3d to create a Texture buffer, so that you can use the Ogre Resource Manager to load texture images in the d3d program.
Hresult hR = d3dxcreatetexturefromfileinmemoryex (
Mpdev,
Stream. getptr (),
Stream. Size (),
D3dx_default, d3dx_default, // dims
Nummips,
Usage,
D3dfmt_unknown,
Pool,
D3dx_default,
D3dx_default,
0, // Color Key
Null, // SRC box
Null, // palette
& Mpnormtex );
//------------------------
It seems that detailed resource management is not involved yet. Let's talk about it next time... Let me study again.
PS: Based on ogre1.6.4 SDK