mittsu 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build-workflow.yml +5 -44
  3. data/Gemfile +0 -4
  4. data/README.md +16 -130
  5. data/bin/console +0 -4
  6. data/lib/mittsu/cameras/cube_camera.rb +1 -1
  7. data/lib/mittsu/core/geometry.rb +3 -3
  8. data/lib/mittsu/core/object_3d.rb +29 -47
  9. data/lib/mittsu/core/uniform.rb +23 -0
  10. data/lib/mittsu/core.rb +1 -0
  11. data/lib/mittsu/loaders/obj_loader.rb +11 -5
  12. data/lib/mittsu/loaders/stl_loader.rb +186 -0
  13. data/lib/mittsu/loaders.rb +1 -0
  14. data/lib/mittsu/math/box3.rb +4 -4
  15. data/lib/mittsu/objects/line.rb +1 -3
  16. data/lib/mittsu/objects/mesh.rb +9 -12
  17. data/lib/mittsu/objects/point_cloud.rb +3 -3
  18. data/lib/mittsu/textures/render_target.rb +93 -0
  19. data/lib/mittsu/textures/render_target_cube.rb +8 -0
  20. data/lib/mittsu/textures/texture.rb +1 -1
  21. data/lib/mittsu/textures.rb +2 -0
  22. data/lib/mittsu/version.rb +1 -1
  23. data/lib/mittsu.rb +0 -1
  24. data/mittsu.gemspec +8 -12
  25. metadata +33 -204
  26. data/install-glfw.ps1 +0 -13
  27. data/lib/mittsu/renderers/generic_lib.rb +0 -122
  28. data/lib/mittsu/renderers/glfw_lib.rb +0 -62
  29. data/lib/mittsu/renderers/glfw_window.rb +0 -233
  30. data/lib/mittsu/renderers/opengl/core/buffer_geometry.rb +0 -11
  31. data/lib/mittsu/renderers/opengl/core/geometry.rb +0 -346
  32. data/lib/mittsu/renderers/opengl/core/object_3d.rb +0 -134
  33. data/lib/mittsu/renderers/opengl/lights/ambient_light.rb +0 -26
  34. data/lib/mittsu/renderers/opengl/lights/directional_light.rb +0 -35
  35. data/lib/mittsu/renderers/opengl/lights/hemisphere_light.rb +0 -39
  36. data/lib/mittsu/renderers/opengl/lights/light.rb +0 -55
  37. data/lib/mittsu/renderers/opengl/lights/point_light.rb +0 -36
  38. data/lib/mittsu/renderers/opengl/lights/spot_light.rb +0 -47
  39. data/lib/mittsu/renderers/opengl/materials/line_basic_material.rb +0 -16
  40. data/lib/mittsu/renderers/opengl/materials/material.rb +0 -274
  41. data/lib/mittsu/renderers/opengl/materials/mesh_basic_material.rb +0 -21
  42. data/lib/mittsu/renderers/opengl/materials/mesh_lambert_material.rb +0 -33
  43. data/lib/mittsu/renderers/opengl/materials/mesh_phong_material.rb +0 -44
  44. data/lib/mittsu/renderers/opengl/materials/opengl_material_basics.rb +0 -57
  45. data/lib/mittsu/renderers/opengl/materials/point_cloud_material.rb +0 -27
  46. data/lib/mittsu/renderers/opengl/materials/shader_material.rb +0 -11
  47. data/lib/mittsu/renderers/opengl/objects/group.rb +0 -9
  48. data/lib/mittsu/renderers/opengl/objects/line.rb +0 -45
  49. data/lib/mittsu/renderers/opengl/objects/mesh.rb +0 -70
  50. data/lib/mittsu/renderers/opengl/objects/point_cloud.rb +0 -39
  51. data/lib/mittsu/renderers/opengl/objects/sprite.rb +0 -12
  52. data/lib/mittsu/renderers/opengl/opengl_buffer.rb +0 -13
  53. data/lib/mittsu/renderers/opengl/opengl_debug.rb +0 -81
  54. data/lib/mittsu/renderers/opengl/opengl_default_target.rb +0 -50
  55. data/lib/mittsu/renderers/opengl/opengl_geometry_group.rb +0 -758
  56. data/lib/mittsu/renderers/opengl/opengl_geometry_like.rb +0 -132
  57. data/lib/mittsu/renderers/opengl/opengl_helper.rb +0 -161
  58. data/lib/mittsu/renderers/opengl/opengl_implementations.rb +0 -37
  59. data/lib/mittsu/renderers/opengl/opengl_lib.rb +0 -19
  60. data/lib/mittsu/renderers/opengl/opengl_light_renderer.rb +0 -43
  61. data/lib/mittsu/renderers/opengl/opengl_mittsu_params.rb +0 -53
  62. data/lib/mittsu/renderers/opengl/opengl_program.rb +0 -250
  63. data/lib/mittsu/renderers/opengl/opengl_shader.rb +0 -58
  64. data/lib/mittsu/renderers/opengl/opengl_state.rb +0 -205
  65. data/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +0 -417
  66. data/lib/mittsu/renderers/opengl/plugins/sprite_fragment.glsl +0 -38
  67. data/lib/mittsu/renderers/opengl/plugins/sprite_plugin.rb +0 -250
  68. data/lib/mittsu/renderers/opengl/plugins/sprite_vertex.glsl +0 -31
  69. data/lib/mittsu/renderers/opengl/scenes/scene.rb +0 -9
  70. data/lib/mittsu/renderers/opengl/textures/compressed_texture.rb +0 -20
  71. data/lib/mittsu/renderers/opengl/textures/cube_texture.rb +0 -77
  72. data/lib/mittsu/renderers/opengl/textures/data_texture.rb +0 -21
  73. data/lib/mittsu/renderers/opengl/textures/texture.rb +0 -107
  74. data/lib/mittsu/renderers/opengl_render_target.rb +0 -201
  75. data/lib/mittsu/renderers/opengl_renderer.rb +0 -1028
  76. data/lib/mittsu/renderers/shaders/rbsl_loader.rb +0 -166
  77. data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_fragment.glsl +0 -5
  78. data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_pars_fragment.glsl +0 -5
  79. data/lib/mittsu/renderers/shaders/shader_chunk/alphatest_fragment.glsl +0 -5
  80. data/lib/mittsu/renderers/shaders/shader_chunk/bumpmap_pars_fragment.glsl +0 -40
  81. data/lib/mittsu/renderers/shaders/shader_chunk/color_fragment.glsl +0 -5
  82. data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_fragment.glsl +0 -5
  83. data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_vertex.glsl +0 -5
  84. data/lib/mittsu/renderers/shaders/shader_chunk/color_vertex.glsl +0 -5
  85. data/lib/mittsu/renderers/shaders/shader_chunk/common.glsl +0 -60
  86. data/lib/mittsu/renderers/shaders/shader_chunk/default_vertex.glsl +0 -15
  87. data/lib/mittsu/renderers/shaders/shader_chunk/defaultnormal_vertex.glsl +0 -21
  88. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_fragment.glsl +0 -62
  89. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_fragment.glsl +0 -21
  90. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_vertex.glsl +0 -7
  91. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_vertex.glsl +0 -17
  92. data/lib/mittsu/renderers/shaders/shader_chunk/fog_fragment.glsl +0 -26
  93. data/lib/mittsu/renderers/shaders/shader_chunk/fog_pars_fragment.glsl +0 -15
  94. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_fragment.glsl +0 -5
  95. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_fragment.glsl +0 -6
  96. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_vertex.glsl +0 -5
  97. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_vertex.glsl +0 -5
  98. data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_pars_vertex.glsl +0 -43
  99. data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_vertex.glsl +0 -196
  100. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_fragment.glsl +0 -243
  101. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_fragment.glsl +0 -58
  102. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_vertex.glsl +0 -5
  103. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_vertex.glsl +0 -5
  104. data/lib/mittsu/renderers/shaders/shader_chunk/linear_to_gamma_fragment.glsl +0 -2
  105. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_fragment.glsl +0 -5
  106. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_fragment.glsl +0 -12
  107. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_vertex.glsl +0 -11
  108. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_vertex.glsl +0 -15
  109. data/lib/mittsu/renderers/shaders/shader_chunk/map_fragment.glsl +0 -9
  110. data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_fragment.glsl +0 -11
  111. data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_vertex.glsl +0 -6
  112. data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_fragment.glsl +0 -5
  113. data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_pars_fragment.glsl +0 -6
  114. data/lib/mittsu/renderers/shaders/shader_chunk/map_vertex.glsl +0 -5
  115. data/lib/mittsu/renderers/shaders/shader_chunk/morphnormal_vertex.glsl +0 -12
  116. data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_pars_vertex.glsl +0 -13
  117. data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_vertex.glsl +0 -20
  118. data/lib/mittsu/renderers/shaders/shader_chunk/normalmap_pars_fragment.glsl +0 -27
  119. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_fragment.glsl +0 -216
  120. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_fragment.glsl +0 -19
  121. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_vertex.glsl +0 -6
  122. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_vertex.glsl +0 -9
  123. data/lib/mittsu/renderers/shaders/shader_chunk/skinbase_vertex.glsl +0 -8
  124. data/lib/mittsu/renderers/shaders/shader_chunk/skinning_pars_vertex.glsl +0 -47
  125. data/lib/mittsu/renderers/shaders/shader_chunk/skinning_vertex.glsl +0 -20
  126. data/lib/mittsu/renderers/shaders/shader_chunk/skinnormal_vertex.glsl +0 -20
  127. data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_fragment.glsl +0 -12
  128. data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_pars_fragment.glsl +0 -5
  129. data/lib/mittsu/renderers/shaders/shader_chunk/worldpos_vertex.glsl +0 -17
  130. data/lib/mittsu/renderers/shaders/shader_chunk.rb +0 -9
  131. data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_fragment.rbsl +0 -37
  132. data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_uniforms.rbslu +0 -3
  133. data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_vertex.rbsl +0 -33
  134. data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_fragment.rbsl +0 -12
  135. data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_uniforms.rbslu +0 -2
  136. data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_vertex.rbsl +0 -12
  137. data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_fragment.rbsl +0 -26
  138. data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_uniforms.rbslu +0 -0
  139. data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_vertex.rbsl +0 -12
  140. data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_fragment.rbsl +0 -56
  141. data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_uniforms.rbslu +0 -7
  142. data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_vertex.rbsl +0 -37
  143. data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_fragment.rbsl +0 -27
  144. data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_uniforms.rbslu +0 -2
  145. data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_vertex.rbsl +0 -25
  146. data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_fragment.rbsl +0 -45
  147. data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_uniforms.rbslu +0 -11
  148. data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_vertex.rbsl +0 -43
  149. data/lib/mittsu/renderers/shaders/shader_lib.rb +0 -43
  150. data/lib/mittsu/renderers/shaders/shader_templates/fragment.glsl.erb +0 -105
  151. data/lib/mittsu/renderers/shaders/shader_templates/vertex.glsl.erb +0 -143
  152. data/lib/mittsu/renderers/shaders/uniforms_lib.rb +0 -106
  153. data/lib/mittsu/renderers/shaders/uniforms_utils.rb +0 -31
  154. data/lib/mittsu/renderers.rb +0 -1
