GetMaterial

This function gets an entity's material.

Syntax

Remarks

This function does not increment the material's reference count. If you want to hold onto a handle to the material so that it won't be deleted if the entity is deleted, increment the reference count. When you are done with this handle, call Release() to decrement the reference count:
Material* material = entity->GetMaterial()
if (material) material->AddRef()

Example

#include "Leadwerks.h"

using namespace Leadwerks;

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();
camera->SetRotation(35, 0, 0);
camera->Move(0, 0, -5);

Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);

//Create a model
Entity* entity = Model::Box();

//Load a material
Material* material = Material::Load("Materials/Grass/grass01.mat");

//Set the entity material
entity->SetMaterial(material);

while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;

Leadwerks::Leadwerks::Time::Update();
world->Update();
world->Render();

context->SetBlendMode(Blend::Alpha);
context->DrawText("Material: " + material->GetPath(), 2, 2);

context->Sync();
}
}