Class: Scene

Inherits:
Object
  • Object
show all
Includes:
DefaultScene
Defined in:
lib/scene.rb

Class Method Summary collapse

Methods included from DefaultScene

#display, #keyboard, #mouse, #reshape, #timer

Class Method Details

.displayObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/scene.rb', line 9

def self.display
  initialize
  
  glutDisplayFunc(Proc.new { display_proxy })
  glutTimerFunc(10, Proc.new { timer_proxy }, 0)
  glutKeyboardFunc(Proc.new { |key, x, y| keyboard_proxy(key, x, y) })
  glutMouseFunc(Proc.new { |button, state, x, y| instance.mouse(button, state, x, y) })
  glutReshapeFunc(Proc.new { |width, height| instance.reshape(width, height) })
  
  glutMainLoop
end

.display_proxyObject



44
45
46
47
48
# File 'lib/scene.rb', line 44

def self.display_proxy
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  instance.display
  glutSwapBuffers
end

.initializeObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/scene.rb', line 27

def self.initialize
  glutInit
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
  glutInitWindowSize(800, 800)
  glutCreateWindow('Super Simple Scene')
  
  glClearColor(0, 0, 0, 0)
  glEnable(GL_DEPTH_TEST)
  
  glMatrixMode(GL_PROJECTION)
  gluPerspective(60, 1, 1, 10)
  glMatrixMode(GL_MODELVIEW)
  gluLookAt(0, 0, -4, 0, 0, 1, 0, 1, 0)
  
  instance # Allow initializer overrides
end

.instanceObject



23
24
25
# File 'lib/scene.rb', line 23

def self.instance
  @instance ||= new
end

.keyboard_proxy(key, x, y) ⇒ Object



59
60
61
# File 'lib/scene.rb', line 59

def self.keyboard_proxy(key, x, y)
  instance.keyboard(key.chr, x, y)
end

.timer_proxyObject



50
51
52
53
54
55
56
57
# File 'lib/scene.rb', line 50

def self.timer_proxy
  @time ||= Time.now.to_f
  elapsed = Time.now.to_f - @time
  @time = Time.now.to_f
  instance.timer(elapsed)
  glutPostRedisplay
  glutTimerFunc(10, Proc.new { timer_proxy }, 0)
end