Module: GLApp
- Defined in:
- lib/glapp.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #draw ⇒ Object
- #go_fullscreen ⇒ Object
- #go_windowed ⇒ Object
- #keyboard_down(key, modifiers) ⇒ Object
- #keyboard_up(key, modifiers) ⇒ Object
- #mouse_click(button, state, x, y) ⇒ Object
- #mouse_dragging_motion(x, y) ⇒ Object
- #mouse_motion(x, y) ⇒ Object
- #mouse_passive_motion(x, y) ⇒ Object
- #post_draw ⇒ Object
- #pre_draw ⇒ Object
- #resize ⇒ Object
- #setup ⇒ Object
-
#setup_context ⇒ Object
begin hooks.
- #show(width, height, title = "glapp", fullscreen = false) ⇒ Object
- #special_keyboard_down(key, modifiers) ⇒ Object
- #special_keyboard_up(key, modifiers) ⇒ Object
- #update(seconds) ⇒ Object
-
#wire ⇒ Object
end hooks.
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
5 6 7 |
# File 'lib/glapp.rb', line 5 def height @height end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/glapp.rb', line 5 def title @title end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
5 6 7 |
# File 'lib/glapp.rb', line 5 def width @width end |
Instance Method Details
#draw ⇒ Object
69 70 |
# File 'lib/glapp.rb', line 69 def draw end |
#go_fullscreen ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/glapp.rb', line 34 def go_fullscreen glutGameModeString([width, height].join("x")) if glutGameModeGet(GLUT_GAME_MODE_POSSIBLE) glutEnterGameMode if glutGameModeGet(GLUT_GAME_MODE_ACTIVE) == 0 go_windowed end else go_windowed end end |
#go_windowed ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/glapp.rb', line 23 def go_windowed if glutGameModeGet(GLUT_GAME_MODE_ACTIVE) != 0 glutLeaveGameMode end unless @window glutInitWindowSize(width, height) @window = glutCreateWindow(title) end end |
#keyboard_down(key, modifiers) ⇒ Object
79 80 |
# File 'lib/glapp.rb', line 79 def keyboard_down(key, modifiers) end |
#keyboard_up(key, modifiers) ⇒ Object
82 83 |
# File 'lib/glapp.rb', line 82 def keyboard_up(key, modifiers) end |
#mouse_click(button, state, x, y) ⇒ Object
91 92 |
# File 'lib/glapp.rb', line 91 def mouse_click(, state, x, y) end |
#mouse_dragging_motion(x, y) ⇒ Object
94 95 |
# File 'lib/glapp.rb', line 94 def mouse_dragging_motion(x, y) end |
#mouse_motion(x, y) ⇒ Object
100 101 |
# File 'lib/glapp.rb', line 100 def mouse_motion(x, y) end |
#mouse_passive_motion(x, y) ⇒ Object
97 98 |
# File 'lib/glapp.rb', line 97 def mouse_passive_motion(x, y) end |
#post_draw ⇒ Object
72 73 74 |
# File 'lib/glapp.rb', line 72 def post_draw glutSwapBuffers end |
#pre_draw ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/glapp.rb', line 59 def pre_draw glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_PROJECTION) glLoadIdentity gluPerspective(30.0, width / height, 0.1, 1000.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity end |
#resize ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/glapp.rb', line 103 def resize # 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) end |
#setup ⇒ Object
56 57 |
# File 'lib/glapp.rb', line 56 def setup end |
#setup_context ⇒ Object
begin hooks
49 50 51 52 53 54 |
# File 'lib/glapp.rb', line 49 def setup_context glEnable(GL_DEPTH_TEST) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glutIgnoreKeyRepeat(1) end |
#show(width, height, title = "glapp", fullscreen = false) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/glapp.rb', line 7 def show(width, height, title = "glapp", fullscreen = false) glutInit glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) @width = width @height = height @title = title fullscreen ? go_fullscreen : go_windowed setup setup_context wire glutMainLoop end |
#special_keyboard_down(key, modifiers) ⇒ Object
85 86 |
# File 'lib/glapp.rb', line 85 def special_keyboard_down(key, modifiers) end |
#special_keyboard_up(key, modifiers) ⇒ Object
88 89 |
# File 'lib/glapp.rb', line 88 def special_keyboard_up(key, modifiers) end |
#update(seconds) ⇒ Object
76 77 |
# File 'lib/glapp.rb', line 76 def update(seconds) end |
#wire ⇒ Object
end hooks
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/glapp.rb', line 122 def wire glutDisplayFunc(lambda do pre_draw draw post_draw end) glutIdleFunc(lambda do time = Time.now @last_time ||= time delta = time - @last_time update(delta) @last_time = time glutPostRedisplay end) glutKeyboardFunc(lambda do |key, x, y| keyboard_down(key, glutGetModifiers) end) glutKeyboardUpFunc(lambda do |key, x, y| keyboard_up(key, glutGetModifiers) end) glutSpecialFunc(lambda do |key, x, y| special_keyboard_down(key, glutGetModifiers) end) glutSpecialUpFunc(lambda do |key, x, y| special_keyboard_up(key, glutGetModifiers) end) glutMouseFunc(lambda do |, state, x, y| mouse_click(, state, x, y) end) glutMotionFunc(lambda do |x, y| mouse_dragging_motion(x, y) mouse_motion(x, y) end) glutPassiveMotionFunc(lambda do |x, y| mouse_passive_motion(x, y) mouse_motion(x, y) end) glutReshapeFunc(lambda do |width, height| @width = width @height = height resize end) end |