SetMaterial
This function sets a surface material.
Syntax
- void SetMaterial(Material* material)
Parameters
- material: the new material to set.
Returns
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;
Model* model = 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();
camera->SetRotation(35, 0, 0);
camera->Move(0, 0, -3);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);
//Create model
model = Model::Box();
//Create a material
Material* material = Material::Create();
Surface* surface = model->GetSurface(0);
surface->SetMaterial(material);
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
model->Turn(0, Leadwerks::Time::GetSpeed(), 0);
//Get the model surface
Surface* surface = model->GetSurface(0);
//Get the surface material
Material* material = surface->GetMaterial();
//Modify the material color
Vec4 color = material->GetColor();
color.r = Math::Mod(color.r + Leadwerks::Time::GetSpeed()*0.01, 1);
color.g = Math::Mod(color.g + Leadwerks::Time::GetSpeed()*0.012, 1);
color.b = Math::Mod(color.b + Leadwerks::Time::GetSpeed()*0.015, 1);
material->SetColor(color);
Leadwerks::Time::Update();
world->Update();
world->Render();
context->Sync();
}
return 0;
}