Doris
light.lua
This displays a teapot which is lit by a single light. You can
rotate the teapot using the rotator. The spinners change the RGB
values of the light and the light can be moved from left to right
with a spinner.
Screenshot
Source Code
-- Try some lights
-- $Id: light.lua,v 1.5 2002/06/24
07:06:31 trout Exp $
-- colour of our light: r,g,b
colour = {.6,.3,0}
-- create a matrix
rotatemat=Matrix:new()
-- The callback function which renders
our scene.
function RenderScene()
-- Note: we
have to put this code here as RenderScene is only called
-- after all
of our GLUT and Doris objects have been created.
-- ie. we
cant create the light before we create the window (below)
if
not first then
first = 1
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glLight(GL_LIGHT0, GL_POSITION, {10,10,0})
glLight(GL_LIGHT0, GL_AMBIENT, colour)
glClearColor(.9,.9,.9,1.0)
end
glClear(GL_DEPTH_BUFFER_BIT + GL_COLOR_BUFFER_BIT)
gluLookAt(0,0,5, 0,0,0,
0,1,0)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadMatrix(rotatemat)
Render:teapot{solid=1}
glPopMatrix()
end
-- Create our window and specify a name
and window rendering function
wmain = Window:create{
title="Doris: Light example",
render=RenderScene
}
-- Put a sub window at the bottom of the
screen
sw = SubWindow{ parent=wmain, side="bottom" }
-- Add an object rotator to the bottom
of the screen that
-- manipulates the matrix we
created.
Rotator{ parent=sw, text="Rotate teapot",
value=rotatemat, line="|", spin = .9
}
-- Some spinners to manipulate the
colour...
Spinner{ parent=sw, text="Red",
value=colour[1], type="float", limits={0,1},
update=function(c)
colour[1]=c
glLight(GL_LIGHT0, GL_AMBIENT, colour)
end
}
Spinner{ parent=sw, text="Green",
value=colour[1], type="float", limits={0,1},
update=function(c)
colour[2]=c
glLight(GL_LIGHT0, GL_AMBIENT, colour)
end
}
Spinner{ parent=sw, text="Blue",
value=colour[1], type="float", limits={0,1}, line="v",
update=function(c)
colour[3]=c
glLight(GL_LIGHT0, GL_AMBIENT, colour)
end
}
-- A spinner to move the light left and
right
Spinner{ parent=sw, text="Move light",
value=10, type="float", limits={-10,10}, line="v",
update=function(p)
glLight(GL_LIGHT0, GL_POSITION, {p,10,0})
end
}
Back