ray 0.1.1 → 0.2.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.
- data/README.md +9 -6
- data/Rakefile +1 -5
- data/ext/audio.c +25 -19
- data/ext/audio_source.c +67 -39
- data/ext/color.c +19 -19
- data/ext/drawable.c +190 -31
- data/ext/extconf.rb +16 -14
- data/ext/gl.c +310 -30
- data/ext/gl_buffer.c +223 -2
- data/ext/gl_index_buffer.c +11 -0
- data/ext/gl_int_array.c +24 -22
- data/ext/gl_vertex.c +84 -49
- data/ext/image.c +115 -51
- data/ext/image_target.c +58 -10
- data/ext/input.c +73 -6
- data/ext/mo.c +583 -0
- data/ext/mo.h +189 -0
- data/ext/music.c +9 -8
- data/ext/pixel_bus.c +349 -0
- data/ext/polygon.c +68 -45
- data/ext/ray.c +1 -0
- data/ext/ray.h +19 -1
- data/ext/rect.c +9 -47
- data/ext/say.h +1 -2
- data/ext/say_all.h +6 -0
- data/ext/say_audio.h +3 -0
- data/ext/say_audio_context.c +1 -4
- data/ext/say_basic_type.c +24 -0
- data/ext/say_basic_type.h +4 -0
- data/ext/say_buffer.c +217 -88
- data/ext/say_buffer.h +20 -5
- data/ext/say_buffer_renderer.c +10 -7
- data/ext/say_buffer_renderer.h +1 -1
- data/ext/say_buffer_slice.c +70 -76
- data/ext/say_context.c +109 -22
- data/ext/say_context.h +14 -0
- data/ext/say_drawable.c +113 -25
- data/ext/say_drawable.h +23 -2
- data/ext/say_error.c +7 -2
- data/ext/say_font.c +30 -27
- data/ext/say_font.h +3 -6
- data/ext/say_get_proc.c +35 -0
- data/ext/say_image.c +102 -27
- data/ext/say_image.h +11 -4
- data/ext/say_image_target.c +88 -34
- data/ext/say_image_target.h +3 -2
- data/ext/say_index_buffer.c +31 -19
- data/ext/say_index_buffer.h +4 -2
- data/ext/say_index_buffer_slice.c +78 -70
- data/ext/say_music.c +4 -2
- data/ext/say_osx.h +3 -2
- data/ext/say_osx_context.h +37 -4
- data/ext/say_osx_window.h +32 -37
- data/ext/say_pixel_bus.c +163 -0
- data/ext/say_pixel_bus.h +44 -0
- data/ext/say_polygon.c +2 -2
- data/ext/say_shader.c +66 -62
- data/ext/say_shader.h +2 -0
- data/ext/say_sprite.c +1 -2
- data/ext/say_target.c +14 -23
- data/ext/say_target.h +3 -1
- data/ext/say_text.c +45 -7
- data/ext/say_text.h +12 -3
- data/ext/say_thread.c +13 -6
- data/ext/say_thread.h +1 -1
- data/ext/say_thread_variable.c +5 -5
- data/ext/say_vertex_type.c +79 -41
- data/ext/say_vertex_type.h +6 -2
- data/ext/say_view.c +10 -31
- data/ext/say_view.h +1 -5
- data/ext/say_win.h +2 -2
- data/ext/say_win_context.h +49 -11
- data/ext/say_win_window.h +30 -27
- data/ext/say_window.c +3 -3
- data/ext/say_x11.h +3 -1
- data/ext/say_x11_context.h +64 -10
- data/ext/say_x11_window.h +22 -17
- data/ext/shader.c +9 -0
- data/ext/sprite.c +7 -1
- data/ext/target.c +80 -28
- data/ext/text.c +43 -1
- data/ext/view.c +53 -1
- data/ext/window.c +4 -0
- data/lib/ray/animation_list.rb +17 -2
- data/lib/ray/audio_source.rb +11 -0
- data/lib/ray/color.rb +14 -0
- data/lib/ray/drawable.rb +23 -0
- data/lib/ray/dsl/event.rb +1 -9
- data/lib/ray/dsl/event_runner.rb +3 -4
- data/lib/ray/dsl/matcher.rb +20 -1
- data/lib/ray/effect.rb +116 -0
- data/lib/ray/effect/black_and_white.rb +38 -0
- data/lib/ray/effect/color_inversion.rb +16 -0
- data/lib/ray/effect/generator.rb +145 -0
- data/lib/ray/effect/grayscale.rb +32 -0
- data/lib/ray/game.rb +25 -5
- data/lib/ray/gl/vertex.rb +105 -26
- data/lib/ray/helper.rb +5 -0
- data/lib/ray/image.rb +54 -13
- data/lib/ray/image_target.rb +7 -0
- data/lib/ray/matrix.rb +26 -0
- data/lib/ray/music.rb +4 -0
- data/lib/ray/pixel_bus.rb +22 -0
- data/lib/ray/polygon.rb +17 -0
- data/lib/ray/pp.rb +28 -0
- data/lib/ray/ray.rb +7 -1
- data/lib/ray/rect.rb +7 -13
- data/lib/ray/scene.rb +24 -5
- data/lib/ray/scene_list.rb +9 -0
- data/lib/ray/shader.rb +11 -2
- data/lib/ray/sound.rb +4 -0
- data/lib/ray/sprite.rb +23 -62
- data/lib/ray/target.rb +25 -0
- data/lib/ray/text.rb +10 -0
- data/lib/ray/turtle.rb +9 -3
- data/lib/ray/vector.rb +18 -0
- data/lib/ray/vertex.rb +6 -0
- data/lib/ray/view.rb +22 -0
- data/samples/animation/sprite_motion.rb +0 -60
- data/samples/audio/{spacial.rb → spatial.rb} +1 -1
- data/samples/buffer/buffer.rb +1 -0
- data/samples/buffer/index_buffer.rb +2 -0
- data/samples/cptn_ruby/cptn_ruby.rb +6 -7
- data/samples/effects/effect.rb +39 -0
- data/samples/effects/grayscale.rb +27 -0
- data/samples/opengl/image.rb +7 -5
- data/samples/opengl/instancing.rb +159 -0
- data/samples/opengl/instancing.rbc +3231 -0
- data/samples/opengl/obj_loader.rb +9 -8
- data/samples/opengl/shader.rb +1 -3
- data/samples/shaders/geometry.rb +108 -38
- data/samples/shaders/geometry.rbc +2074 -0
- data/samples/shaders/shape.rb +2 -2
- data/samples/starfighter/starfighter.rb +5 -5
- data/samples/window/get_pixel.rb +1 -1
- data/test/animation_list_test.rb +18 -4
- data/test/drawable_test.rb +70 -1
- data/test/effect_generator_test.rb +63 -0
- data/test/effect_test.rb +61 -0
- data/test/game_test.rb +18 -0
- data/test/gl_buffer_test.rb +43 -1
- data/test/gl_index_buffer_test.rb +5 -0
- data/test/gl_vertex_test.rb +28 -1
- data/test/image_test.rb +5 -5
- data/test/input_test.rb +49 -0
- data/test/pixel_bus_test.rb +28 -0
- data/test/rect_test.rb +4 -0
- data/{samples/_media → test/res}/Beep.wav +0 -0
- data/samples/_media/CptnRuby Gem.png b/data/test/res/CptnRuby → Gem.png +0 -0
- data/samples/_media/CptnRuby Map.txt b/data/test/res/CptnRuby → Map.txt +0 -0
- data/samples/_media/CptnRuby Tileset.png b/data/test/res/CptnRuby → Tileset.png +0 -0
- data/{samples/_media → test/res}/CptnRuby.png +0 -0
- data/{samples/_media → test/res}/Space.png +0 -0
- data/{samples/_media → test/res}/Star.png +0 -0
- data/{samples/_media → test/res}/Starfighter.png +0 -0
- data/test/res/cube.obj +28 -0
- data/test/res/light3d.c +2 -2
- data/test/res/stone.png +0 -0
- data/test/scene_test.rb +3 -0
- data/test/sprite_test.rb +10 -0
- data/test/text_test.rb +31 -2
- data/test/view_test.rb +13 -1
- metadata +38 -17
- data/ext/say_array.c +0 -124
- data/ext/say_array.h +0 -34
- data/ext/say_table.c +0 -86
- data/ext/say_table.h +0 -24
data/ext/image.c
CHANGED
@@ -21,19 +21,24 @@ VALUE ray_image_alloc(VALUE self) {
|
|
21
21
|
}
|
22
22
|
|
23
23
|
/*
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
24
|
+
* @overload initialize(io)
|
25
|
+
* Creates an image from an IO object
|
26
|
+
* @param [IO, #read] io An object containing the image.
|
27
|
+
* @example
|
28
|
+
* open("test.png") { |io| Ray::Image.new(io) }
|
29
|
+
*
|
30
|
+
* @overload initialize(filename)
|
31
|
+
* Loads an image from a file
|
32
|
+
* @param [String] filename Name of a file to load the image from.
|
33
|
+
* @example
|
34
|
+
* Ray::Image.new "test.png"
|
35
|
+
*
|
36
|
+
* @overload initialize(size)
|
37
|
+
* Creates an image from a size
|
38
|
+
* @param [Vector2, #to_vector2] size Size of the image to create
|
39
|
+
* @example
|
40
|
+
* Ray::Image.new [64, 128]
|
41
|
+
*/
|
37
42
|
static
|
38
43
|
VALUE ray_image_init(VALUE self, VALUE arg) {
|
39
44
|
say_image *img = ray_rb2image(self);
|
@@ -63,16 +68,20 @@ static
|
|
63
68
|
VALUE ray_image_init_copy(VALUE self, VALUE other) {
|
64
69
|
say_image *orig = ray_rb2image(other);
|
65
70
|
|
66
|
-
|
67
|
-
|
68
|
-
|
71
|
+
say_image_load_flipped_raw(ray_rb2image(self),
|
72
|
+
say_image_get_width(orig),
|
73
|
+
say_image_get_height(orig),
|
74
|
+
say_image_get_buffer(orig));
|
69
75
|
|
70
76
|
return self;
|
71
77
|
}
|
72
78
|
|
73
79
|
/*
|
74
80
|
* @overload write_bmp(filename)
|
75
|
-
* Saves the image as a BMP
|
81
|
+
* Saves the image as a BMP
|
82
|
+
*
|
83
|
+
* Notice BMP output ignores alpha channel. Use PNG or TGA output when
|
84
|
+
* possible.
|
76
85
|
*/
|
77
86
|
static
|
78
87
|
VALUE ray_image_write_bmp(VALUE self, VALUE filename) {
|
@@ -85,7 +94,8 @@ VALUE ray_image_write_bmp(VALUE self, VALUE filename) {
|
|
85
94
|
|
86
95
|
/*
|
87
96
|
* @overload write_png(filename)
|
88
|
-
* Saves the image as a PNG
|
97
|
+
* Saves the image as a PNG
|
98
|
+
* @raise [RuntimeError] This method will not work on Windows.
|
89
99
|
*/
|
90
100
|
static
|
91
101
|
VALUE ray_image_write_png(VALUE self, VALUE filename) {
|
@@ -98,7 +108,7 @@ VALUE ray_image_write_png(VALUE self, VALUE filename) {
|
|
98
108
|
|
99
109
|
/*
|
100
110
|
* @overload write_tga(filename)
|
101
|
-
* Saves the image as a TGA
|
111
|
+
* Saves the image as a TGA
|
102
112
|
*/
|
103
113
|
static
|
104
114
|
VALUE ray_image_write_tga(VALUE self, VALUE filename) {
|
@@ -111,8 +121,11 @@ VALUE ray_image_write_tga(VALUE self, VALUE filename) {
|
|
111
121
|
|
112
122
|
/*
|
113
123
|
* @overload write(filename)
|
114
|
-
* Saves the image
|
115
|
-
*
|
124
|
+
* Saves the image in any format supported by Ray
|
125
|
+
*
|
126
|
+
* This will try to guess the format based on the filename extension
|
127
|
+
* (regardless of the case). If Ray can't guess the filename, the image will
|
128
|
+
* be saved anyway using TGA.
|
116
129
|
*/
|
117
130
|
static
|
118
131
|
VALUE ray_image_write(VALUE self, VALUE filename) {
|
@@ -154,12 +167,14 @@ void ray_image_assert_pos(say_image *img, size_t x, size_t y) {
|
|
154
167
|
}
|
155
168
|
|
156
169
|
/*
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
170
|
+
* @overload [](x, y)
|
171
|
+
* Reads the color of a pixel
|
172
|
+
*
|
173
|
+
* @param [Integer] x X position of the pixel
|
174
|
+
* @param [Integer] y Y position of the pixel
|
175
|
+
*
|
176
|
+
* @return [Color] Color of the pixel
|
177
|
+
*/
|
163
178
|
static
|
164
179
|
VALUE ray_image_get(VALUE self, VALUE rb_x, VALUE rb_y) {
|
165
180
|
say_image *img = ray_rb2image(self);
|
@@ -173,12 +188,14 @@ VALUE ray_image_get(VALUE self, VALUE rb_x, VALUE rb_y) {
|
|
173
188
|
}
|
174
189
|
|
175
190
|
/*
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
191
|
+
* @overload []=(x, y, color)
|
192
|
+
* Changes the color of a pixel
|
193
|
+
*
|
194
|
+
* @param [Integer] x X position of the pixel
|
195
|
+
* @param [Integer] y Y position of the pixel
|
196
|
+
*
|
197
|
+
* @param [Color] color New color of the pixel
|
198
|
+
*/
|
182
199
|
static
|
183
200
|
VALUE ray_image_set(VALUE self, VALUE rb_x, VALUE rb_y, VALUE color) {
|
184
201
|
rb_check_frozen(self);
|
@@ -193,36 +210,59 @@ VALUE ray_image_set(VALUE self, VALUE rb_x, VALUE rb_y, VALUE color) {
|
|
193
210
|
}
|
194
211
|
|
195
212
|
/*
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
213
|
+
* @overload tex_rect(rect)
|
214
|
+
* Converts a rect of pixel coordinates to a rect of texture coordinates
|
215
|
+
*
|
216
|
+
* Texture coordinates can be useful when manually generating vertices that
|
217
|
+
* need to be textured.
|
218
|
+
*
|
219
|
+
* The returned rect is setup so that (x,y) is the top left corner of the
|
220
|
+
* image. The height of the rect may thus be negative.
|
221
|
+
*
|
222
|
+
* @param [Rect] rect Rect in pixel coordinates
|
223
|
+
* @return [Rect] Rect in texture coordinates
|
224
|
+
*/
|
203
225
|
VALUE ray_image_tex_rect(VALUE self, VALUE rect) {
|
204
226
|
return ray_rect2rb(say_image_get_tex_rect(ray_rb2image(self),
|
205
227
|
ray_convert_to_rect(rect)));
|
206
228
|
}
|
207
229
|
|
208
230
|
/*
|
209
|
-
|
210
|
-
|
211
|
-
*/
|
231
|
+
* Binds the texture, which will be used as GL_TEXTURE_2D when drawing with
|
232
|
+
* OpenGL
|
233
|
+
*/
|
212
234
|
VALUE ray_image_bind(VALUE self) {
|
213
235
|
say_image_bind(ray_rb2image(self));
|
214
236
|
return self;
|
215
237
|
}
|
216
238
|
|
217
239
|
/*
|
218
|
-
|
219
|
-
|
220
|
-
|
240
|
+
* @return [Integer] Identifer of the image's texture
|
241
|
+
*/
|
242
|
+
VALUE ray_image_texture(VALUE self) {
|
243
|
+
return ULONG2NUM(say_image_get_texture(ray_rb2image(self)));
|
244
|
+
}
|
245
|
+
|
246
|
+
/*
|
247
|
+
* @see smooth=
|
221
248
|
*/
|
222
249
|
VALUE ray_image_is_smooth(VALUE self) {
|
223
250
|
return say_image_is_smooth(ray_rb2image(self)) ? Qtrue : Qfalse;
|
224
251
|
}
|
225
252
|
|
253
|
+
/*
|
254
|
+
* @overload smooth=(val)
|
255
|
+
* Enables or disables smoothing
|
256
|
+
*
|
257
|
+
* When smoothing is enabled, the color of interpolated pixels is chosen by
|
258
|
+
* taking the average of the four colors that are the nearest to each of
|
259
|
+
* them (linear interpolation). When it is not enabled, the color of the
|
260
|
+
* nearest point is simply used.
|
261
|
+
*
|
262
|
+
* Smoothing is disabled by default.
|
263
|
+
*
|
264
|
+
* @param [Boolean] val True to enable smoothing
|
265
|
+
*/
|
226
266
|
VALUE ray_image_set_smooth(VALUE self, VALUE val) {
|
227
267
|
rb_check_frozen(self);
|
228
268
|
say_image_set_smooth(ray_rb2image(self), RTEST(val));
|
@@ -230,34 +270,58 @@ VALUE ray_image_set_smooth(VALUE self, VALUE val) {
|
|
230
270
|
}
|
231
271
|
|
232
272
|
/*
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
273
|
+
* Document-class: Ray::Image
|
274
|
+
*
|
275
|
+
* An image is a bidimensonial array of pixels used to texture rendering. It is
|
276
|
+
* not an object you can draw per se. See {Ray::Sprite} or more generically
|
277
|
+
* {Ray::Drawable} for this.
|
278
|
+
*
|
279
|
+
* You can directly access pixels of an image, but an image target
|
280
|
+
* ({Ray::ImageTarget}) must be used to be able to draw more complex objects
|
281
|
+
* on it.
|
282
|
+
*
|
283
|
+
* @see Ray::ImageTarget
|
284
|
+
* @see Ray::Sprite
|
285
|
+
* @see Ray::Drawable
|
286
|
+
*/
|
238
287
|
void Init_ray_image() {
|
239
288
|
ray_cImage = rb_define_class_under(ray_mRay, "Image", rb_cObject);
|
240
289
|
|
290
|
+
/* @group Creating an image */
|
241
291
|
rb_define_alloc_func(ray_cImage, ray_image_alloc);
|
242
292
|
rb_define_method(ray_cImage, "initialize", ray_image_init, 1);
|
243
293
|
rb_define_method(ray_cImage, "initialize_copy", ray_image_init_copy, 1);
|
294
|
+
/* @endgroup */
|
244
295
|
|
296
|
+
/* @group Saving an image */
|
245
297
|
rb_define_method(ray_cImage, "write_bmp", ray_image_write_bmp, 1);
|
246
298
|
rb_define_method(ray_cImage, "write_png", ray_image_write_png, 1);
|
247
299
|
rb_define_method(ray_cImage, "write_tga", ray_image_write_tga, 1);
|
248
300
|
rb_define_method(ray_cImage, "write", ray_image_write, 1);
|
301
|
+
/* @endgroup */
|
249
302
|
|
303
|
+
/* @group Getting image size */
|
250
304
|
rb_define_method(ray_cImage, "width", ray_image_width, 0);
|
251
305
|
rb_define_method(ray_cImage, "height", ray_image_height, 0);
|
252
306
|
rb_define_method(ray_cImage, "size", ray_image_size, 0);
|
307
|
+
/* @endgroup */
|
253
308
|
|
309
|
+
/* @group Pixel-level access */
|
254
310
|
rb_define_method(ray_cImage, "[]", ray_image_get, 2);
|
255
311
|
rb_define_method(ray_cImage, "[]=", ray_image_set, 3);
|
312
|
+
/* @endgroup */
|
256
313
|
|
314
|
+
/* @group Texture parameters */
|
257
315
|
rb_define_method(ray_cImage, "smooth?", ray_image_is_smooth, 0);
|
258
316
|
rb_define_method(ray_cImage, "smooth=", ray_image_set_smooth, 1);
|
317
|
+
/* @endgroup */
|
259
318
|
|
319
|
+
/* @group Coordinate conversions */
|
260
320
|
rb_define_method(ray_cImage, "tex_rect", ray_image_tex_rect, 1);
|
321
|
+
/* @endgroup */
|
261
322
|
|
323
|
+
/* @group OpenGL access */
|
262
324
|
rb_define_method(ray_cImage, "bind", ray_image_bind, 0);
|
325
|
+
rb_define_method(ray_cImage, "texture", ray_image_texture, 0);
|
326
|
+
/* @endgroup */
|
263
327
|
}
|
data/ext/image_target.c
CHANGED
@@ -17,13 +17,17 @@ say_image_target *ray_rb2image_target(VALUE obj) {
|
|
17
17
|
VALUE ray_image_target_alloc(VALUE self) {
|
18
18
|
if (!say_image_target_is_available())
|
19
19
|
rb_raise(rb_eRuntimeError, "Ray::RenderImage is not supported here");
|
20
|
-
|
20
|
+
|
21
21
|
say_image_target *target = say_image_target_create();
|
22
22
|
return Data_Wrap_Struct(ray_cImageTarget, NULL, say_image_target_free,
|
23
23
|
target);
|
24
24
|
}
|
25
25
|
|
26
|
-
/*
|
26
|
+
/*
|
27
|
+
* @overload image=(img)
|
28
|
+
* Sets the image this object will draw on
|
29
|
+
* @param [Ray::Image] img New image to draw on
|
30
|
+
*/
|
27
31
|
VALUE ray_image_target_set_image(VALUE self, VALUE img) {
|
28
32
|
rb_check_frozen(self);
|
29
33
|
say_image_target_set_image(ray_rb2image_target(self), ray_rb2image(img));
|
@@ -31,26 +35,50 @@ VALUE ray_image_target_set_image(VALUE self, VALUE img) {
|
|
31
35
|
return img;
|
32
36
|
}
|
33
37
|
|
34
|
-
/* @
|
38
|
+
/* @see image= */
|
35
39
|
VALUE ray_image_target_image(VALUE self) {
|
36
40
|
return rb_iv_get(self, "@image");
|
37
41
|
}
|
38
42
|
|
39
|
-
/*
|
43
|
+
/*
|
44
|
+
* Updates the content of the image target
|
45
|
+
*
|
46
|
+
* The pixels of the image will also be updated:
|
47
|
+
* Ray::ImageTarget.new image do |target|
|
48
|
+
* target.clear Ray::Color.red
|
49
|
+
* target.update
|
50
|
+
* end
|
51
|
+
*
|
52
|
+
* image[0, 0] # => RGBA(255, 0, 0, 255)
|
53
|
+
*/
|
40
54
|
VALUE ray_image_target_update(VALUE self) {
|
41
55
|
say_image_target_update(ray_rb2image_target(self));
|
42
56
|
return self;
|
43
57
|
}
|
44
58
|
|
45
|
-
/*
|
59
|
+
/*
|
60
|
+
* Binds an image target to draw directly on it
|
61
|
+
*
|
62
|
+
* This method is only useful when performing low-level OpenGL rendering. It
|
63
|
+
* is different from {#make_current} because it doesn't use the target's own
|
64
|
+
* OpenGL context. Instead, it will use the current context (ensuring there is
|
65
|
+
* one).
|
66
|
+
*
|
67
|
+
* Notice binding the image target (and, therefore, making it the current
|
68
|
+
* target) clears the depth buffer of the image, so that everything will be
|
69
|
+
* rendered over what was already on the image.
|
70
|
+
*/
|
46
71
|
VALUE ray_image_target_bind(VALUE self) {
|
47
72
|
say_image_target_bind(ray_rb2image_target(self));
|
48
73
|
return self;
|
49
74
|
}
|
50
75
|
|
51
76
|
/*
|
52
|
-
* Unbinds any image target
|
53
|
-
*
|
77
|
+
* Unbinds any image target
|
78
|
+
*
|
79
|
+
* This is rarely needed, as this method gets called automatically when a window
|
80
|
+
* is bound, and because windows and image targets do not share the same OpenGL
|
81
|
+
* context.
|
54
82
|
*/
|
55
83
|
VALUE ray_image_target_unbind(VALUE self) {
|
56
84
|
/*
|
@@ -63,18 +91,38 @@ VALUE ray_image_target_unbind(VALUE self) {
|
|
63
91
|
}
|
64
92
|
|
65
93
|
/*
|
94
|
+
* Checks availability of image targets
|
95
|
+
*
|
96
|
+
* Image targets are only part of OpenGL core since OpenGL 3 (although they may
|
97
|
+
* be supported as an extension in older versions).
|
98
|
+
*
|
66
99
|
* @return [true, false] True when ImageTargets are available
|
67
100
|
*/
|
68
101
|
VALUE ray_image_target_available(VALUE self) {
|
69
102
|
return say_image_target_is_available() ? Qtrue : Qfalse;
|
70
103
|
}
|
71
104
|
|
105
|
+
/*
|
106
|
+
* Document-class: Ray::ImageTarget
|
107
|
+
*
|
108
|
+
* Image targets are objects that allow to draw any drawable object on an image
|
109
|
+
* instead of doing on-screen rendering. Off-screen rendering can be useful to
|
110
|
+
* pre-render some objects.
|
111
|
+
*
|
112
|
+
* Notice image targets modify the image they are drawing on directly. You may
|
113
|
+
* therefore not want to draw on a cached image, but rather on a copy thereof.
|
114
|
+
*
|
115
|
+
* @see Ray::Image
|
116
|
+
*/
|
72
117
|
void Init_ray_image_target() {
|
73
|
-
ray_cImageTarget = rb_define_class_under(ray_mRay, "ImageTarget",
|
118
|
+
ray_cImageTarget = rb_define_class_under(ray_mRay, "ImageTarget",
|
119
|
+
ray_cTarget);
|
74
120
|
rb_define_alloc_func(ray_cImageTarget, ray_image_target_alloc);
|
75
121
|
|
76
|
-
rb_define_singleton_method(ray_cImageTarget, "unbind",
|
77
|
-
|
122
|
+
rb_define_singleton_method(ray_cImageTarget, "unbind",
|
123
|
+
ray_image_target_unbind, 0);
|
124
|
+
rb_define_singleton_method(ray_cImageTarget, "available?",
|
125
|
+
ray_image_target_available, 0);
|
78
126
|
|
79
127
|
rb_define_method(ray_cImageTarget, "image=", ray_image_target_set_image, 1);
|
80
128
|
rb_define_method(ray_cImageTarget, "image", ray_image_target_image, 0);
|
data/ext/input.c
CHANGED
@@ -17,21 +17,72 @@ say_input *ray_rb2input(VALUE obj) {
|
|
17
17
|
VALUE ray_input2rb(say_input *input, VALUE owner) {
|
18
18
|
VALUE obj = Data_Wrap_Struct(rb_path2class("Ray::Input"), NULL, NULL, input);
|
19
19
|
rb_iv_set(obj, "@owner", owner);
|
20
|
-
|
21
20
|
return obj;
|
22
21
|
}
|
23
22
|
|
24
23
|
static
|
25
24
|
VALUE ray_input_alloc(VALUE self) {
|
26
|
-
|
25
|
+
say_input *obj = malloc(sizeof(say_input));
|
26
|
+
say_input_reset(obj);
|
27
|
+
return Data_Wrap_Struct(self, NULL, free, obj);
|
28
|
+
}
|
29
|
+
|
30
|
+
/*
|
31
|
+
* Resets the input
|
32
|
+
*
|
33
|
+
* After a reset, all the keys are marked released and the mouse position is set
|
34
|
+
* to (0, 0).
|
35
|
+
*/
|
36
|
+
static
|
37
|
+
VALUE ray_input_reset(VALUE self) {
|
38
|
+
say_input_reset(ray_rb2input(self));
|
39
|
+
return self;
|
40
|
+
}
|
41
|
+
|
42
|
+
/*
|
43
|
+
* @overload press(key)
|
44
|
+
* Marks a key as pressed
|
45
|
+
* @param [Integer] key A key
|
46
|
+
*/
|
47
|
+
static
|
48
|
+
VALUE ray_input_press(VALUE self, VALUE key) {
|
49
|
+
say_input_press(ray_rb2input(self), NUM2INT(key));
|
50
|
+
return Qnil;
|
51
|
+
}
|
52
|
+
|
53
|
+
/*
|
54
|
+
* @overload release(key)
|
55
|
+
* Marks a key as released
|
56
|
+
* @param [Integer] key A key
|
57
|
+
*/
|
58
|
+
static
|
59
|
+
VALUE ray_input_release(VALUE self, VALUE key) {
|
60
|
+
say_input_release(ray_rb2input(self), NUM2INT(key));
|
27
61
|
return Qnil;
|
28
62
|
}
|
29
63
|
|
30
64
|
/*
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
65
|
+
* @overload mouse_pos=(pos)
|
66
|
+
* Changes the known position of the mouse
|
67
|
+
*
|
68
|
+
* Notice this only affects the input object's state, it won't actually move
|
69
|
+
* the mouse.
|
70
|
+
*
|
71
|
+
* @param [Ray::Vector2] pos New position
|
72
|
+
*/
|
73
|
+
static
|
74
|
+
VALUE ray_input_set_mouse_pos(VALUE self, VALUE pos) {
|
75
|
+
say_input_set_mouse_pos(ray_rb2input(self), ray_convert_to_vector2(pos));
|
76
|
+
return pos;
|
77
|
+
}
|
78
|
+
|
79
|
+
/*
|
80
|
+
* @overload holding?(key)
|
81
|
+
* Checks if a key is being held
|
82
|
+
*
|
83
|
+
* @param [Integer] key A key
|
84
|
+
* @return [true, false] True if the given key is being held
|
85
|
+
*/
|
35
86
|
static
|
36
87
|
VALUE ray_input_holding(VALUE self, VALUE key) {
|
37
88
|
return say_input_is_holding(ray_rb2input(self), NUM2INT(key)) ?
|
@@ -44,10 +95,26 @@ VALUE ray_input_mouse_pos(VALUE self) {
|
|
44
95
|
return ray_vector2_to_rb(say_input_get_mouse_pos(ray_rb2input(self)));
|
45
96
|
}
|
46
97
|
|
98
|
+
/*
|
99
|
+
* Document-class: Ray::Input
|
100
|
+
*
|
101
|
+
* An input object is used to keep track of pressed keys and the position of the
|
102
|
+
* mouse. Methods are also provided to affect the state of the input, possibly
|
103
|
+
* useful in tests.
|
104
|
+
*/
|
47
105
|
void Init_ray_input() {
|
48
106
|
ray_cInput = rb_define_class_under(ray_mRay, "Input", rb_cObject);
|
49
107
|
rb_define_alloc_func(ray_cInput, ray_input_alloc);
|
50
108
|
|
109
|
+
/* @group Change input */
|
110
|
+
rb_define_method(ray_cInput, "reset", ray_input_reset, 0);
|
111
|
+
rb_define_method(ray_cInput, "press", ray_input_press, 1);
|
112
|
+
rb_define_method(ray_cInput, "release", ray_input_release, 1);
|
113
|
+
rb_define_method(ray_cInput, "mouse_pos=", ray_input_set_mouse_pos, 1);
|
114
|
+
/* @engroup */
|
115
|
+
|
116
|
+
/* @group Read input */
|
51
117
|
rb_define_method(ray_cInput, "holding?", ray_input_holding, 1);
|
52
118
|
rb_define_method(ray_cInput, "mouse_pos", ray_input_mouse_pos, 0);
|
119
|
+
/* @endgroup */
|
53
120
|
}
|