glfw3 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 197903711fa3522d32955dca8172d60d7f3b5a54
4
- data.tar.gz: 6fa9a291165798a578aca51f943ccd467b3fb22b
3
+ metadata.gz: 8321b1d791bc79297ffc7ce8c4087290f2de35de
4
+ data.tar.gz: e70fed392fc347121443d92da642dde29714e521
5
5
  SHA512:
6
- metadata.gz: 0f8165aa744318363832f74fde53762086ab1ba65c470ede8bfed41cac5bc14ce8b4464f503aafe05978bff2c615ce15cda576eb2793cdd2661fcc7eda26d729
7
- data.tar.gz: 8e7134f82f4d78128b2b170e49daee6e2a323c7ae04677ae82eb1394a2382d2380f662ef38305a3c54bf620a629d46478566a6b55fcaa358ad766744a8344dbe
6
+ metadata.gz: a3af48ed74e81c3e577d2df3c719557b669825b8459c79acd36db0e8cd363ac3434693018f9d0db76cccff2cb2db92668d6dcc528e8a8a471b04b26380a23437
7
+ data.tar.gz: 70952724a68e2e1142d5fc89b41f8b54995365c5f5a0559a80027dfeee27158daa6db13c24829b2b5a7c2cdd7ac641b2568531282644867fe25d4342df8f6919
data/README.md CHANGED
@@ -9,11 +9,15 @@ find it. You may also want to grab some [OpenGL bindings] as well.
9
9
  [OpenGL bindings]: https://github.com/nilium/ruby-opengl
10
10
  [GLFW 3]: https://github.com/glfw/glfw
11
11
 
12
- Once that's taken care of, you can install it simply by building and installing
13
- the gem, like so:
12
+ Once that's taken care of, you can install it simply by installing the gem via RubyGems.org using
13
+
14
+ $ gem install glfw3
15
+
16
+ Or by building and installing the gem, making note of the version so you know
17
+ the gem package to install, like so:
14
18
 
15
19
  $ gem build glfw3.gemspec
16
- $ gem install glfw3-0.0.1.gemspec
20
+ $ gem install glfw3-VERSION-HERE.gemspec
17
21
 
18
22
  After that, write a quick script to toy with it. For example:
19
23
 
data/ext/glfw3/glfw3.c CHANGED
@@ -134,11 +134,15 @@ VALUE rb_glfw_get_monitors(VALUE self)
134
134
  long monitor_index = 0;
135
135
  int num_monitors = 0;
136
136
  GLFWmonitor **monitors = glfwGetMonitors(&num_monitors);
137
- VALUE monitors_out = rb_ary_new();
138
- for (; num_monitors; --num_monitors, ++monitor_index) {
139
- VALUE monitor = Data_Wrap_Struct(s_glfw_monitor_klass, 0, 0, monitors[monitor_index]);
140
- rb_obj_call_init(monitor, 0, 0);
141
- rb_ary_push(monitors_out, monitor);
137
+ VALUE monitors_out = Qnil;
138
+
139
+ if (monitors) {
140
+ monitors_out = rb_ary_new();
141
+ for (; num_monitors; --num_monitors, ++monitor_index) {
142
+ VALUE monitor = Data_Wrap_Struct(s_glfw_monitor_klass, 0, 0, monitors[monitor_index]);
143
+ rb_obj_call_init(monitor, 0, 0);
144
+ rb_ary_push(monitors_out, monitor);
145
+ }
142
146
  }
143
147
  return monitors_out;
144
148
  }
@@ -155,9 +159,13 @@ VALUE rb_glfw_get_monitors(VALUE self)
155
159
  */
156
160
  VALUE rb_glfw_get_primary_monitor(VALUE self)
157
161
  {
158
- VALUE monitor = Data_Wrap_Struct(s_glfw_monitor_klass, 0, 0, glfwGetPrimaryMonitor());
159
- rb_obj_call_init(monitor, 0, 0);
160
- return monitor;
162
+ GLFWmonitor *monitor = glfwGetPrimaryMonitor();
163
+ VALUE rb_monitor = Qnil;
164
+ if (monitor != NULL) {
165
+ rb_monitor = Data_Wrap_Struct(s_glfw_monitor_klass, 0, 0, monitor);
166
+ rb_obj_call_init(rb_monitor, 0, 0);
167
+ }
168
+ return rb_monitor;
161
169
  }
162
170
 
163
171
 
@@ -213,8 +221,10 @@ VALUE rb_monitor_physical_size(VALUE self)
213
221
  VALUE rb_monitor_name(VALUE self)
