###############################
Loading a Material from Library
###############################

The materials provided by REDmaterials can be easily loaded from the library resource files. Here is an example with the Concrete04 material:

.. code:: cpp 
        
    // Get a pointer to the RED resource manager.
    RED::Object* resmgr = RED::Factory::CreateInstance( CID_REDResourceManager );
    RED::IResourceManager* iresmgr = resmgr->As< RED::IResourceManager >();

    // Create the file to handle the loading.
    RED::Object* redfile = RED::Factory::CreateInstance( CID_REDFile );
    if( !redfile )
    RC_TEST( RED_FAIL );

    RED::IREDFile* ifile = redfile->As< RED::IREDFile >();
    RED::StreamingPolicy policy;
    RED::FileHeader header;
    RED::FileInfo finfo;
    RED::Vector< unsigned int > ctx;

    // Load the scene from realistic.red.
    RC_TEST( ifile->Load( "concrete_Concrete04.red", iresmgr->GetState(), policy, header, finfo, ctx ) );

    RC_TEST( RED::Factory::DeleteInstance( redfile, iresmgr->GetState() ) );

    // Retrieve the realistic material from the scene.
    RED::Object* realistic = iresmgr->FindMaterial( "material" );
    if( !realistic )
    RC_TEST( RED_FAIL );
    RED::IMaterial* irealistic = realistic->As< RED::IMaterial >();

    // Retrieve the realistic material controller.
    RED::Object* realisticctrl = iresmgr->GetMaterialController( realistic );
    RED::IMaterialController* irealisticctrl = realisticctrl->As< RED::IMaterialController >();

After the loading, the controller is simply retrieved with the ``RED::IResourceManager::GetMaterialController`` function. 