sgl 0.4.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. data/ChangeLog +254 -234
  2. data/History.txt +6 -0
  3. data/Manifest.txt +10 -0
  4. data/Rakefile +27 -7
  5. data/examples/cocoa1-basic.rb +14 -14
  6. data/examples/cocoa10-transparent.rb +26 -26
  7. data/examples/cocoa11-application.rb +13 -13
  8. data/examples/cocoa2-draw.rb +23 -23
  9. data/examples/cocoa3-affine.rb +29 -29
  10. data/examples/cocoa4-font.rb +24 -24
  11. data/examples/cocoa5-image.rb +22 -22
  12. data/examples/cocoa6-sound.rb +24 -24
  13. data/examples/cocoa7-movie.rb +40 -40
  14. data/examples/cocoa8-movieoverlay.rb +42 -42
  15. data/examples/cocoa9-streaming.rb +40 -40
  16. data/examples/opengl1-basic.rb +14 -14
  17. data/examples/opengl11-application.rb +13 -13
  18. data/examples/opengl2-draw.rb +23 -23
  19. data/examples/opengl3-affine.rb +29 -29
  20. data/examples/sample1.rb +11 -11
  21. data/examples/sample10.rb +16 -16
  22. data/examples/sample11.rb +22 -22
  23. data/examples/sample11a.rb +33 -33
  24. data/examples/sample12.rb +30 -30
  25. data/examples/sample12a.rb +35 -35
  26. data/examples/sample13.rb +116 -116
  27. data/examples/sample15.rb +24 -24
  28. data/examples/sample16.rb +31 -31
  29. data/examples/sample16a.rb +35 -35
  30. data/examples/sample6.rb +18 -18
  31. data/examples/sample7.rb +16 -16
  32. data/examples/sample9.rb +20 -20
  33. data/examples/testgl.rb +169 -169
  34. data/lib/sgl/bass.rb +46 -46
  35. data/lib/sgl/cocoa-app.rb +43 -43
  36. data/lib/sgl/cocoa-color.rb +65 -65
  37. data/lib/sgl/cocoa-draw.rb +72 -72
  38. data/lib/sgl/cocoa-event.rb +229 -229
  39. data/lib/sgl/cocoa-media.rb +144 -144
  40. data/lib/sgl/cocoa-notuse.rb +493 -493
  41. data/lib/sgl/cocoa-window.rb +203 -203
  42. data/lib/sgl/cocoa.rb +8 -8
  43. data/lib/sgl/opengl-app.rb +38 -38
  44. data/lib/sgl/opengl-color.rb +44 -44
  45. data/lib/sgl/opengl-draw.rb +260 -260
  46. data/lib/sgl/opengl-event.rb +325 -325
  47. data/lib/sgl/opengl-modules.rb +22 -22
  48. data/lib/sgl/opengl-window.rb +224 -224
  49. data/lib/sgl/opengl.rb +7 -7
  50. data/lib/sgl/sgl-button.rb +135 -135
  51. data/lib/sgl/sgl-client.rb +21 -21
  52. data/lib/sgl/sgl-color.rb +68 -82
  53. data/lib/sgl/sgl-connect.rb +9 -9
  54. data/lib/sgl/sgl-server.rb +58 -58
  55. data/lib/sgl/sgl-spring.rb +216 -216
  56. data/lib/sgl/version.rb +2 -2
  57. data/scripts/lib-txt2html.rb +130 -0
  58. data/scripts/txt2html +2 -63
  59. data/spec/sgl_spec.rb +13 -0
  60. data/spec/spec.opts +1 -0
  61. data/spec/spec_helper.rb +1 -0
  62. data/test/test_cocoa_app.rb +291 -291
  63. data/test/test_module_ruby16.rb +30 -30
  64. data/test/test_opengl_app.rb +147 -147
  65. data/test/test_opengl_basic.rb +22 -22
  66. data/test/test_opengl_fullscreen.rb +23 -23
  67. data/test/test_opengl_novice.rb +35 -35
  68. data/website/challenge1.html +91 -91
  69. data/website/challenge1.txt +3 -3
  70. data/website/challenge2.html +143 -144
  71. data/website/challenge2.txt +13 -14
  72. data/website/challenge3.html +66 -63
  73. data/website/challenge3.txt +7 -7
  74. data/website/cocoa.html +85 -88
  75. data/website/cocoa.txt +2 -4
  76. data/website/description.html +138 -138
  77. data/website/description.txt +1 -1
  78. data/website/exercise1.html +262 -264
  79. data/website/exercise1.txt +58 -53
  80. data/website/exercise2.html +241 -683
  81. data/website/exercise2.txt +11 -427
  82. data/website/exercise3.html +206 -0
  83. data/website/exercise3.txt +155 -0
  84. data/website/exercise4.html +198 -0
  85. data/website/exercise4.txt +151 -0
  86. data/website/exercise5.html +162 -0
  87. data/website/exercise5.txt +113 -0
  88. data/website/exhibition.html +84 -84
  89. data/website/howto.html +146 -134
  90. data/website/howto.txt +9 -0
  91. data/website/index.html +178 -178
  92. data/website/index.txt +20 -19
  93. data/website/sound.html +141 -141
  94. metadata +16 -3
