Method: RBGLox::Window#exec

Defined in:
lib/rbglox/window.rb

#execObject

Opens the window and fires up the event loop



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/rbglox/window.rb', line 61

def exec
  glutInit

  glfwOpenWindowHint GLFW_WINDOW_NO_RESIZE, true
  #glfwOpenWindowHint GLFW_FSAA_SAMPLE, multisample
 
  glfwOpenWindow width, height, 0, 0, 0, 0, 32, 0, GLFW_WINDOW

  glfwSetWindowPos 0, 0
  glfwSetWindowTitle title
  glfwEnable GLFW_KEY_REPEAT
  glfwSwapInterval vsync

  glfwSetWindowSizeCallback lambda { |w, h| resize(w, h) }

  trap('INT') do
    glfwCloseWindow
  end

  unless watch.nil?
    puts "Watching #{watch} for changes ..."
    dw = DirectoryWatcher.new watch, :glob => "**/*", :pre_load => true, :interval => 1
    dw.add_observer do |*args|
      args.each do |event|
        reload event
      end
    end
    dw.start
  end

  glClearColor 0.2, 0.2, 0.2, 1
glClearDepth 1.0

  glEnable GL_DEPTH_TEST
glDepthFunc GL_LEQUAL 
  
  glShadeModel GL_SMOOTH
  glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST

  glEnable GL_TEXTURE_2D
glEnable GL_COLOR_MATERIAL
glEnable GL_NORMALIZE

  puts 'init'
  init

  while true
    break unless glfwGetWindowParam GLFW_OPENED
    break if key? GLFW_KEY_ESC
    
    update

    begin_frame
      draw
    end_frame
  end

  unless watch.nil?
    dw.stop
  end

  shutdown
  puts 'shutdown'
end