SetVertexColor
This function sets a vertex color.
Syntax
- void SetVertexColor(int index, float r, float g, float b, float a)
- void SetVertexColor(int index, const Vec4& color)
Parameters
- index: the surface index to set.
- r: the red component of the color to set.
- g: the green component of the color to set.
- b: the blue component of the color to set.
- a: the alpha component of the color to set.
- color: the color 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 a model
model = Model::Box();
//Load a material
Material* material = Material::Load("Materials/Concrete/concrete_dirty.mat");
model->SetMaterial(material);
material->Release();
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
Leadwerks::Time::Update();
//===========================================
//Begin Model Modification
//===========================================
Surface* surface = model->GetSurface(0);
for (int v = 0; v < surface->CountVertices(); v++)
{
Vec3 position = surface->GetVertexPosition(v);
Vec3 normal = surface->GetVertexNormal(v);
Vec2 texcoords = surface->GetVertexTexCoords(v);
Vec4 color = surface->GetVertexColor(v);
position = position + normal * Vec3(Math::Sin(Leadwerks::Time::GetCurrent() / 10.0) * 0.005);
texcoords += Leadwerks::Time::GetSpeed() / 100.0;
color.r = Math::Mod(color.r + Leadwerks::Time::GetSpeed()*0.01, 1);
color.g = Math::Mod(color.g + Leadwerks::Time::GetSpeed()*0.011, 1);
color.b = Math::Mod(color.b + Leadwerks::Time::GetSpeed()*0.012, 1);
surface->SetVertexPosition(v, position);
surface->SetVertexNormal(v, normal);
surface->SetVertexTexCoords(v, texcoords);
surface->SetVertexColor(v, color);
}
//Update the surface AABB
surface->UpdateAABB();
//Update the model local and global AABBs so the renderer keeps proper track of it
model->UpdateAABB(Entity::LocalAABB | Entity::GlobalAABB);
//===========================================
//End Model Modification
//===========================================
world->Update();
world->Render();
context->Sync(false);
}
return 0;
}