214
222
  {
215
223
  GLFWmonitor *monitor;
224
+ const char *monitor_name = NULL;
216
225
  Data_Get_Struct(self, GLFWmonitor, monitor);
217
- return rb_str_new2(glfwGetMonitorName(monitor));
226
+ monitor_name = glfwGetMonitorName(monitor);
227
+ return monitor_name ? rb_str_new2(monitor_name) : Qnil;
218
228
  }
219
229
 
220
230
 
@@ -391,8 +401,114 @@ static VALUE rb_monitor_set_gamma(VALUE self, VALUE gamma)
391
401
 
392
402
 
393
403
 
394
- #warning "No implementation for glfwGetGammaRamp bindings"
395
- #warning "No implementation for glfwSetGammaRamp bindings"
404
+ /*
405
+ * Gets the monitor's gamma ramp and returns it as a hash of its red, green, and
406
+ * blue gamma ramps. By default, this might be equal to
407
+ * `{ :red => [], :green => [], :blue => []}`. Ramp values are in the range of
408
+ * 0 through 65535, or the 0 through USHRT_MAX (in C).
409
+ *
410
+ * call-seq:
411
+ * get_gamma_ramp -> { :red => [...], :green => [...], :blue => [...] } or nil
412
+ * gamma_ramp = -> hash or nil
413
+ *
414
+ * Wraps glfwGetGammaRamp.
415
+ */
416
+ static VALUE rb_monitor_get_gamma_ramp(VALUE self)
417
+ {
418
+ GLFWmonitor *monitor;
419
+ const GLFWgammaramp *ramp;
420
+ VALUE rb_gamma_hash, rb_red, rb_green, rb_blue;
421
+ unsigned int ramp_index;
422
+ unsigned int ramp_len = ramp->size;
423
+
424
+ Data_Get_Struct(self, GLFWmonitor, monitor);
425
+ ramp = glfwGetGammaRamp(monitor);
426
+
427
+ rb_gamma_hash = rb_hash_new();
428
+ rb_red = rb_ary_new();
429
+ rb_green = rb_ary_new();
430
+ rb_blue = rb_ary_new();
431
+
432
+ for (ramp_index = 0; ramp_index < ramp_len; ++ramp_index) {
433
+ rb_ary_push(rb_red, INT2NUM(ramp->red[ramp_index]));
434
+ rb_ary_push(rb_green, INT2NUM(ramp->green[ramp_index]));
435
+ rb_ary_push(rb_blue, INT2NUM(ramp->blue[ramp_index]));
436
+ }
437
+
438
+ rb_hash_aset(rb_gamma_hash, ID2SYM(rb_intern("red")), rb_red);
439
+ rb_hash_aset(rb_gamma_hash, ID2SYM(rb_intern("green")), rb_green);
440
+ rb_hash_aset(rb_gamma_hash, ID2SYM(rb_intern("blue")), rb_blue);
441
+
442
+ return rb_gamma_hash;
443
+ }
444
+
445
+
446
+
447
+ /*
448
+ * Sets the monitor's gamma ramp with the ramps provided in the ramp hash. The
449
+ * ramp hash must have arrays for :red, :green, and :blue keys. The arrays
450
+ * should be the same length, otherwise the shortest array length will be used.
451
+ *
452
+ * Gamma ramps should be in the range of an usngiend short, so 0 through 65535
453
+ * or USHRT_MAX.
454
+ *
455
+ * For example, to set a linear gamma ramp that is half as intense as what is
456
+ * likely your default:
457
+ *
458
+ * ramp = (0 ... 32768).step(128).to_a
459
+ * monitor.set_gamma_ramp({ :red => ramp, :green => ramp, :blue => ramp })
460
+ *
461
+ * call-seq:
462
+ * set_gamma_ramp(ramp) -> self
463
+ * gamma_ramp = ramp -> self
464
+ *
465
+ * Wraps glfwSetGammaRamp.
466
+ *
467
+ */
468
+ static VALUE rb_monitor_set_gamma_ramp(VALUE self, VALUE ramp_hash)
469
+ {
470
+ GLFWmonitor *monitor;
471
+ GLFWgammaramp ramp;
472
+ VALUE rb_red, rb_green, rb_blue;
473
+ unsigned int ramp_index;
474
+ unsigned int ramp_len = 0;
475
+
476
+ Data_Get_Struct(self, GLFWmonitor, monitor);
477
+
478
+ rb_red = rb_hash_aref(ramp_hash, ID2SYM(rb_intern("red")));
479
+ rb_green = rb_hash_aref(ramp_hash, ID2SYM(rb_intern("green")));
480
+ rb_blue = rb_hash_aref(ramp_hash, ID2SYM(rb_intern("blue")));
481
+
482
+ if (!(RTEST(rb_red) && RTEST(rb_green) && RTEST(rb_blue))) {
483
+ rb_raise(rb_eArgError, "Ramp Hash must contain :red, :green, and :blue arrays");
484
+ }
485
+
486
+ ramp_len = RARRAY_LEN(rb_red);
487
+ if ((ramp_index = (unsigned int)RARRAY_LEN(rb_green)) < ramp_len) {
488
+ ramp_len = ramp_index;
489
+ } else if ((ramp_index = (unsigned int)RARRAY_LEN(rb_blue)) < ramp_len) {
490
+ ramp_len = ramp_index;
491
+ }
492
+
493
+ unsigned short *ramp_buffer = ALLOC_N(unsigned short, 3 * ramp_len);
494
+ ramp.red = ramp_buffer;
495
+ ramp.green = &ramp_buffer[ramp_len];
496
+ ramp.blue = &ramp_buffer[ramp_len * 2];
497
+
498
+ for (ramp_index = 0; ramp_index < ramp_len; ++ramp_index) {
499
+ ramp.red[ramp_index] = rb_num2ushort(rb_ary_entry(rb_red, ramp_index));
500
+ ramp.green[ramp_index] = rb_num2ushort(rb_ary_entry(rb_green, ramp_index));
501
+ ramp.blue[ramp_index] = rb_num2ushort(rb_ary_entry(rb_blue, ramp_index));
502
+ }
503
+
504
+ ramp.size = ramp_len;
505
+
506
+ glfwSetGammaRamp(monitor, &ramp);
507
+
508
+ free(ramp_buffer);
509
+
510
+ return self;
511
+ }
396
512
 
