glut_bindings.lua 1.5 KB

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