1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
quit = false
function resize_func(w, h)
local ratio = w / h
print('====== resize')
glMatrixMode(gl.PROJECTION)
glLoadIdentity()
glViewport(0,0,w,h)
gluPerspective(45,ratio,1,1000)
glMatrixMode(gl.MODELVIEW)
glLoadIdentity()
end
angle = 0
angle2 = 0
previous_time = 0
function display_func()
if quit then return end
local cur_time = glutGet(glut.ELAPSED_TIME)
local delta = (cur_time - previous_time) / 1000
previous_time = cur_time
glClear(gl.COLOR_BUFFER_BIT + gl.DEPTH_BUFFER_BIT)
glPushMatrix()
glTranslate(0,0,-5)
glRotate(angle, 0, 1, 0)
glRotate(angle2, 0, 0, 1)
glColor3(1,0,0)
-- glutWireSphere(0.75, 10, 10)
glutSolidTeapot(0.75)
-- glColor3(1,1,1)
-- glutWireTeapot(0.75)
glPopMatrix()
angle = angle + 200 * delta
angle2 = angle2 + 170 * delta
frames = frames + 1
if math.mod(frames, 100) == 0 then
local fps = frames * 1000 / (glutGet(glut.ELAPSED_TIME) - start_time);
print('fps: ' .. fps .. ' time: ' .. glutGet(glut.ELAPSED_TIME) .. ' frames: ' .. frames)
end
glutSwapBuffers()
end
function keyboard_func(key,x,y)
print('keyboard' .. key)
if key == 27 then glutDestroyWindow(window) quit = true end
end
glutInitWindowSize(600,600)
glutInitWindowPosition(0,0)
glutInitDisplayMode(glut.RGB + glut.DOUBLE + glut.DEPTH)
window = glutCreateWindow("luabind, glut-bindings")
glutDisplayFunc(display_func)
glutIdleFunc(display_func)
glutKeyboardFunc(keyboard_func)
glutReshapeFunc(resize_func)
resize_func(600,600)
start_time = glutGet(glut.ELAPSED_TIME)
frames = 0
glutMainLoop()
|