397
513
 
398
514
 
@@ -758,8 +874,12 @@ static VALUE rb_window_hide(VALUE self)
758
874
  static VALUE rb_window_get_monitor(VALUE self)
759
875
  {
760
876
  GLFWmonitor *monitor = glfwGetWindowMonitor(rb_get_window(self));
761
- VALUE rb_monitor = Data_Wrap_Struct(s_glfw_monitor_klass, 0, 0, monitor);
762
- rb_obj_call_init(rb_monitor, 0, 0);
877
+ VALUE rb_monitor = Qnil;
878
+ if (monitor != NULL) {
879
+ // windowed mode
880
+ Data_Wrap_Struct(s_glfw_monitor_klass, 0, 0, monitor);
881
+ rb_obj_call_init(rb_monitor, 0, 0);
882
+ }
763
883
  return rb_monitor;
764
884
  }
765
885
 
@@ -1339,6 +1459,8 @@ void Init_glfw3(void)
1339
1459
  rb_define_method(s_glfw_monitor_klass, "video_modes", rb_monitor_video_modes, 0);
1340
1460
  rb_define_method(s_glfw_monitor_klass, "video_mode", rb_monitor_video_mode, 0);
1341
1461
  rb_define_method(s_glfw_monitor_klass, "set_gamma", rb_monitor_set_gamma, 1);
1462
+ rb_define_method(s_glfw_monitor_klass, "set_gamma_ramp", rb_monitor_set_gamma_ramp, 1);
1463
+ rb_define_method(s_glfw_monitor_klass, "get_gamma_ramp", rb_monitor_get_gamma_ramp, 0);
1342
1464
 
1343
1465
  /* Glfw::VideoMode */
1344
1466
  rb_define_method(s_glfw_videomode_klass, "width", rb_videomode_width, 0);
@@ -1353,21 +1475,17 @@ void Init_glfw3(void)
1353
1475
  rb_define_singleton_method(s_glfw_window_klass, "window_hint", rb_window_window_hint, 2);
1354
1476
  rb_define_singleton_method(s_glfw_window_klass, "default_window_hints", rb_window_default_window_hints, 0);
1355
1477
  rb_define_singleton_method(s_glfw_window_klass, "unset_context", rb_window_unset_context, 0);
1356
- // rb_define_method(s_glfw_window_klass, "initialize", rb_window_init, -1);
1357
1478
  rb_define_method(s_glfw_window_klass, "destroy", rb_window_destroy, 0);
1358
- rb_define_method(s_glfw_window_klass, "should_close?", rb_window_should_close, 0);
1359
- rb_define_method(s_glfw_window_klass, "should_close=", rb_window_set_should_close, 1);
1479
+ rb_define_method(s_glfw_window_klass, "get_should_close", rb_window_should_close, 0);
1360
1480
  rb_define_method(s_glfw_window_klass, "set_should_close", rb_window_set_should_close, 1);
1361
1481
  rb_define_method(s_glfw_window_klass, "current_context", rb_window_get_current_context, 0);
