Class: GLApp
- Inherits:
-
Object
- Object
- GLApp
- Defined in:
- lib/glapp.rb
Defined Under Namespace
Modules: Engine
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(engine, width, height, title = "") ⇒ GLApp
constructor
A new instance of GLApp.
- #keyboard(key, modifiers) ⇒ Object
- #keyboard_up(key, modifiers) ⇒ Object
- #mouse_active_motion(x, y) ⇒ Object
- #mouse_click(button, state, x, y) ⇒ Object
- #mouse_passive_motion(x, y) ⇒ Object
- #resize(width, height) ⇒ Object
- #show ⇒ Object
- #special_keyboard(key, modifiers) ⇒ Object
- #special_keyboard_up(key, modifiers) ⇒ Object
- #update(seconds) ⇒ Object
Constructor Details
#initialize(engine, width, height, title = "") ⇒ GLApp
Returns a new instance of GLApp.
5 6 7 8 9 10 11 12 |
# File 'lib/glapp.rb', line 5 def initialize(engine, width, height, title = "") @engine = engine @width = width @height = height @title = title @running = false self.gl_init end |
Instance Method Details
#draw ⇒ Object
18 19 20 |
# File 'lib/glapp.rb', line 18 def draw @engine.draw end |
#keyboard(key, modifiers) ⇒ Object
22 23 24 |
# File 'lib/glapp.rb', line 22 def keyboard(key, modifiers) @engine.keyboard_down(key, modifiers) end |
#keyboard_up(key, modifiers) ⇒ Object
26 27 28 |
# File 'lib/glapp.rb', line 26 def keyboard_up(key, modifiers) @engine.keyboard_up(key, modifiers) end |
#mouse_active_motion(x, y) ⇒ Object
42 43 44 45 |
# File 'lib/glapp.rb', line 42 def mouse_active_motion(x, y) @engine.mouse_dragging_motion(x, y) @engine.mouse_motion(x, y) end |
#mouse_click(button, state, x, y) ⇒ Object
38 39 40 |
# File 'lib/glapp.rb', line 38 def mouse_click(, state, x, y) @engine.mouse_click(, state, x, y) end |
#mouse_passive_motion(x, y) ⇒ Object
47 48 49 50 |
# File 'lib/glapp.rb', line 47 def mouse_passive_motion(x, y) @engine.mouse_passive_motion(x, y) @engine.mouse_motion(x, y) end |
#resize(width, height) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/glapp.rb', line 52 def resize(width, height) # avoid divide-by-zero height = 1.0 if height <= 0 # Reset the coordinate system glMatrixMode(GL_PROJECTION) glLoadIdentity # Set the viewport to be the entire window glViewport(0, 0, width, height) # Set the correct perspective gluPerspective(45, width.to_f / height.to_f, 1, 1000) glMatrixMode(GL_MODELVIEW) glLoadIdentity gluLookAt(0, 0, 5, 0, 0, -1, 0, 1, 0) @width, @height = width, height end |
#show ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/glapp.rb', line 74 def show if glutGameModeGet(GLUT_GAME_MODE_ACTIVE) != 0 glutLeaveGameMode end unless @window glutInitWindowSize(@width, @height) @window = glutCreateWindow(@title) end self.setup_context self.go unless running? end |
#special_keyboard(key, modifiers) ⇒ Object
30 31 32 |
# File 'lib/glapp.rb', line 30 def special_keyboard(key, modifiers) @engine.special_keyboard_down(key, modifiers) end |
#special_keyboard_up(key, modifiers) ⇒ Object
34 35 36 |
# File 'lib/glapp.rb', line 34 def special_keyboard_up(key, modifiers) @engine.special_keyboard_up(key, modifiers) end |
#update(seconds) ⇒ Object
14 15 16 |
# File 'lib/glapp.rb', line 14 def update(seconds) @engine.update(seconds) end |