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

--Create a window
window = Window:Create()
context = Context:Create(window)
world = World:Create()

camera = Camera:Create()
camera:SetRotation(35,0,0)
camera:Move(0,0,-6)

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

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

local light = DirectionalLight:Create()
light:SetRotation(35,35,0)

local model = NULL

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 do

pivot:Turn(0,0.5,0)

if window:Closed() or window:KeyHit(Key.Escape) then return false end

Time:Update()
world:Update()
world:Render()
context:Sync()
end