require "opengl"
require "glut"
$light_diffuse = [1.0, 0.7, 0.7, 1.0]
$light_position = [1.0, 1.0, 1.0, 0.0]
$n = [
[-1.0, 0.0, 0.0], [0.2, 1.0, 0.0], [1.0, 0.0, 0.0],
[0.0, -1.0, 0.0], [0.0, 0.3, 1.0], [0.0, 0.0, -1.0] ]
$faces = [
[0, 1, 2, 3], [3, 2, 6, 2], [7, 6, 5, 4],
[4, 2, 1, 2], [5, 6, 2, 1], [7, 4, 0, 3] ]
def drawbox
for i in (0..5)
gl.begin(gl::quads)
gl.normal(*($n[i]))
gl.vertex($v[$faces[i][0]])
gl.vertex($v[$faces[i][1]])
gl.vertex($v[$faces[i][2]])
gl.vertex($v[$faces[i][3]])
gl.end()
end
end
display = proc.new {
gl.clear(gl::color_buffer_bit | gl::depth_buffer_bit)
drawbox
glut.swapbuffers
}
def myinit
$v = [[-1, -1,1],[-1, -1,-1], [-1,1,-1], [-1,1,1], [1, -1,1],
[1, -1,-1], [1, 1,-1], [1,1,1]]
gl.light(gl::light0, gl::diffuse, $light_diffuse)
gl.light(gl::light0, gl::position, $light_position)
gl.enable(gl::light0)
gl.enable(gl::lighting)
gl.enable(gl::depth_test)
gl.matrixmode(gl::projection)
glu.perspective(40.0, 1.0, 1.0, 10.0)
gl.matrixmode(gl::modelview)
glu.lookat(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
gl.translate(0.0, 0.0, -1.0)
gl.rotate(60, 1.0, 0.0, 0.0)
gl.rotate(-20, 0.0, 0.0, 1.0)
end
glut.init
glut.initdisplaymode(glut::double | glut::rgb | glut::depth)
glut.createwindow("red 3d lighted cube")
glut.displayfunc(display)
myinit
glut.mainloop()
用户登录
还没有账号?立即注册
用户注册
投稿取消
| 文章分类: |
|
还能输入300字
上传中....
sad浅梦