glfw 0.9.8 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Makefile +3 -3
- data/README.md +5 -2
- data/Rakefile +0 -9
- data/ext/glfw/common.h +45 -45
- data/ext/glfw/cursor.c +42 -42
- data/ext/glfw/cursor.h +13 -13
- data/ext/glfw/extconf.rb +13 -16
- data/ext/glfw/glfw.c +2 -2
- data/ext/glfw/image.c +76 -76
- data/ext/glfw/image.h +13 -13
- data/ext/glfw/monitor.c +209 -209
- data/ext/glfw/monitor.h +28 -28
- data/ext/glfw/video_mode.c +60 -60
- data/ext/glfw/video_mode.h +20 -20
- data/ext/glfw/vulkan.c +48 -48
- data/ext/glfw/vulkan.h +15 -15
- data/ext/glfw/window.c +708 -708
- data/ext/glfw/window.h +86 -86
- data/lib/glfw.rb +8 -26
- data/lib/glfw/version.rb +1 -1
- metadata +3 -4
- data/ext/glfw/lib/libglfw3.a +0 -0
data/ext/glfw/image.h
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
|
2
|
-
#ifndef GLFW_RB_IMAGE_H
|
3
|
-
#define GLFW_RB_IMAGE_H 1
|
4
|
-
|
5
|
-
#include "common.h"
|
6
|
-
|
7
|
-
void Init_glfw_image(VALUE module);
|
8
|
-
static VALUE rb_glfw_image_alloc(VALUE klass);
|
9
|
-
VALUE rb_glfw_image_initialize(int argc, VALUE *argv, VALUE self);
|
10
|
-
VALUE rb_glfw_image_width(VALUE self);
|
11
|
-
VALUE rb_glfw_image_height(VALUE self);
|
12
|
-
VALUE rb_glfw_image_pixels(VALUE self);
|
13
|
-
|
1
|
+
|
2
|
+
#ifndef GLFW_RB_IMAGE_H
|
3
|
+
#define GLFW_RB_IMAGE_H 1
|
4
|
+
|
5
|
+
#include "common.h"
|
6
|
+
|
7
|
+
void Init_glfw_image(VALUE module);
|
8
|
+
static VALUE rb_glfw_image_alloc(VALUE klass);
|
9
|
+
VALUE rb_glfw_image_initialize(int argc, VALUE *argv, VALUE self);
|
10
|
+
VALUE rb_glfw_image_width(VALUE self);
|
11
|
+
VALUE rb_glfw_image_height(VALUE self);
|
12
|
+
VALUE rb_glfw_image_pixels(VALUE self);
|
13
|
+
|
14
14
|
#endif /* GLFW_RB_IMAGE_H */
|
data/ext/glfw/monitor.c
CHANGED
@@ -1,209 +1,209 @@
|
|
1
|
-
|
2
|
-
#include "monitor.h"
|
3
|
-
|
4
|
-
VALUE rb_cGLFWmonitor;
|
5
|
-
|
6
|
-
void Init_glfw_monitor(VALUE module) {
|
7
|
-
rb_cGLFWmonitor = rb_define_class_under(module, "Monitor", rb_cObject);
|
8
|
-
|
9
|
-
rb_define_method(rb_cGLFWmonitor, "name", rb_glfw_monitor_name, 0);
|
10
|
-
rb_define_method(rb_cGLFWmonitor, "position", rb_glfw_monitor_pos, 0);
|
11
|
-
rb_define_method(rb_cGLFWmonitor, "size", rb_glfw_monitor_size, 0);
|
12
|
-
rb_define_method(rb_cGLFWmonitor, "x", rb_glfw_monitor_x, 0);
|
13
|
-
rb_define_method(rb_cGLFWmonitor, "y", rb_glfw_monitor_y, 0);
|
14
|
-
rb_define_method(rb_cGLFWmonitor, "width", rb_glfw_monitor_width, 0);
|
15
|
-
rb_define_method(rb_cGLFWmonitor, "height", rb_glfw_monitor_height, 0);
|
16
|
-
rb_define_method(rb_cGLFWmonitor, "dimensions", rb_glfw_monitor_dimensions, 0);
|
17
|
-
|
18
|
-
rb_define_method(rb_cGLFWmonitor, "gamma", rb_glfw_monitor_gamma, 1);
|
19
|
-
rb_define_method(rb_cGLFWmonitor, "gamma_ramp", rb_glfw_monitor_get_gamma_ramp, 0);
|
20
|
-
rb_define_method(rb_cGLFWmonitor, "set_gamma_ramp", rb_glfw_monitor_set_gamma_ramp, -1);
|
21
|
-
rb_define_method(rb_cGLFWmonitor, "video_mode", rb_glfw_monitor_video_mode, 0);
|
22
|
-
rb_define_method(rb_cGLFWmonitor, "video_modes", rb_glfw_monitor_video_modes, 0);
|
23
|
-
|
24
|
-
rb_define_singleton_method(rb_cGLFWmonitor, "primary", rb_glfw_monitor_primary, 0);
|
25
|
-
rb_define_const(rb_cGLFWmonitor, "NONE", rb_glfw_monitor_alloc(rb_cGLFWmonitor));
|
26
|
-
|
27
|
-
rb_funcall(rb_cGLFWmonitor, rb_intern("private_class_method"), 1, STR2SYM("new"));
|
28
|
-
}
|
29
|
-
|
30
|
-
static VALUE rb_glfw_monitor_alloc(VALUE klass) {
|
31
|
-
GLFWmonitor *monitor = ruby_xmalloc(SIZEOF_INTPTR_T);
|
32
|
-
memset(monitor, 0, SIZEOF_INTPTR_T);
|
33
|
-
return Data_Wrap_Struct(rb_cGLFWmonitor, NULL, RUBY_DEFAULT_FREE, monitor);
|
34
|
-
}
|
35
|
-
|
36
|
-
VALUE rb_glfw_monitor_name(VALUE self) {
|
37
|
-
MONITOR();
|
38
|
-
const char *name = glfwGetMonitorName(m);
|
39
|
-
return rb_str_new_cstr(name);
|
40
|
-
}
|
41
|
-
|
42
|
-
VALUE rb_glfw_monitor_pos(VALUE self) {
|
43
|
-
MONITOR();
|
44
|
-
int x, y;
|
45
|
-
glfwGetMonitorPos(m, &x, &y);
|
46
|
-
VALUE ary = rb_ary_new_capa(2);
|
47
|
-
rb_ary_store(ary, 0, INT2NUM(x));
|
48
|
-
rb_ary_store(ary, 1, INT2NUM(y));
|
49
|
-
return ary;
|
50
|
-
}
|
51
|
-
|
52
|
-
VALUE rb_glfw_monitor_size(VALUE self) {
|
53
|
-
MONITOR();
|
54
|
-
int width, height;
|
55
|
-
glfwGetMonitorPhysicalSize(m, &width, &height);
|
56
|
-
VALUE ary = rb_ary_new_capa(2);
|
57
|
-
rb_ary_store(ary, 0, INT2NUM(width));
|
58
|
-
rb_ary_store(ary, 1, INT2NUM(height));
|
59
|
-
return ary;
|
60
|
-
}
|
61
|
-
|
62
|
-
VALUE rb_glfw_monitor_x(VALUE self) {
|
63
|
-
MONITOR();
|
64
|
-
int x;
|
65
|
-
glfwGetMonitorPos(m, &x, NULL);
|
66
|
-
return INT2NUM(x);
|
67
|
-
}
|
68
|
-
|
69
|
-
VALUE rb_glfw_monitor_y(VALUE self) {
|
70
|
-
MONITOR();
|
71
|
-
int y;
|
72
|
-
glfwGetMonitorPos(m, NULL, &y);
|
73
|
-
return INT2NUM(y);
|
74
|
-
}
|
75
|
-
|
76
|
-
VALUE rb_glfw_monitor_width(VALUE self) {
|
77
|
-
MONITOR();
|
78
|
-
int width;
|
79
|
-
glfwGetMonitorPhysicalSize(m, &width, NULL);
|
80
|
-
return INT2NUM(width);
|
81
|
-
}
|
82
|
-
|
83
|
-
VALUE rb_glfw_monitor_height(VALUE self) {
|
84
|
-
MONITOR();
|
85
|
-
int height;
|
86
|
-
glfwGetMonitorPhysicalSize(m, NULL, &height);
|
87
|
-
return INT2NUM(height);
|
88
|
-
}
|
89
|
-
|
90
|
-
VALUE rb_glfw_monitor_dimensions(VALUE self) {
|
91
|
-
MONITOR();
|
92
|
-
int x, y, width, height;
|
93
|
-
glfwGetMonitorPos(m, &x, &y);
|
94
|
-
glfwGetMonitorPhysicalSize(m, &width, &height);
|
95
|
-
VALUE ary = rb_ary_new_capa(4);
|
96
|
-
rb_ary_store(ary, 0, INT2NUM(x));
|
97
|
-
rb_ary_store(ary, 1, INT2NUM(y));
|
98
|
-
rb_ary_store(ary, 2, INT2NUM(width));
|
99
|
-
rb_ary_store(ary, 3, INT2NUM(height));
|
100
|
-
return ary;
|
101
|
-
}
|
102
|
-
|
103
|
-
VALUE rb_glfw_monitor_get_gamma_ramp(VALUE self) {
|
104
|
-
MONITOR();
|
105
|
-
const GLFWgammaramp *ramp = glfwGetGammaRamp(m);
|
106
|
-
|
107
|
-
if (ramp == NULL)
|
108
|
-
return Qnil;
|
109
|
-
|
110
|
-
int count = ramp->size;
|
111
|
-
VALUE hash = rb_hash_new();
|
112
|
-
VALUE red = rb_ary_new_capa(count), green = rb_ary_new_capa(count), blue = rb_ary_new_capa(count);
|
113
|
-
|
114
|
-
for (int i = 0; i < count; i++) {
|
115
|
-
rb_ary_store(red, i, INT2NUM(ramp->red[i]));
|
116
|
-
rb_ary_store(green, i, INT2NUM(ramp->green[i]));
|
117
|
-
rb_ary_store(blue, i, INT2NUM(ramp->blue[i]));
|
118
|
-
}
|
119
|
-
|
120
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("red")), red);
|
121
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("green")), green);
|
122
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("blue")), blue);
|
123
|
-
|
124
|
-
return hash;
|
125
|
-
}
|
126
|
-
|
127
|
-
VALUE rb_glfw_monitor_set_gamma_ramp(int argc, VALUE *argv, VALUE self) {
|
128
|
-
if (argc != 1 && argc != 3)
|
129
|
-
{
|
130
|
-
rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 1, 3)", argc);
|
131
|
-
return Qnil;
|
132
|
-
}
|
133
|
-
|
134
|
-
MONITOR();
|
135
|
-
VALUE red, green, blue;
|
136
|
-
|
137
|
-
if (argc == 1)
|
138
|
-
{
|
139
|
-
Check_Type(argv[0], T_HASH);
|
140
|
-
red = rb_hash_aref(argv[0], ID2SYM(rb_intern("red")));
|
141
|
-
green = rb_hash_aref(argv[0], ID2SYM(rb_intern("green")));
|
142
|
-
blue = rb_hash_aref(argv[0], ID2SYM(rb_intern("blue")));
|
143
|
-
}
|
144
|
-
else
|
145
|
-
{
|
146
|
-
red = argv[0];
|
147
|
-
green = argv[1];
|
148
|
-
blue = argv[2];
|
149
|
-
}
|
150
|
-
|
151
|
-
Check_Type(red, T_ARRAY);
|
152
|
-
Check_Type(green, T_ARRAY);
|
153
|
-
Check_Type(blue, T_ARRAY);
|
154
|
-
|
155
|
-
int size = rb_array_len(red);
|
156
|
-
if (rb_array_len(green) != size || rb_array_len(blue) != size)
|
157
|
-
{
|
158
|
-
rb_raise(rb_eRuntimeError, "red, green, and blue gamma ramps must all be of equal length");
|
159
|
-
return Qnil;
|
160
|
-
}
|
161
|
-
|
162
|
-
GLFWgammaramp *ramp = malloc(sizeof(GLFWgammaramp));
|
163
|
-
ramp->size = size;
|
164
|
-
ramp->red = malloc(sizeof(u_short) * size);
|
165
|
-
ramp->green = malloc(sizeof(u_short) * size);
|
166
|
-
ramp->blue = malloc(sizeof(u_short) * size);
|
167
|
-
|
168
|
-
for (int i = 0; i < size; i++)
|
169
|
-
{
|
170
|
-
ramp->red[i] = NUM2USHORT(rb_ary_entry(red, i));
|
171
|
-
ramp->green[i] = NUM2USHORT(rb_ary_entry(green, i));
|
172
|
-
ramp->blue[i] = NUM2USHORT(rb_ary_entry(blue, i));
|
173
|
-
}
|
174
|
-
|
175
|
-
glfwSetGammaRamp(m, ramp);
|
176
|
-
|
177
|
-
free(ramp);
|
178
|
-
return self;
|
179
|
-
}
|
180
|
-
|
181
|
-
VALUE rb_glfw_monitor_gamma(VALUE self, VALUE exponent) {
|
182
|
-
MONITOR();
|
183
|
-
float e = (float) NUM2DBL(exponent);
|
184
|
-
glfwSetGamma(m, e);
|
185
|
-
return exponent;
|
186
|
-
}
|
187
|
-
|
188
|
-
VALUE rb_glfw_monitor_primary(VALUE klass) {
|
189
|
-
GLFWmonitor *m = glfwGetPrimaryMonitor();
|
190
|
-
return Data_Wrap_Struct(klass, NULL, RUBY_DEFAULT_FREE, m);
|
191
|
-
}
|
192
|
-
|
193
|
-
VALUE rb_glfw_monitor_video_mode(VALUE self) {
|
194
|
-
MONITOR();
|
195
|
-
const GLFWvidmode *v = glfwGetVideoMode(m);
|
196
|
-
return Data_Wrap_Struct(rb_cGLFWvidmode, NULL, RUBY_DEFAULT_FREE, (void*) v);
|
197
|
-
}
|
198
|
-
|
199
|
-
VALUE rb_glfw_monitor_video_modes(VALUE self) {
|
200
|
-
MONITOR();
|
201
|
-
int count;
|
202
|
-
const GLFWvidmode *modes = glfwGetVideoModes(m, &count);
|
203
|
-
VALUE ary = rb_ary_new_capa(count);
|
204
|
-
for (int i = 0; i < count; i++)
|
205
|
-
{
|
206
|
-
rb_ary_store(ary, i, Data_Wrap_Struct(rb_cGLFWvidmode, NULL, RUBY_DEFAULT_FREE, (void*) &modes[i]));
|
207
|
-
}
|
208
|
-
return ary;
|
209
|
-
}
|
1
|
+
|
2
|
+
#include "monitor.h"
|
3
|
+
|
4
|
+
VALUE rb_cGLFWmonitor;
|
5
|
+
|
6
|
+
void Init_glfw_monitor(VALUE module) {
|
7
|
+
rb_cGLFWmonitor = rb_define_class_under(module, "Monitor", rb_cObject);
|
8
|
+
|
9
|
+
rb_define_method(rb_cGLFWmonitor, "name", rb_glfw_monitor_name, 0);
|
10
|
+
rb_define_method(rb_cGLFWmonitor, "position", rb_glfw_monitor_pos, 0);
|
11
|
+
rb_define_method(rb_cGLFWmonitor, "size", rb_glfw_monitor_size, 0);
|
12
|
+
rb_define_method(rb_cGLFWmonitor, "x", rb_glfw_monitor_x, 0);
|
13
|
+
rb_define_method(rb_cGLFWmonitor, "y", rb_glfw_monitor_y, 0);
|
14
|
+
rb_define_method(rb_cGLFWmonitor, "width", rb_glfw_monitor_width, 0);
|
15
|
+
rb_define_method(rb_cGLFWmonitor, "height", rb_glfw_monitor_height, 0);
|
16
|
+
rb_define_method(rb_cGLFWmonitor, "dimensions", rb_glfw_monitor_dimensions, 0);
|
17
|
+
|
18
|
+
rb_define_method(rb_cGLFWmonitor, "gamma", rb_glfw_monitor_gamma, 1);
|
19
|
+
rb_define_method(rb_cGLFWmonitor, "gamma_ramp", rb_glfw_monitor_get_gamma_ramp, 0);
|
20
|
+
rb_define_method(rb_cGLFWmonitor, "set_gamma_ramp", rb_glfw_monitor_set_gamma_ramp, -1);
|
21
|
+
rb_define_method(rb_cGLFWmonitor, "video_mode", rb_glfw_monitor_video_mode, 0);
|
22
|
+
rb_define_method(rb_cGLFWmonitor, "video_modes", rb_glfw_monitor_video_modes, 0);
|
23
|
+
|
24
|
+
rb_define_singleton_method(rb_cGLFWmonitor, "primary", rb_glfw_monitor_primary, 0);
|
25
|
+
rb_define_const(rb_cGLFWmonitor, "NONE", rb_glfw_monitor_alloc(rb_cGLFWmonitor));
|
26
|
+
|
27
|
+
rb_funcall(rb_cGLFWmonitor, rb_intern("private_class_method"), 1, STR2SYM("new"));
|
28
|
+
}
|
29
|
+
|
30
|
+
static VALUE rb_glfw_monitor_alloc(VALUE klass) {
|
31
|
+
GLFWmonitor *monitor = ruby_xmalloc(SIZEOF_INTPTR_T);
|
32
|
+
memset(monitor, 0, SIZEOF_INTPTR_T);
|
33
|
+
return Data_Wrap_Struct(rb_cGLFWmonitor, NULL, RUBY_DEFAULT_FREE, monitor);
|
34
|
+
}
|
35
|
+
|
36
|
+
VALUE rb_glfw_monitor_name(VALUE self) {
|
37
|
+
MONITOR();
|
38
|
+
const char *name = glfwGetMonitorName(m);
|
39
|
+
return rb_str_new_cstr(name);
|
40
|
+
}
|
41
|
+
|
42
|
+
VALUE rb_glfw_monitor_pos(VALUE self) {
|
43
|
+
MONITOR();
|
44
|
+
int x, y;
|
45
|
+
glfwGetMonitorPos(m, &x, &y);
|
46
|
+
VALUE ary = rb_ary_new_capa(2);
|
47
|
+
rb_ary_store(ary, 0, INT2NUM(x));
|
48
|
+
rb_ary_store(ary, 1, INT2NUM(y));
|
49
|
+
return ary;
|
50
|
+
}
|
51
|
+
|
52
|
+
VALUE rb_glfw_monitor_size(VALUE self) {
|
53
|
+
MONITOR();
|
54
|
+
int width, height;
|
55
|
+
glfwGetMonitorPhysicalSize(m, &width, &height);
|
56
|
+
VALUE ary = rb_ary_new_capa(2);
|
57
|
+
rb_ary_store(ary, 0, INT2NUM(width));
|
58
|
+
rb_ary_store(ary, 1, INT2NUM(height));
|
59
|
+
return ary;
|
60
|
+
}
|
61
|
+
|
62
|
+
VALUE rb_glfw_monitor_x(VALUE self) {
|
63
|
+
MONITOR();
|
64
|
+
int x;
|
65
|
+
glfwGetMonitorPos(m, &x, NULL);
|
66
|
+
return INT2NUM(x);
|
67
|
+
}
|
68
|
+
|
69
|
+
VALUE rb_glfw_monitor_y(VALUE self) {
|
70
|
+
MONITOR();
|
71
|
+
int y;
|
72
|
+
glfwGetMonitorPos(m, NULL, &y);
|
73
|
+
return INT2NUM(y);
|
74
|
+
}
|
75
|
+
|
76
|
+
VALUE rb_glfw_monitor_width(VALUE self) {
|
77
|
+
MONITOR();
|
78
|
+
int width;
|
79
|
+
glfwGetMonitorPhysicalSize(m, &width, NULL);
|
80
|
+
return INT2NUM(width);
|
81
|
+
}
|
82
|
+
|
83
|
+
VALUE rb_glfw_monitor_height(VALUE self) {
|
84
|
+
MONITOR();
|
85
|
+
int height;
|
86
|
+
glfwGetMonitorPhysicalSize(m, NULL, &height);
|
87
|
+
return INT2NUM(height);
|
88
|
+
}
|
89
|
+
|
90
|
+
VALUE rb_glfw_monitor_dimensions(VALUE self) {
|
91
|
+
MONITOR();
|
92
|
+
int x, y, width, height;
|
93
|
+
glfwGetMonitorPos(m, &x, &y);
|
94
|
+
glfwGetMonitorPhysicalSize(m, &width, &height);
|
95
|
+
VALUE ary = rb_ary_new_capa(4);
|
96
|
+
rb_ary_store(ary, 0, INT2NUM(x));
|
97
|
+
rb_ary_store(ary, 1, INT2NUM(y));
|
98
|
+
rb_ary_store(ary, 2, INT2NUM(width));
|
99
|
+
rb_ary_store(ary, 3, INT2NUM(height));
|
100
|
+
return ary;
|
101
|
+
}
|
102
|
+
|
103
|
+
VALUE rb_glfw_monitor_get_gamma_ramp(VALUE self) {
|
104
|
+
MONITOR();
|
105
|
+
const GLFWgammaramp *ramp = glfwGetGammaRamp(m);
|
106
|
+
|
107
|
+
if (ramp == NULL)
|
108
|
+
return Qnil;
|
109
|
+
|
110
|
+
int count = ramp->size;
|
111
|
+
VALUE hash = rb_hash_new();
|
112
|
+
VALUE red = rb_ary_new_capa(count), green = rb_ary_new_capa(count), blue = rb_ary_new_capa(count);
|
113
|
+
|
114
|
+
for (int i = 0; i < count; i++) {
|
115
|
+
rb_ary_store(red, i, INT2NUM(ramp->red[i]));
|
116
|
+
rb_ary_store(green, i, INT2NUM(ramp->green[i]));
|
117
|
+
rb_ary_store(blue, i, INT2NUM(ramp->blue[i]));
|
118
|
+
}
|
119
|
+
|
120
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("red")), red);
|
121
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("green")), green);
|
122
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("blue")), blue);
|
123
|
+
|
124
|
+
return hash;
|
125
|
+
}
|
126
|
+
|
127
|
+
VALUE rb_glfw_monitor_set_gamma_ramp(int argc, VALUE *argv, VALUE self) {
|
128
|
+
if (argc != 1 && argc != 3)
|
129
|
+
{
|
130
|
+
rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 1, 3)", argc);
|
131
|
+
return Qnil;
|
132
|
+
}
|
133
|
+
|
134
|
+
MONITOR();
|
135
|
+
VALUE red, green, blue;
|
136
|
+
|
137
|
+
if (argc == 1)
|
138
|
+
{
|
139
|
+
Check_Type(argv[0], T_HASH);
|
140
|
+
red = rb_hash_aref(argv[0], ID2SYM(rb_intern("red")));
|
141
|
+
green = rb_hash_aref(argv[0], ID2SYM(rb_intern("green")));
|
142
|
+
blue = rb_hash_aref(argv[0], ID2SYM(rb_intern("blue")));
|
143
|
+
}
|
144
|
+
else
|
145
|
+
{
|
146
|
+
red = argv[0];
|
147
|
+
green = argv[1];
|
148
|
+
blue = argv[2];
|
149
|
+
}
|
150
|
+
|
151
|
+
Check_Type(red, T_ARRAY);
|
152
|
+
Check_Type(green, T_ARRAY);
|
153
|
+
Check_Type(blue, T_ARRAY);
|
154
|
+
|
155
|
+
int size = rb_array_len(red);
|
156
|
+
if (rb_array_len(green) != size || rb_array_len(blue) != size)
|
157
|
+
{
|
158
|
+
rb_raise(rb_eRuntimeError, "red, green, and blue gamma ramps must all be of equal length");
|
159
|
+
return Qnil;
|
160
|
+
}
|
161
|
+
|
162
|
+
GLFWgammaramp *ramp = malloc(sizeof(GLFWgammaramp));
|
163
|
+
ramp->size = size;
|
164
|
+
ramp->red = malloc(sizeof(u_short) * size);
|
165
|
+
ramp->green = malloc(sizeof(u_short) * size);
|
166
|
+
ramp->blue = malloc(sizeof(u_short) * size);
|
167
|
+
|
168
|
+
for (int i = 0; i < size; i++)
|
169
|
+
{
|
170
|
+
ramp->red[i] = NUM2USHORT(rb_ary_entry(red, i));
|
171
|
+
ramp->green[i] = NUM2USHORT(rb_ary_entry(green, i));
|
172
|
+
ramp->blue[i] = NUM2USHORT(rb_ary_entry(blue, i));
|
173
|
+
}
|
174
|
+
|
175
|
+
glfwSetGammaRamp(m, ramp);
|
176
|
+
|
177
|
+
free(ramp);
|
178
|
+
return self;
|
179
|
+
}
|
180
|
+
|
181
|
+
VALUE rb_glfw_monitor_gamma(VALUE self, VALUE exponent) {
|
182
|
+
MONITOR();
|
183
|
+
float e = (float) NUM2DBL(exponent);
|
184
|
+
glfwSetGamma(m, e);
|
185
|
+
return exponent;
|
186
|
+
}
|
187
|
+
|
188
|
+
VALUE rb_glfw_monitor_primary(VALUE klass) {
|
189
|
+
GLFWmonitor *m = glfwGetPrimaryMonitor();
|
190
|
+
return Data_Wrap_Struct(klass, NULL, RUBY_DEFAULT_FREE, m);
|
191
|
+
}
|
192
|
+
|
193
|
+
VALUE rb_glfw_monitor_video_mode(VALUE self) {
|
194
|
+
MONITOR();
|
195
|
+
const GLFWvidmode *v = glfwGetVideoMode(m);
|
196
|
+
return Data_Wrap_Struct(rb_cGLFWvidmode, NULL, RUBY_DEFAULT_FREE, (void*) v);
|
197
|
+
}
|
198
|
+
|
199
|
+
VALUE rb_glfw_monitor_video_modes(VALUE self) {
|
200
|
+
MONITOR();
|
201
|
+
int count;
|
202
|
+
const GLFWvidmode *modes = glfwGetVideoModes(m, &count);
|
203
|
+
VALUE ary = rb_ary_new_capa(count);
|
204
|
+
for (int i = 0; i < count; i++)
|
205
|
+
{
|
206
|
+
rb_ary_store(ary, i, Data_Wrap_Struct(rb_cGLFWvidmode, NULL, RUBY_DEFAULT_FREE, (void*) &modes[i]));
|
207
|
+
}
|
208
|
+
return ary;
|
209
|
+
}
|
data/ext/glfw/monitor.h
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
|
2
|
-
#ifndef GLFW_RB_MONITOR_H
|
3
|
-
#define GLFW_RB_MONITOR_H 1
|
4
|
-
|
5
|
-
#include "common.h"
|
6
|
-
#include "monitor.h"
|
7
|
-
|
8
|
-
#define MONITOR() \
|
9
|
-
GLFWmonitor *m; \
|
10
|
-
Data_Get_Struct(self, GLFWmonitor, m)
|
11
|
-
|
12
|
-
void Init_glfw_monitor(VALUE module);
|
13
|
-
static VALUE rb_glfw_monitor_alloc(VALUE klass);
|
14
|
-
VALUE rb_glfw_monitor_name(VALUE self);
|
15
|
-
VALUE rb_glfw_monitor_pos(VALUE self);
|
16
|
-
VALUE rb_glfw_monitor_size(VALUE self);
|
17
|
-
VALUE rb_glfw_monitor_x(VALUE self);
|
18
|
-
VALUE rb_glfw_monitor_y(VALUE self);
|
19
|
-
VALUE rb_glfw_monitor_width(VALUE self);
|
20
|
-
VALUE rb_glfw_monitor_height(VALUE self);
|
21
|
-
VALUE rb_glfw_monitor_dimensions(VALUE self);
|
22
|
-
VALUE rb_glfw_monitor_get_gamma_ramp(VALUE self);
|
23
|
-
VALUE rb_glfw_monitor_set_gamma_ramp(int argc, VALUE *argv, VALUE self);
|
24
|
-
VALUE rb_glfw_monitor_gamma(VALUE self, VALUE exponent);
|
25
|
-
VALUE rb_glfw_monitor_video_mode(VALUE self);
|
26
|
-
VALUE rb_glfw_monitor_video_modes(VALUE self);
|
27
|
-
VALUE rb_glfw_monitor_primary(VALUE klass);
|
28
|
-
|
1
|
+
|
2
|
+
#ifndef GLFW_RB_MONITOR_H
|
3
|
+
#define GLFW_RB_MONITOR_H 1
|
4
|
+
|
5
|
+
#include "common.h"
|
6
|
+
#include "monitor.h"
|
7
|
+
|
8
|
+
#define MONITOR() \
|
9
|
+
GLFWmonitor *m; \
|
10
|
+
Data_Get_Struct(self, GLFWmonitor, m)
|
11
|
+
|
12
|
+
void Init_glfw_monitor(VALUE module);
|
13
|
+
static VALUE rb_glfw_monitor_alloc(VALUE klass);
|
14
|
+
VALUE rb_glfw_monitor_name(VALUE self);
|
15
|
+
VALUE rb_glfw_monitor_pos(VALUE self);
|
16
|
+
VALUE rb_glfw_monitor_size(VALUE self);
|
17
|
+
VALUE rb_glfw_monitor_x(VALUE self);
|
18
|
+
VALUE rb_glfw_monitor_y(VALUE self);
|
19
|
+
VALUE rb_glfw_monitor_width(VALUE self);
|
20
|
+
VALUE rb_glfw_monitor_height(VALUE self);
|
21
|
+
VALUE rb_glfw_monitor_dimensions(VALUE self);
|
22
|
+
VALUE rb_glfw_monitor_get_gamma_ramp(VALUE self);
|
23
|
+
VALUE rb_glfw_monitor_set_gamma_ramp(int argc, VALUE *argv, VALUE self);
|
24
|
+
VALUE rb_glfw_monitor_gamma(VALUE self, VALUE exponent);
|
25
|
+
VALUE rb_glfw_monitor_video_mode(VALUE self);
|
26
|
+
VALUE rb_glfw_monitor_video_modes(VALUE self);
|
27
|
+
VALUE rb_glfw_monitor_primary(VALUE klass);
|
28
|
+
|
29
29
|
#endif /* GLFW_RB_MONITOR_H */
|