SetMaterial
This function sets an entity's material.
Syntax
- void Entity::SetMaterial(Material* material, bool recursive = false)
Parameters
- material: the new material to set. This value may be NULL if no material is to be used.
- recursive: if set to true, the function will be called recursively for all children.
Remarks
This function will increment the reference count of the new material and decrement the reference count of the old material (if they exist).
Example
#include "Leadwerks.h"
using namespace Leadwerks;
Entity* entity = NULL;
int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
World* world = World::Create();
Camera* camera = Camera::Create();
DirectionalLight::Create()->SetRotation(45, 35, 0);
//Create a material
Material* material = Material::Create();
material->SetColor(1, 0, 0);
//Create a model and apply the material to it
Model* model = Model::Sphere();
model->SetPosition(0, 0, 2);
model->SetMaterial(material);
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
Leadwerks::Time::Update();
world->Update();
world->Render();
context->Sync();
}
return 0;
}