GetMaterial

This function gets a surface's material. This function does not increment the material reference count.

Syntax

Returns

Returns the surface's material. If the surface has no material, NULL is returned.

Example

--Create a window
window = Window:Create()
context = Context:Create(window)
world = World:Create()
local camera = Camera:Create()
camera:SetRotation(35,0,0)
camera:Move(0,0,-3)
local light = DirectionalLight:Create()
light:SetRotation(35,35,0)

--Create model
model = Model:Box()

--Create a material
local material = Material:Create()
local surface = model:GetSurface(0)
surface:SetMaterial(material)

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

model:Turn(0,Time:GetSpeed(),0)

--Get the model surface
local surface = model:GetSurface(0)

--Get the surface material
local material = surface:GetMaterial()

--Modify the material color
local color = material:GetColor()
color.r = Math:Mod(color.r+Time:GetSpeed()*0.01,1)
color.g = Math:Mod(color.g+Time:GetSpeed()*0.012,1)
color.b = Math:Mod(color.b+Time:GetSpeed()*0.015,1)
material:SetColor(color)

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