@@ -1,22 +1,22 @@
1
- # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
- # License: Ruby License
3
-
4
- module SGL
5
- # module control
6
- def useMidi() $__a__.useMidi; end
7
- def useMidiIn(*a) $__a__.useMidiIn(*a) end
8
-
9
- class Application
10
- def useMidi
11
- require "sgl/sgl-midi"
12
- $__midi__ = SGLMidi.new
13
- end
14
-
15
- def useMidiIn(num = -1)
16
- require "sgl/sgl-midiin"
17
- printMidiDeviceNames
18
- openMidiIn(num)
19
- startMidiInThread
20
- end
21
- end
22
- end
1
+ # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
+ # License: Ruby License
3
+
4
+ module SGL
5
+ # module control
6
+ def useMidi() $__a__.useMidi; end
7
+ def useMidiIn(*a) $__a__.useMidiIn(*a) end
8
+
9
+ class Application
10
+ def useMidi
11
+ require "sgl/sgl-midi"
12
+ $__midi__ = SGLMidi.new
13
+ end
14
+
15
+ def useMidiIn(num = -1)
16
+ require "sgl/sgl-midiin"
17
+ printMidiDeviceNames
18
+ openMidiIn(num)
19
+ startMidiInThread
20
+ end
21
+ end
22
+ end
@@ -1,224 +1,224 @@
1
- # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
- # License: Ruby License
3
-
4
- module SGL
5
- # window functions
6
- def window(*a) $__a__.window(*a) end
7
- def close_window() $__a__.close_window; end
8
- def width() $__a__.width; end
9
- def height() $__a__.height; end
10
-
11
- # opengl special functions
12
- def useFov(*a) $__a__.useFov(*a); end
13
- def useDepth(*a) $__a__.useDepth(*a) end
14
- def useSmooth(*a) $__a__.useSmooth(*a) end
15
- def useCulling(*a) $__a__.useCulling(*a) end
16
- def useFullscreen(*a) $__a__.useFullscreen(*a) end
17
- alias useFullScreen useFullscreen
18
- def useCursor(*a) $__a__.useCursor(*a) end
19
-
20
- class Application
21
- DEFAULT_WINDOW_WIDTH = 100
22
- DEFAULT_WINDOW_HEIGHT = 100
23
- DEFAULT_FULLSCREEN_WIDTH = 1024
24
- DEFAULT_FULLSCREEN_HEIGHT = 768
25
-
26
- def initialize_window
27
- @width, @height = DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT
28
- @left, @bottom, @right, @top = 0, 0, @width, @height
29
- @cameraX, @cameraY, @cameraZ = 0, 0, 5
30
- initialize_sdl
31
- end
32
-
33
- def initialize_sdl
34
- SDL.init(SDL::INIT_VIDEO)
35
- # Setting color size is important for Mac OS X.
36
- SDL.setGLAttr(SDL::GL_RED_SIZE, 5)
37
- SDL.setGLAttr(SDL::GL_GREEN_SIZE, 5)
38
- SDL.setGLAttr(SDL::GL_BLUE_SIZE, 5)
39
- SDL.setGLAttr(SDL::GL_DEPTH_SIZE, 16)
40
- SDL.setGLAttr(SDL::GL_DOUBLEBUFFER, 1)
41
- if !windows?
42
- SDL.setVideoMode(640, 400, 16, SDL::OPENGL)
43
- end
44
- @sdl_event = SDL::Event.new
45
- end
46
- private :initialize_window, :initialize_sdl
47
-
48
- def windows?
49
- r = RUBY_PLATFORM
50
- (r.index("cygwin") || r.index("mswin32") || r.index("mingw32")) != nil
51
- end
52
- private :windows?
53
-
54
- # create window
55
- def window(*a)
56
- @options.update(a.pop) if a.last.is_a? Hash
57
-
58
- if a.length == 4
59
- @left, @bottom, @right, @top = a
60
- elsif a.length == 2
61
- @right, @top = a
62
- @left = @bottom = 0
63
- else
64
- raise "error"
65
- end
66
-
67
- @width, @height = (@right - @left), (@top - @bottom)
68
-
69
- # Do not initialize twice.
70
- if ! defined?($__sgl_sdl_window_initialized__)
71
- # sdl_window_init
72
- mode = SDL::OPENGL
73
- if @options[:fullscreen]
74
- mode |= SDL::FULLSCREEN
75
- w, h = @options[:fullscreen]
76
- SDL.setVideoMode(w, h, 0, mode)
77
- else
78
- SDL.setVideoMode(@width, @height + 1, 0, mode) # why +1?
79
- end
80
- GC.start
81
- SDL::WM.setCaption("sgl", "sgl")
82
- $__sgl_sdl_window_initialized__ = true
83
- end
84
-
85
- # setCurosr
86
- if @options[:cursor]
87
- # You can use only black and white for cursor image.
88
- file = @options[:cursor]
89
- bmp = SDL::Surface.loadBMP(file) # Create surface from bitmap.
90
- SDL::Mouse.setCursor(bmp, # bitmap
91
- [255, 255, 255], # white
92
- [ 0, 0, 0], # black
93
- [128, 128, 128], # transparent
94
- [100, 100, 100], # inverted
95
- 8, 8) # hot_x, hot_y
96
- end
97
-
98
- # gl_init
99
- if @options[:fullscreen]
100
- set_fullscreen_position
101
- else
102
- set_window_position
103
- end
104
- set_camera_position
105
- GL.Enable(GL::BLEND)
106
- GL.BlendFunc(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA)
107
- GL.ShadeModel(GL::SMOOTH)
108
- useDepth(@options[:depth])
109
- useCulling(@options[:culling])
110
- useSmooth(@options[:smooth])
111
-
112
- background(0)
113
- color(100)
114
-
115
- check_event
116
- end
117
-
118
- def close_window
119
- # do nothing for now
120
- end
121
-
122
- # get window size
123
- attr_reader :width, :height
124
-
125
- # world control methods
126
- def useFov(f = 45)
127
- @options[:fov] = f
128
- end
129
-
130
- def useDepth(a = true)
131
- @options[:depth] = a
132
- @options[:depth] ? GL.Enable(GL::DEPTH_TEST) : GL.Disable(GL::DEPTH_TEST)
133
- end
134
-
135
- def useSmooth(a = true)
136
- @options[:smooth] = a
137
- @options[:smooth] ?
138
- GL.Enable(GL::LINE_SMOOTH) : GL.Disable(GL::LINE_SMOOTH)
139
- end
140
-
141
- def useCulling(a = true)
142
- @options[:culling] = a
143
- @options[:culling] ? GL.Enable(GL::CULL_FACE) : GL.Disable(GL::CULL_FACE)
144
- end
145
-
146
- def useFullscreen(w=DEFAULT_FULLSCREEN_WIDTH, h=DEFAULT_FULLSCREEN_HEIGHT)
147
- if @options[:fullscreen].nil?
148
- @options[:fullscreen] = (w.nil? || h.nil?) ? nil : [w, h]
149
- end
150
- end
151
-
152
- def useCursor(bmpfile)
153
- @options[:cursor] = bmpfile
154
- end
155
-
156
- def useDelay(sec)
157
- @options[:delaytime] = sec
158
- end
159
-
160
- def useFramerate(f)
161
- @options[:framerate] = f
162
- end
163
-
164
- def useRuntime(r)
165
- @options[:runtime] = r
166
- end
167
-
168
- def runtime=(r)
169
- useRuntime(r)
170
- end
171
-
172
- def set_window_position
173
- @cameraX, @cameraY = ((@left + @right)/2), ((@bottom + @top)/2)
174
- fov = @options[:fov]
175
- @cameraZ = 1.0 +
176
- @height / (2.0 * Math.tan(Math::PI * (fov/2.0) / 180.0))
177
- GL.Viewport(0, 0, @width, @height)
178
- GL.MatrixMode(GL::PROJECTION)
179
- loadIdentity
180
- GLU.Perspective(fov, @width/@height.to_f, @cameraZ * 0.1, @cameraZ * 10.0)
181
- end
182
-
183
- def set_fullscreen_position
184
- cx, cy = ((@left + @right)/2), ((@bottom + @top)/2)
185
- @cameraX, @cameraY = cx, cy
186
- w, h = @options[:fullscreen]
187
- fhw = w / 2 #fullscreen half width
188
- fhh = h / 2 #fullscreen half height
189
- left = cx - fhw
190
- bottom = cy - fhh
191
- right = cx + fhw
192
- top = cy + fhh
193
- GL.Viewport(0, 0, w, h)
194
- GL.MatrixMode(GL::PROJECTION)
195
- loadIdentity
196
- fov = @options[:fov]
197
- @cameraZ = 1.0 + h / (2.0 * Math.tan(Math::PI * (fov/2.0) / 180.0));
198
- GLU.Perspective(fov, w/h.to_f, @cameraZ * 0.1, @cameraZ * 10.0)
199
- end
200
- private :set_window_position, :set_fullscreen_position
201
-
202
- def set_camera_position
203
- GL.MatrixMode(GL::MODELVIEW)
204
- loadIdentity
205
- GLU.LookAt(@cameraX, @cameraY, @cameraZ,
206
- @cameraX, @cameraY, 0,
207
- 0, 1, 0)
208
- end
209
-
210
- def set_fullscreen_camera_position
211
- GL.MatrixMode(GL::MODELVIEW)
212
- loadIdentity
213
- GLU.LookAt(0, 0, @cameraZ,
214
- 0, 0, 0,
215
- 0, 1, 0)
216
- end
217
- private :set_camera_position, :set_fullscreen_camera_position
218
-
219
- def loadIdentity
220
- GL.LoadIdentity
221
- end
222
- private :loadIdentity
223
- end
224
- end
1
+ # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
+ # License: Ruby License
3
+
4
+ module SGL
5
+ # window functions
6
+ def window(*a) $__a__.window(*a) end
7
+ def close_window() $__a__.close_window; end
8
+ def width() $__a__.width; end
9
+ def height() $__a__.height; end
10
+
11
+ # opengl special functions
12
+ def useFov(*a) $__a__.useFov(*a); end
13
+ def useDepth(*a) $__a__.useDepth(*a) end
14
+ def useSmooth(*a) $__a__.useSmooth(*a) end
15
+ def useCulling(*a) $__a__.useCulling(*a) end
16
+ def useFullscreen(*a) $__a__.useFullscreen(*a) end
17
+ alias useFullScreen useFullscreen
18
+ def useCursor(*a) $__a__.useCursor(*a) end
19
+
20
+ class Application
21
+ DEFAULT_WINDOW_WIDTH = 100
22
+ DEFAULT_WINDOW_HEIGHT = 100
23
+ DEFAULT_FULLSCREEN_WIDTH = 1024
24
+ DEFAULT_FULLSCREEN_HEIGHT = 768
25
+
26
+ def initialize_window
27
+ @width, @height = DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT
28
+ @left, @bottom, @right, @top = 0, 0, @width, @height
29
+ @cameraX, @cameraY, @cameraZ = 0, 0, 5
30
+ initialize_sdl
31
+ end
32
+
33
+ def initialize_sdl
34
+ SDL.init(SDL::INIT_VIDEO)
35
+ # Setting color size is important for Mac OS X.
36
+ SDL.setGLAttr(SDL::GL_RED_SIZE, 5)
37
+ SDL.setGLAttr(SDL::GL_GREEN_SIZE, 5)
38
+ SDL.setGLAttr(SDL::GL_BLUE_SIZE, 5)
39
+ SDL.setGLAttr(SDL::GL_DEPTH_SIZE, 16)
40
+ SDL.setGLAttr(SDL::GL_DOUBLEBUFFER, 1)
41
+ if !windows?
42
+ SDL.setVideoMode(640, 400, 16, SDL::OPENGL)
43
+ end
44
+ @sdl_event = SDL::Event.new
45
+ end
46
+ private :initialize_window, :initialize_sdl
47
+
48
+ def windows?
49
+ r = RUBY_PLATFORM
50
+ (r.index("cygwin") || r.index("mswin32") || r.index("mingw32")) != nil
51
+ end
52
+ private :windows?
53
+
54
+ # create window
55
+ def window(*a)
56
+ @options.update(a.pop) if a.last.is_a? Hash
57
+
58
+ if a.length == 4
59
+ @left, @bottom, @right, @top = a
60
+ elsif a.length == 2
61
+ @right, @top = a
62
+ @left = @bottom = 0
63
+ else
64
+ raise "error"
65
+ end
66
+
67
+ @width, @height = (@right - @left), (@top - @bottom)
68
+
69
+ # Do not initialize twice.
70
+ if ! defined?($__sgl_sdl_window_initialized__)
71
+ # sdl_window_init
72
+ mode = SDL::OPENGL
73
+ if @options[:fullscreen]
74
+ mode |= SDL::FULLSCREEN
75
+ w, h = @options[:fullscreen]
76
+ SDL.setVideoMode(w, h, 0, mode)
77
+ else
78
+ SDL.setVideoMode(@width, @height + 1, 0, mode) # why +1?
79
+ end
80
+ GC.start
81
+ SDL::WM.setCaption("sgl", "sgl")
82
+ $__sgl_sdl_window_initialized__ = true
83
+ end
84
+
85
+ # setCurosr
86
+ if @options[:cursor]
87
+ # You can use only black and white for cursor image.
88
+ file = @options[:cursor]
89
+ bmp = SDL::Surface.loadBMP(file) # Create surface from bitmap.
90
+ SDL::Mouse.setCursor(bmp, # bitmap
91
+ [255, 255, 255], # white
92
+ [ 0, 0, 0], # black
93
+ [128, 128, 128], # transparent
94
+ [100, 100, 100], # inverted
95
+ 8, 8) # hot_x, hot_y
96
+ end
97
+
98
+ # gl_init
99
+ if @options[:fullscreen]
100
+ set_fullscreen_position
101
+ else
102
+ set_window_position
103
+ end
104
+ set_camera_position
105
+ GL.Enable(GL::BLEND)
106
+ GL.BlendFunc(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA)
107
+ GL.ShadeModel(GL::SMOOTH)
108
+ useDepth(@options[:depth])
109
+ useCulling(@options[:culling])
110
+ useSmooth(@options[:smooth])
111
+
112
+ background(0)
113
+ color(100)
114
+
115
+ check_event
116
+ end
117
+
118
+ def close_window
119
+ # do nothing for now
120
+ end
121
+
122
+ # get window size
123
+ attr_reader :width, :height
124
+
125
+ # world control methods
126
+ def useFov(f = 45)
127
+ @options[:fov] = f
128
+ end
129
+
130
+ def useDepth(a = true)
131
+ @options[:depth] = a
132
+ @options[:depth] ? GL.Enable(GL::DEPTH_TEST) : GL.Disable(GL::DEPTH_TEST)
133
+ end
134
+
135
+ def useSmooth(a = true)
136
+ @options[:smooth] = a
137
+ @options[:smooth] ?
138
+ GL.Enable(GL::LINE_SMOOTH) : GL.Disable(GL::LINE_SMOOTH)
139
+ end
140
+
141
+ def useCulling(a = true)
142
+ @options[:culling] = a
143
+ @options[:culling] ? GL.Enable(GL::CULL_FACE) : GL.Disable(GL::CULL_FACE)
144
+ end
145
+
146
+ def useFullscreen(w=DEFAULT_FULLSCREEN_WIDTH, h=DEFAULT_FULLSCREEN_HEIGHT)
147
+ if @options[:fullscreen].nil?
148
+ @options[:fullscreen] = (w.nil? || h.nil?) ? nil : [w, h]
149
+ end
150
+ end
151
+
152
+ def useCursor(bmpfile)
153
+ @options[:cursor] = bmpfile
154
+ end
155
+
156
+ def useDelay(sec)
157
+ @options[:delaytime] = sec
158
+ end
159
+
160
+ def useFramerate(f)
161
+ @options[:framerate] = f
162
+ end
163
+
164
+ def useRuntime(r)
165
+ @options[:runtime] = r
166
+ end
167
+
168
+ def runtime=(r)
169
+ useRuntime(r)
170
+ end
171
+
172
+ def set_window_position
173
+ @cameraX, @cameraY = ((@left + @right)/2), ((@bottom + @top)/2)
174
+ fov = @options[:fov]
175
+ @cameraZ = 1.0 +
176
+ @height / (2.0 * Math.tan(Math::PI * (fov/2.0) / 180.0))
177
+ GL.Viewport(0, 0, @width, @height)
178
+ GL.MatrixMode(GL::PROJECTION)
179
+ loadIdentity
180
+ GLU.Perspective(fov, @width/@height.to_f, @cameraZ * 0.1, @cameraZ * 10.0)
181
+ end
182
+
183
+ def set_fullscreen_position
184
+ cx, cy = ((@left + @right)/2), ((@bottom + @top)/2)
185
+ @cameraX, @cameraY = cx, cy
186
+ w, h = @options[:fullscreen]
187
+ fhw = w / 2 #fullscreen half width
188
+ fhh = h / 2 #fullscreen half height
189
+ left = cx - fhw
190
+ bottom = cy - fhh
191
+ right = cx + fhw
192
+ top = cy + fhh
193
+ GL.Viewport(0, 0, w, h)
194
+ GL.MatrixMode(GL::PROJECTION)
195
+ loadIdentity
196
+ fov = @options[:fov]
197
+ @cameraZ = 1.0 + h / (2.0 * Math.tan(Math::PI * (fov/2.0) / 180.0));
198
+ GLU.Perspective(fov, w/h.to_f, @cameraZ * 0.1, @cameraZ * 10.0)
199
+ end
200
+ private :set_window_position, :set_fullscreen_position
201
+
202
+ def set_camera_position
203
+ GL.MatrixMode(GL::MODELVIEW)
204
+ loadIdentity
205
+ GLU.LookAt(@cameraX, @cameraY, @cameraZ,
206
+ @cameraX, @cameraY, 0,
207
+ 0, 1, 0)
208
+ end
209
+
210
+ def set_fullscreen_camera_position
211
+ GL.MatrixMode(GL::MODELVIEW)
212
+ loadIdentity
213
+ GLU.LookAt(0, 0, @cameraZ,
214
+ 0, 0, 0,
215
+ 0, 1, 0)
216
+ end
217
+ private :set_camera_position, :set_fullscreen_camera_position
218
+
219
+ def loadIdentity
220
+ GL.LoadIdentity
221
+ end
222
+ private :loadIdentity
223
+ end
224
+ end