@@ -1,122 +0,0 @@
1
- module Mittsu
2
- module GenericLib
3
- def discover
4
- case OpenGL.get_platform
5
- when :OPENGL_PLATFORM_WINDOWS
6
- self::Windows.new
7
- when :OPENGL_PLATFORM_MACOSX
8
- self::MacOS.new
9
- when :OPENGL_PLATFORM_LINUX
10
- self::Linux.new
11
- else
12
- warn "WARNING: Unsupported platform: #{OpenGL.get_platform}"
13
- Base.new
14
- end
15
- end
16
-
17
- class Base
18
- def path; nil; end
19
- def file; nil; end
20
- end
21
-
22
- class Linux < Base
23
- def path
24
- return nil if file_path.nil?
25
- File.dirname file_path
26
- end
27
-
28
- def file
29
- return nil if file_path.nil?
30
- File.basename file_path
31
- end
32
-
33
- class << self
34
- def kernel_module_in_use
35
- lspci_line = `lspci -nnk | grep -i vga -A3 | grep 'in use'`
36
- /in use:\s*(\S+)/ =~ lspci_line && $1
37
- rescue
38
- ''
39
- end
40
-
41
- def libgl_paths
42
- Dir.glob('/usr/lib*/**/libGL.so*')
43
- rescue
44
- []
45
- end
46
-
47
- def sixtyfour_bits?
48
- 1.size == 8
49
- end
50
-
51
- def ldconfig
52
- `ldconfig -p | grep 'libGL\\.so'`.lines
53
- rescue
54
- []
55
- end
56
- end
57
-
58
- private
59
- def file_path
60
- @_file_path ||= begin
61
- ldconfig_lib || driver_specific_lib || sixtyfour_bit_lib || fallback_lib || give_up
62
- end.tap do |result|
63
- print_debug_info(result) if DEBUG
64
- end
65
- end
66
-
67
- def ldconfig_lib
68
- return nil if ldconfig.empty?
69
- @_debug = { source: 'ldconfig', info: ldconfig.inspect } if DEBUG
70
- ldconfig_for_arch = ldconfig.reject { |lib| @loader.sixtyfour_bits? ^ ldconfig_64?(lib) }
71
- ldconfig_for_arch.first.match(/=> (\/.*)$/)[1]
72
- end
73
-
74
- def ldconfig_64?(lib)
75
- lib =~ /\([^\)]*64[^\)]*\) =>/
76
- end
77
-
78
- def driver_specific_lib
79
- return nil if libs.empty?
80
- @_debug = { source: 'driver', info: kernel_module } if DEBUG
81
- libs.select { |lib| lib =~ /nvidia/ }.first if kernel_module =~ /nvidia/
82
- end
83
-
84
- def sixtyfour_bit_lib
85
- return nil if libs.empty?
86
- sixtyfour_bit_libs = libs.select { |lib| lib =~ /64/ }
87
- @_debug = { source: '64', info: sixtyfour_bit_libs.inspect } if DEBUG
88
- sixtyfour_bit_libs.first if @loader.sixtyfour_bits?
89
- end
90
-
91
- def fallback_lib
92
- return nil if libs.empty?
93
- @_debug = { source: 'fallback', info: libs.inspect } if DEBUG
94
- libs.first
95
- end
96
-
97
- def give_up
98
- @_debug = { source: 'none', info: nil } if DEBUG
99
- nil
100
- end
101
-
102
- def kernel_module
103
- @_kernel_module ||= @loader.kernel_module_in_use
104
- end
105
-
106
- def libs
107
- @_libs ||= @loader.libgl_paths.sort_by(&:length)
108
- end
109
-
110
- def ldconfig
111
- @_ldconfig ||= @loader.ldconfig
112
- end
113
-
114
- def print_debug_info(result)
115
- puts "Loading lib path: #{result.inspect}"
116
- puts "Source: #{@_debug[:source]}"
117
- puts "Info: #{@_debug[:info]}"
118
- puts "64-bit? #{@loader.sixtyfour_bits?}"
119
- end
120
- end
121
- end
122
- end
@@ -1,62 +0,0 @@
1
- require 'mittsu/renderers/generic_lib'
2
-
3
- module Mittsu
4
- module GLFWLib
5
- extend GenericLib
6
-
7
- class Linux < GenericLib::Linux
8
- def initialize(loader = Linux)
9
- @loader = loader
10
- end
11
-
12
- class << self
13
- def libgl_paths
14
- Dir.glob('/usr/lib*/**/libglfw*.so*')
15
- rescue
16
- []
17
- end
18
-
19
- def ldconfig
20
- `ldconfig -p | grep 'libglfw3\\?\\.so'`.lines
21
- rescue
22
- []
23
- end
24
- end
25
- end
26
-
27
- class Windows < GenericLib::Base
28
- def file
29
- 'glfw3.dll'
30
- end
31
- end
32
-
33
- class MacOS < GenericLib::Base
34
- SEARCH_GLOBS = ['/usr/local/lib/**',
35
- '/usr/lib/**',
36
- '/opt/homebrew/**']
37
-
38
- def path
39
- File.dirname(match)
40
- end
41
-
42
- def file
43
- File.basename(match)
44
- end
45
-
46
- private
47
-
48
- def match
49
- @match ||= find_match
50
- end
51
-
52
- def find_match
53
- SEARCH_GLOBS.each do |glob|
54
- matches = Dir.glob("#{glob}/libglfw*.dylib")
55
- next if matches.empty?
56
-
57
- return matches.find { |m| m.end_with?('libglfw3.dylib') || m.end_with?('libglfw.3.dylib') } || matches.first
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,233 +0,0 @@
1
- require 'opengl'
2
- require 'glfw'
3
-
4
- require 'mittsu/utils'
5
- require 'mittsu/renderers/glfw_lib'
6
- glfw_lib = Mittsu::GLFWLib.discover
7
- GLFW.load_lib(ENV["MITTSU_LIBGLFW_FILE"] || glfw_lib.file, ENV["MITTSU_LIBGLFW_PATH"] || glfw_lib.path) unless Mittsu.test?
8
-
9
- include GLFW
10
-
11
- module Mittsu
12
- module GLFW
13
- class Window
14
- attr_accessor :key_press_handler, :key_release_handler, :key_repeat_handler, :char_input_handler, :cursor_pos_handler, :mouse_button_press_handler, :mouse_button_release_handler, :scroll_handler, :framebuffer_size_handler
15
-
16
- def initialize(width, height, title, antialias: 0)
17
- glfwInit
18
-
19
- glfwWindowHint GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE
20
- glfwWindowHint GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE
21
- glfwWindowHint GLFW_CONTEXT_VERSION_MAJOR, 3
22
- glfwWindowHint GLFW_CONTEXT_VERSION_MINOR, 3
23
- glfwWindowHint GLFW_CONTEXT_REVISION, 0
24
-
25
- if antialias > 0
26
- glfwWindowHint GLFW_SAMPLES, antialias
27
- end
28
-
29
- @width, @height, @title = width, height, title
30
- @handle = glfwCreateWindow(@width, @height, @title, nil, nil)
31
- if @handle.null?
32
- raise "Unable to create window."
33
- end
34
- glfwMakeContextCurrent @handle
35
- glfwSwapInterval 1
36
-
37
- this = self
38
- @key_callback = ::GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods|
39
- if action == GLFW_PRESS
40
- this.key_press_handler.call(key) unless this.key_press_handler.nil?
41
- this.key_repeat_handler.call(key) unless this.key_repeat_handler.nil?
42
- elsif action == GLFW_RELEASE
43
- this.key_release_handler.call(key) unless this.key_release_handler.nil?
44
- elsif action == GLFW_REPEAT
45
- this.key_repeat_handler.call(key) unless this.key_repeat_handler.nil?
46
- end
47
- end
48
- glfwSetKeyCallback(@handle, @key_callback)
49
-
50
- @char_callback = ::GLFW::create_callback(:GLFWcharfun) do |window_handle, codepoint|
51
- char = [codepoint].pack('U')
52
- this.char_input_handler.call(char) unless this.char_input_handler.nil?
53
- end
54
- glfwSetCharCallback(@handle, @char_callback)
55
-
56
- @cursor_pos_callback = ::GLFW::create_callback(:GLFWcursorposfun) do |window_handle, xpos, ypos|
57
- this.cursor_pos_handler.call(Vector2.new(xpos, ypos)) unless this.cursor_pos_handler.nil?
58
- end
59
- glfwSetCursorPosCallback(@handle, @cursor_pos_callback)
60
-
61
- @mouse_button_callback = ::GLFW::create_callback(:GLFWmousebuttonfun) do |window_handle, button, action, mods|
62
- mpos = this.mouse_position
63
- if action == GLFW_PRESS
64
- this.mouse_button_press_handler.call(button, mpos) unless this.mouse_button_press_handler.nil?
65
- elsif action == GLFW_RELEASE
66
- this.mouse_button_release_handler.call(button, mpos) unless this.mouse_button_release_handler.nil?
67
- end
68
- end
69
- glfwSetMouseButtonCallback(@handle, @mouse_button_callback)
70
-
71
- @scroll_callback = ::GLFW::create_callback(:GLFWscrollfun) do |window_handle, xoffset, yoffset|
72
- this.scroll_handler.call(Vector2.new(xoffset, yoffset)) unless this.scroll_handler.nil?
73
- end
74
- glfwSetScrollCallback(@handle, @scroll_callback)
75
-
76
- @frabuffer_size_callback = ::GLFW::create_callback(:GLFWframebuffersizefun) do |window_handle, new_width, new_height|
77
- this.framebuffer_size_handler.call(new_width, new_height) unless this.framebuffer_size_handler.nil?
78
- end
79
- glfwSetFramebufferSizeCallback(@handle, @frabuffer_size_callback)
80
-
81
- @joystick_buttons = poll_all_joysticks_buttons
82
- end
83
-
84
- def run
85
- while glfwWindowShouldClose(@handle) == 0
86
- yield
87
-
88
- glfwSwapBuffers @handle
89
- glfwPollEvents
90
- poll_joystick_events
91
- end
92
- glfwDestroyWindow @handle
93
- glfwTerminate
94
- end
95
-
96
- def framebuffer_size
97
- width, height = ' '*8, ' '*8
98
- glfwGetFramebufferSize(@handle, width, height)
99
- [width.unpack('L')[0], height.unpack('L')[0]]
100
- end
101
-
102
- def on_key_pressed &block
103
- @key_press_handler = block
104
- end
105
-
106
- def on_key_released &block
107
- @key_release_handler = block
108
- end
109
-
110
- def on_key_typed &block
111
- @key_repeat_handler = block
112
- end
113
-
114
- def key_down?(key)
115
- glfwGetKey(@handle, key) == GLFW_PRESS
116
- end
117
-
118
- def on_character_input &block
119
- @char_input_handler = block
120
- end
121
-
122
- def on_mouse_move &block
123
- @cursor_pos_handler = block
124
- end
125
-
126
- def on_mouse_button_pressed &block
127
- @mouse_button_press_handler = block
128
- end
129
-
130
- def on_mouse_button_released &block
131
- @mouse_button_release_handler = block
132
- end
133
-
134
- def mouse_position
135
- xpos, ypos = ' '*8, ' '*8
136
- glfwGetCursorPos(@handle, xpos, ypos);
137
- Vector2.new(xpos.unpack('D')[0], ypos.unpack('D')[0])
138
- end
139
-
140
- def mouse_button_down?(button)
141
- glfwGetMouseButton(@handle, button) == GLFW_PRESS
142
- end
143
-
144
- def on_scroll &block
145
- @scroll_handler = block
146
- end
147
-
148
- def on_resize &block
149
- @framebuffer_size_handler = block
150
- end
151
-
152
- def joystick_buttons(joystick = GLFW_JOYSTICK_1)
153
- @joystick_buttons = poll_all_joysticks_buttons
154
- @joystick_buttons[joystick]
155
- end
156
-
157
- def joystick_axes(joystick = GLFW_JOYSTICK_1)
158
- return [] unless joystick_present?(joystick)
159
- count = ' ' * 4
160
- array = glfwGetJoystickAxes(joystick, count)
161
- count = count.unpack('l')[0]
162
- array[0, count * 4].unpack('f' * count)
163
- end
164
-
165
- def on_joystick_button_pressed &block
166
- @joystick_button_press_handler = block
167
- end
168
-
169
- def on_joystick_button_released &block
170
- @joystick_button_release_handler = block
171
- end
172
-
173
- def joystick_present?(joystick = GLFW_JOYSTICK_1)
174
- glfwJoystickPresent(joystick).nonzero?
175
- end
176
-
177
- def joystick_button_down?(button, joystick = GLFW_JOYSTICK_1)
178
- @joystick_buttons[joystick][button]
179
- end
180
-
181
- def joystick_name(joystick = GLFW_JOYSTICK_1)
182
- glfwGetJoystickName(joystick)
183
- end
184
-
185
- def set_mouselock(value)
186
- if value
187
- glfwSetInputMode(@handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED)
188
- else
189
- glfwSetInputMode(@handle, GLFW_CURSOR, GLFW_CURSOR_NORMAL)
190
- end
191
- end
192
-
193
- private
194
-
195
- def poll_all_joysticks_buttons
196
- (GLFW_JOYSTICK_1..GLFW_JOYSTICK_LAST).map do |joystick|
197
- poll_joystick_buttons(joystick)
198
- end
199
- end
200
-
201
- def poll_joystick_buttons(joystick)
202
- return nil unless joystick_present?(joystick)
203
- count = ' ' * 4
204
- array = glfwGetJoystickButtons(joystick, count)
205
- count = count.unpack('l')[0]
206
- array[0, count].unpack('c' * count).map(&:nonzero?)
207
- end
208
-
209
- def poll_joystick_events
210
- new_joystick_buttons = poll_all_joysticks_buttons
211
- new_joystick_buttons.each_with_index do |buttons, joystick|
212
- poll_single_joystick_events(joystick, buttons)
213
- end
214
- @joystick_buttons = new_joystick_buttons
215
- end
216
-
217
- def poll_single_joystick_events(joystick, buttons)
218
- return if buttons.nil?
219
- buttons.each_with_index do |pressed, button|
220
- fire_joystick_button_event(joystick, button, pressed)
221
- end
222
- end
223
-
224
- def fire_joystick_button_event(joystick, button, pressed)
225
- if !@joystick_buttons[joystick][button] && pressed
226
- @joystick_button_press_handler.call(joystick, button) unless @joystick_button_press_handler.nil?
227
- elsif @joystick_buttons[joystick][button] && !pressed
228
- @joystick_button_release_handler.call(joystick, button) unless @joystick_button_release_handler.nil?
229
- end
230
- end
231
- end
232
- end
233
- end
@@ -1,11 +0,0 @@
1
- module Mittsu
2
- class BufferGeometry
3
- include OpenGLGeometryLike
4
-
5
- attr_accessor :initted
6
-
7
- def init
8
- @initted = true
9
- end
10
- end
11
- end