1362
1482
  rb_define_method(s_glfw_window_klass, "make_context_current", rb_window_make_context_current, 0);
1363
1483
  rb_define_method(s_glfw_window_klass, "swap_buffers", rb_window_swap_buffers, 0);
1364
1484
  rb_define_method(s_glfw_window_klass, "title=", rb_window_set_title, 1);
1365
- rb_define_method(s_glfw_window_klass, "position", rb_window_get_position, 0);
1485
+ rb_define_method(s_glfw_window_klass, "get_position", rb_window_get_position, 0);
1366
1486
  rb_define_method(s_glfw_window_klass, "set_position", rb_window_set_position, 2);
1367
- rb_define_method(s_glfw_window_klass, "move", rb_window_set_position, 2);
1368
- rb_define_method(s_glfw_window_klass, "size", rb_window_get_size, 0);
1487
+ rb_define_method(s_glfw_window_klass, "get_size", rb_window_get_size, 0);
1369
1488
  rb_define_method(s_glfw_window_klass, "set_size", rb_window_set_size, 2);
1370
- rb_define_method(s_glfw_window_klass, "resize", rb_window_set_size, 2);
1371
1489
  rb_define_method(s_glfw_window_klass, "framebuffer_size", rb_window_get_framebuffer_size, 0);
1372
1490
  rb_define_method(s_glfw_window_klass, "iconify", rb_window_iconify, 0);
1373
1491
  rb_define_method(s_glfw_window_klass, "restore", rb_window_restore, 0);
@@ -1385,7 +1503,7 @@ void Init_glfw3(void)
1385
1503
  rb_define_method(s_glfw_window_klass, "set_input_mode", rb_window_set_input_mode, 2);
1386
1504
  rb_define_method(s_glfw_window_klass, "key", rb_window_get_key, 1);
1387
1505
  rb_define_method(s_glfw_window_klass, "mouse_button", rb_window_get_mouse_button, 1);
1388
- rb_define_method(s_glfw_window_klass, "cursor_pos", rb_window_get_cursor_pos, 0);
1506
+ rb_define_method(s_glfw_window_klass, "get_cursor_pos", rb_window_get_cursor_pos, 0);
1389
1507
  rb_define_method(s_glfw_window_klass, "set_cursor_pos", rb_window_set_cursor_pos, 2);
1390
1508
  rb_define_method(s_glfw_window_klass, "set_key_callback__", rb_window_set_key_callback, 1);
1391
1509
  rb_define_method(s_glfw_window_klass, "set_char_callback__", rb_window_set_char_callback, 1);
data/lib/glfw3.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'glfw3/glfw3'
2
2
  require 'glfw3/callbacks'
3
+ require 'glfw3/monitor'
3
4
  require 'glfw3/window'
4
5
 
5
6
  #
@@ -0,0 +1,8 @@
1
+ require 'glfw3/glfw3'
2
+
3
+ module Glfw ; end
4
+
5
+ class Glfw::Monitor
6
+ alias_method :gamma_ramp=, :set_gamma_ramp
7
+ alias_method :gamma_ramp, :get_gamma_ramp
8
+ end
data/lib/glfw3/window.rb CHANGED
@@ -33,14 +33,39 @@ class Glfw::Window
33
33
  #
34
34
  attr_accessor :user_data
35
35
 
36
+
37
+
38
+ alias_method :should_close?, :get_should_close
39
+ alias_method :should_close=, :set_should_close
40
+
41
+ alias_method :cursor_pos, :get_cursor_pos
42
+
43
+ def cursor_pos=(xy)
44
+ set_cursor_pos(*xy)
45
+ end
46
+
47
+ alias_method :move, :set_position
48
+ alias_method :resize, :set_size
49
+
50
+ alias_method :position, :get_position
51
+ alias_method :size, :get_size
52
+
53
+ def position=(xy)
54
+ set_position(*xy)
55
+ end
56
+
57
+ def size=(wh)
58
+ set_size(*wh)
59
+ end
60
+
36
61
  #
37
62
  # Returns an array of all allocated GLFW windows.
38
63
  #
39
64
  # call-seq:
40
65
  # windows -> [Glfw::Window, ...]
41
66
  #
42
- def windows
43
- @__windows.values
67
+ def self.windows
68
+ @@__windows.values
44
69
  end
45
70
 
46
71
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glfw3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noel Raymond Cower
@@ -21,6 +21,7 @@ extra_rdoc_files:
21
21
  - COPYING
22
22
  files:
23
23
  - lib/glfw3/callbacks.rb
24
+ - lib/glfw3/monitor.rb
24
25
  - lib/glfw3/window.rb
25
26
  - lib/glfw3.rb
26
27
  - ext/glfw3/glfw3.c