Is it just me or is there a dearth of documentation on materials and using materials?
Right now I have
auto tile = GetSubsystem< Tile >();
std::string tileString = tile->GetTile( 0, 0, 0 );
const char* tileData = tileString.c_str();
MemoryBuffer tileMemoryBuffer( (void*)tileData, tileString.size() );
Image* tileImage = new Image( context_ );
tileImage->SetSize( MAP_TILE_SIZE, MAP_TILE_SIZE, 3 );
tileImage->Load( tileMemoryBuffer );
Texture2D* tileTexture2D = new Texture2D( context_ );
tileTexture2D->SetData( tileImage );
SharedPtr< Node > tileNode_;
tileNode_ = scene_->CreateChild( "tile" );
tileNode_->SetPosition( Vector3( 0, 3, 0 ) );
tileNode_->SetScale( Vector3( 1, 1, 1 ) );
StaticModel* tileObject = tileNode_->CreateComponent< StaticModel >();
tileObject->SetModel( cache->GetResource< Model >( "Models/Box.mdl" ) );
tileObject->SetMaterial( TU_DIFFUSE, tileTexture2D );
(Of course that last line throws an error because it expects an XML or JSON document instead of a 2D texture.)
It seems to me Urho3D demands a file be loaded from disk. I can create all the MemoryBuffer
s I like but it is always going to ask for a material? I read all your guys responses (thanks again!) and I do not see how the code ends. How do I create a material on the fly at runtime?
@SirNate0
I could not find a way around using the C-style string so I used the constructor that lets you specify size instead. I think that should fix that issue (if I was even seeing that).
@JSandusky
Thanks for the heads up. When I get this working I will shorten the code.
Edit
Re-reading your replies again I feel like I am overlooking something here. What am I glossing over?