SetRenderTarget

This functions sets a camera to render directly to a texture. The texture can be used in a material and applied to an object, or drawn onscreen. You can use this feature for making CCTV systems, rear-view mirrors, or other visual effects.

Syntax

Parameters

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, -6);

Camera* camera2 = Camera::Create();
camera2->Move(0, 0, -4);
camera2->SetClearColor(1, 0, 0);
Entity* pivot = Pivot::Create();
camera2->SetParent(pivot);

Texture* tex = Texture::Create(512, 512);
Material* mtl = Material::Create();
mtl->SetShader("Shaders/Model/Diffuse.shader");
mtl->SetTexture(tex);
camera2->SetRenderTarget(tex);

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

Model* model = Model::Box();
model->SetPosition(-2, 0, 0);
model->SetMaterial(mtl);

model = Model::Cylinder();
model->SetColor(0.0, 1.0, 0.0);
model->SetPosition(0, 0, 0);

model = Model::Cone();
model->SetColor(0.0, 0.0, 1.0);
model->SetPosition(2, 0, 0);

while (true)
{
pivot->Turn(0, 0.5, 0);
if (window->Closed() || window->KeyHit(Key::Escape)) break;

Leadwerks::Leadwerks::Time::Update();
world->Update();
world->Render();
context->Sync();
}
return 0;
}