Module: GLApp
- Defined in:
- lib/glapp.rb
Defined Under Namespace
Modules: Helpers
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
74 75 |
# File 'lib/glapp.rb', line 74 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
84 85 |
# File 'lib/glapp.rb', line 84 def keyboard_down(key, modifiers) end |
#keyboard_up(key, modifiers) ⇒ Object
87 88 |
# File 'lib/glapp.rb', line 87 def keyboard_up(key, modifiers) end |
#mouse_click(button, state, x, y) ⇒ Object
96 97 |
# File 'lib/glapp.rb', line 96 def mouse_click(, state, x, y) end |
#mouse_dragging_motion(x, y) ⇒ Object
99 100 |
# File 'lib/glapp.rb', line 99 def mouse_dragging_motion(x, y) end |
#mouse_motion(x, y) ⇒ Object
105 106 |
# File 'lib/glapp.rb', line 105 def mouse_motion(x, y) end |
#mouse_passive_motion(x, y) ⇒ Object
102 103 |
# File 'lib/glapp.rb', line 102 def mouse_passive_motion(x, y) end |
#post_draw ⇒ Object
77 78 79 |
# File 'lib/glapp.rb', line 77 def post_draw glutSwapBuffers end |
#pre_draw ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/glapp.rb', line 65 def pre_draw glMatrixMode(GL_PROJECTION) glLoadIdentity gluPerspective(30.0, width / height, 0.1, 1000.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity end |
#resize ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/glapp.rb', line 108 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
62 63 |
# File 'lib/glapp.rb', line 62 def setup end |
#setup_context ⇒ Object
begin hooks
55 56 57 58 59 60 |
# File 'lib/glapp.rb', line 55 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
90 91 |
# File 'lib/glapp.rb', line 90 def special_keyboard_down(key, modifiers) end |
#special_keyboard_up(key, modifiers) ⇒ Object
93 94 |
# File 'lib/glapp.rb', line 93 def special_keyboard_up(key, modifiers) end |
#update(seconds) ⇒ Object
81 82 |
# File 'lib/glapp.rb', line 81 def update(seconds) end |
#wire ⇒ Object
end hooks
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 174 175 176 177 178 |
# File 'lib/glapp.rb', line 127 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 |