sgl 0.4.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +254 -234
- data/History.txt +6 -0
- data/Manifest.txt +10 -0
- data/Rakefile +27 -7
- data/examples/cocoa1-basic.rb +14 -14
- data/examples/cocoa10-transparent.rb +26 -26
- data/examples/cocoa11-application.rb +13 -13
- data/examples/cocoa2-draw.rb +23 -23
- data/examples/cocoa3-affine.rb +29 -29
- data/examples/cocoa4-font.rb +24 -24
- data/examples/cocoa5-image.rb +22 -22
- data/examples/cocoa6-sound.rb +24 -24
- data/examples/cocoa7-movie.rb +40 -40
- data/examples/cocoa8-movieoverlay.rb +42 -42
- data/examples/cocoa9-streaming.rb +40 -40
- data/examples/opengl1-basic.rb +14 -14
- data/examples/opengl11-application.rb +13 -13
- data/examples/opengl2-draw.rb +23 -23
- data/examples/opengl3-affine.rb +29 -29
- data/examples/sample1.rb +11 -11
- data/examples/sample10.rb +16 -16
- data/examples/sample11.rb +22 -22
- data/examples/sample11a.rb +33 -33
- data/examples/sample12.rb +30 -30
- data/examples/sample12a.rb +35 -35
- data/examples/sample13.rb +116 -116
- data/examples/sample15.rb +24 -24
- data/examples/sample16.rb +31 -31
- data/examples/sample16a.rb +35 -35
- data/examples/sample6.rb +18 -18
- data/examples/sample7.rb +16 -16
- data/examples/sample9.rb +20 -20
- data/examples/testgl.rb +169 -169
- data/lib/sgl/bass.rb +46 -46
- data/lib/sgl/cocoa-app.rb +43 -43
- data/lib/sgl/cocoa-color.rb +65 -65
- data/lib/sgl/cocoa-draw.rb +72 -72
- data/lib/sgl/cocoa-event.rb +229 -229
- data/lib/sgl/cocoa-media.rb +144 -144
- data/lib/sgl/cocoa-notuse.rb +493 -493
- data/lib/sgl/cocoa-window.rb +203 -203
- data/lib/sgl/cocoa.rb +8 -8
- data/lib/sgl/opengl-app.rb +38 -38
- data/lib/sgl/opengl-color.rb +44 -44
- data/lib/sgl/opengl-draw.rb +260 -260
- data/lib/sgl/opengl-event.rb +325 -325
- data/lib/sgl/opengl-modules.rb +22 -22
- data/lib/sgl/opengl-window.rb +224 -224
- data/lib/sgl/opengl.rb +7 -7
- data/lib/sgl/sgl-button.rb +135 -135
- data/lib/sgl/sgl-client.rb +21 -21
- data/lib/sgl/sgl-color.rb +68 -82
- data/lib/sgl/sgl-connect.rb +9 -9
- data/lib/sgl/sgl-server.rb +58 -58
- data/lib/sgl/sgl-spring.rb +216 -216
- data/lib/sgl/version.rb +2 -2
- data/scripts/lib-txt2html.rb +130 -0
- data/scripts/txt2html +2 -63
- data/spec/sgl_spec.rb +13 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +1 -0
- data/test/test_cocoa_app.rb +291 -291
- data/test/test_module_ruby16.rb +30 -30
- data/test/test_opengl_app.rb +147 -147
- data/test/test_opengl_basic.rb +22 -22
- data/test/test_opengl_fullscreen.rb +23 -23
- data/test/test_opengl_novice.rb +35 -35
- data/website/challenge1.html +91 -91
- data/website/challenge1.txt +3 -3
- data/website/challenge2.html +143 -144
- data/website/challenge2.txt +13 -14
- data/website/challenge3.html +66 -63
- data/website/challenge3.txt +7 -7
- data/website/cocoa.html +85 -88
- data/website/cocoa.txt +2 -4
- data/website/description.html +138 -138
- data/website/description.txt +1 -1
- data/website/exercise1.html +262 -264
- data/website/exercise1.txt +58 -53
- data/website/exercise2.html +241 -683
- data/website/exercise2.txt +11 -427
- data/website/exercise3.html +206 -0
- data/website/exercise3.txt +155 -0
- data/website/exercise4.html +198 -0
- data/website/exercise4.txt +151 -0
- data/website/exercise5.html +162 -0
- data/website/exercise5.txt +113 -0
- data/website/exhibition.html +84 -84
- data/website/howto.html +146 -134
- data/website/howto.txt +9 -0
- data/website/index.html +178 -178
- data/website/index.txt +20 -19
- data/website/sound.html +141 -141
- metadata +16 -3
data/lib/sgl/opengl-modules.rb
CHANGED
@@ -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
|
data/lib/sgl/opengl-window.rb
CHANGED
@@ -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
|