texplay 0.4.3 → 0.4.4.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +225 -222
- data/README.markdown +48 -48
- data/Rakefile +16 -16
- data/examples/common.rb +18 -18
- data/examples/example_alpha_blend.rb +29 -29
- data/examples/example_bezier.rb +41 -41
- data/examples/example_blank.rb +37 -37
- data/examples/example_cache.rb +21 -21
- data/examples/example_color_control.rb +69 -69
- data/examples/example_color_transform.rb +62 -62
- data/examples/example_color_transform_circle.rb +34 -34
- data/examples/example_darken.rb +24 -24
- data/examples/example_dup.rb +73 -73
- data/examples/example_each.rb +39 -39
- data/examples/example_effect.rb +34 -34
- data/examples/example_fill.rb +43 -43
- data/examples/example_fill_old.rb +48 -48
- data/examples/example_fluent.rb +29 -29
- data/examples/example_font.rb +31 -31
- data/examples/example_hash_arguments.rb +46 -46
- data/examples/example_ippa.rb +23 -23
- data/examples/example_light.rb +75 -75
- data/examples/example_light_multiply.rb +18 -18
- data/examples/example_lsystem.rb +61 -61
- data/examples/example_melt.rb +25 -25
- data/examples/example_meyet.rb +62 -62
- data/examples/example_polyline.rb +42 -42
- data/examples/example_scale.rb +27 -27
- data/examples/example_select.rb +36 -36
- data/examples/example_select2.rb +25 -25
- data/examples/example_simple.rb +46 -46
- data/examples/example_splice.rb +26 -26
- data/examples/example_sync.rb +59 -59
- data/examples/example_tiles.rb +41 -41
- data/examples/example_trace.rb +22 -22
- data/examples/example_transparent.rb +28 -28
- data/examples/example_transparent2.rb +24 -24
- data/examples/example_transparent3.rb +20 -20
- data/examples/example_turtle.rb +39 -39
- data/examples/example_weird.rb +22 -22
- data/examples/example_window_render_to_image.rb +41 -41
- data/examples/example_window_to_blob.rb +35 -35
- data/examples/media/maria.png +0 -0
- data/examples/media/rose.bmp +0 -0
- data/ext/texplay/actions.c +1011 -1006
- data/ext/texplay/actions.h +60 -60
- data/ext/texplay/bindings.c +1130 -1125
- data/ext/texplay/bindings.h +46 -46
- data/ext/texplay/cache.c +123 -118
- data/ext/texplay/cache.h +24 -24
- data/ext/texplay/compat.h +21 -27
- data/ext/texplay/extconf.rb +38 -38
- data/ext/texplay/graphics_utils.c +1318 -1313
- data/ext/texplay/graphics_utils.h +22 -22
- data/ext/texplay/texplay.c +206 -201
- data/ext/texplay/texplay.h +153 -153
- data/ext/texplay/utils.c +896 -891
- data/ext/texplay/utils.h +153 -153
- data/lib/texplay-contrib.rb +147 -147
- data/lib/texplay.rb +347 -347
- data/lib/texplay/alone.rb +20 -20
- data/lib/texplay/c_function_docs.rb +178 -178
- data/lib/texplay/live.rb +84 -84
- data/lib/texplay/version.rb +3 -3
- data/live/live.rb +85 -85
- data/test/image_spec.rb +45 -45
- data/test/texplay_spec.rb +144 -144
- metadata +42 -52
- data/lib/texplay/1.8/texplay.so +0 -0
- data/lib/texplay/1.9/texplay.so +0 -0
@@ -1,22 +1,22 @@
|
|
1
|
-
#ifndef GUARD_GRAPHICS_UTILS_H
|
2
|
-
#define GUARD_GRAPHICS_UTILS_H
|
3
|
-
|
4
|
-
void update_lazy_bounds(action_struct * cur, texture_info * tex);
|
5
|
-
void update_bounds(action_struct * cur, int xmin, int ymin, int xmax, int ymax);
|
6
|
-
void set_local_bounds(action_struct * cur, int xmin, int ymin, int xmax, int ymax, texture_info * tex);
|
7
|
-
|
8
|
-
void draw_prologue(action_struct * cur, texture_info * tex, int xmin, int ymin, int xmax, int ymax, VALUE * hash_arg,
|
9
|
-
|
10
|
-
void draw_epilogue(action_struct * cur, texture_info * tex, bool primary);
|
11
|
-
|
12
|
-
void set_pixel_color_with_style(action_struct * payload, texture_info * tex, int x, int y);
|
13
|
-
void set_pixel_color(rgba * pixel_color, texture_info * tex, int x, int y);
|
14
|
-
|
15
|
-
rgba get_pixel_color_from_chunk(float * chunk, int width, int height, int x, int y);
|
16
|
-
rgba get_pixel_color(texture_info * tex, int x, int y);
|
17
|
-
float* get_pixel_data(texture_info * tex, int x, int y);
|
18
|
-
|
19
|
-
/* create a blank gosu image of width and height */
|
20
|
-
VALUE create_image(VALUE window, int width, int height);
|
21
|
-
|
22
|
-
#endif
|
1
|
+
#ifndef GUARD_GRAPHICS_UTILS_H
|
2
|
+
#define GUARD_GRAPHICS_UTILS_H
|
3
|
+
|
4
|
+
void update_lazy_bounds(action_struct * cur, texture_info * tex);
|
5
|
+
void update_bounds(action_struct * cur, int xmin, int ymin, int xmax, int ymax);
|
6
|
+
void set_local_bounds(action_struct * cur, int xmin, int ymin, int xmax, int ymax, texture_info * tex);
|
7
|
+
|
8
|
+
void draw_prologue(action_struct * cur, texture_info * tex, int xmin, int ymin, int xmax, int ymax, VALUE * hash_arg,
|
9
|
+
sync_ sync_mode, bool primary, action_struct ** payload_ptr);
|
10
|
+
void draw_epilogue(action_struct * cur, texture_info * tex, bool primary);
|
11
|
+
|
12
|
+
void set_pixel_color_with_style(action_struct * payload, texture_info * tex, int x, int y);
|
13
|
+
void set_pixel_color(rgba * pixel_color, texture_info * tex, int x, int y);
|
14
|
+
|
15
|
+
rgba get_pixel_color_from_chunk(float * chunk, int width, int height, int x, int y);
|
16
|
+
rgba get_pixel_color(texture_info * tex, int x, int y);
|
17
|
+
float* get_pixel_data(texture_info * tex, int x, int y);
|
18
|
+
|
19
|
+
/* create a blank gosu image of width and height */
|
20
|
+
VALUE create_image(VALUE window, int width, int height);
|
21
|
+
|
22
|
+
#endif
|
data/ext/texplay/texplay.c
CHANGED
@@ -1,201 +1,206 @@
|
|
1
|
-
/* texplay.c, light-weight alternative to rmagick for ruby */
|
2
|
-
/* (C) John Mair 2009
|
3
|
-
* This program is distributed under the terms of the MIT License
|
4
|
-
* */
|
5
|
-
|
6
|
-
#include <ruby.h>
|
7
|
-
#include <stdio.h>
|
8
|
-
#include <time.h>
|
9
|
-
#include "texplay.h"
|
10
|
-
#include "actions.h"
|
11
|
-
#include "utils.h"
|
12
|
-
#include "bindings.h"
|
13
|
-
#ifdef __APPLE__
|
14
|
-
# include <
|
15
|
-
#
|
16
|
-
# include <
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
rb_define_method(
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
rb_define_method(jm_Module, "
|
46
|
-
rb_define_method(jm_Module, "
|
47
|
-
rb_define_method(jm_Module, "
|
48
|
-
rb_define_method(jm_Module, "
|
49
|
-
rb_define_method(jm_Module, "
|
50
|
-
|
51
|
-
rb_define_method(jm_Module, "
|
52
|
-
|
53
|
-
rb_define_method(jm_Module, "
|
54
|
-
rb_define_method(jm_Module, "
|
55
|
-
|
56
|
-
rb_define_method(jm_Module, "
|
57
|
-
|
58
|
-
rb_define_method(jm_Module, "
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
rb_define_method(jm_Module, "
|
67
|
-
rb_define_method(jm_Module, "
|
68
|
-
rb_define_method(jm_Module, "
|
69
|
-
rb_define_method(jm_Module, "
|
70
|
-
|
71
|
-
rb_define_method(jm_Module, "
|
72
|
-
rb_define_method(jm_Module, "
|
73
|
-
|
74
|
-
rb_define_method(jm_Module, "
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
rb_define_method(jm_Module, "
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
int
|
159
|
-
int
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
gosu_window(
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
1
|
+
/* texplay.c, light-weight alternative to rmagick for ruby */
|
2
|
+
/* (C) John Mair 2009
|
3
|
+
* This program is distributed under the terms of the MIT License
|
4
|
+
* */
|
5
|
+
|
6
|
+
#include <ruby.h>
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <time.h>
|
9
|
+
#include "texplay.h"
|
10
|
+
#include "actions.h"
|
11
|
+
#include "utils.h"
|
12
|
+
#include "bindings.h"
|
13
|
+
#ifdef __APPLE__
|
14
|
+
# include <AvailabilityMacros.h>
|
15
|
+
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9
|
16
|
+
# include <GLUT/glut.h>
|
17
|
+
#else
|
18
|
+
# include <GL/glut.h>
|
19
|
+
#endif
|
20
|
+
#else
|
21
|
+
# include <GL/glut.h>
|
22
|
+
#endif
|
23
|
+
|
24
|
+
|
25
|
+
/* setup ruby bindings */
|
26
|
+
|
27
|
+
/** constructor for TPPoint class **/
|
28
|
+
static VALUE m_init_TPPoint(int argc, VALUE * argv, VALUE self);
|
29
|
+
static void monkey_patch_gosu(void);
|
30
|
+
static VALUE gosu_window(void);
|
31
|
+
|
32
|
+
void
|
33
|
+
Init_texplay() {
|
34
|
+
|
35
|
+
VALUE jm_Module = rb_define_module("TexPlay");
|
36
|
+
VALUE TPPoint = rb_define_class_under(jm_Module, "TPPoint", rb_cObject);
|
37
|
+
|
38
|
+
/** define basic point class TPPoint **/
|
39
|
+
rb_attr(TPPoint, rb_intern("x"), 1, 1, Qtrue);
|
40
|
+
rb_attr(TPPoint, rb_intern("y"), 1, 1, Qtrue);
|
41
|
+
rb_define_method(TPPoint, "initialize", m_init_TPPoint, -1);
|
42
|
+
/** end of TPPoint definition **/
|
43
|
+
|
44
|
+
/* TexPlay methods */
|
45
|
+
rb_define_method(jm_Module, "paint", m_paint, -1);
|
46
|
+
rb_define_method(jm_Module, "get_pixel", m_getpixel, -1);
|
47
|
+
rb_define_method(jm_Module, "circle", m_circle, -1);
|
48
|
+
rb_define_method(jm_Module, "line", m_line, -1);
|
49
|
+
rb_define_method(jm_Module, "rect", m_rect, -1);
|
50
|
+
rb_define_method(jm_Module, "pixel", m_pixel, -1);
|
51
|
+
rb_define_method(jm_Module, "fill", m_flood_fill, -1);
|
52
|
+
rb_define_method(jm_Module, "bezier", m_bezier, -1);
|
53
|
+
rb_define_method(jm_Module, "polyline", m_polyline, -1);
|
54
|
+
rb_define_method(jm_Module, "ngon", m_ngon, -1);
|
55
|
+
|
56
|
+
rb_define_method(jm_Module, "splice", m_splice, -1);
|
57
|
+
|
58
|
+
rb_define_method(jm_Module, "color", m_color, -1);
|
59
|
+
rb_define_method(jm_Module, "offset", m_offset, -1);
|
60
|
+
rb_define_method(jm_Module, "method_missing", m_missing, -1);
|
61
|
+
rb_define_method(jm_Module, "quad_cached?", m_quad_cached, 0);
|
62
|
+
|
63
|
+
rb_define_method(jm_Module, "each", m_each, -1);
|
64
|
+
|
65
|
+
/* needs to be updated, not yet done **/
|
66
|
+
/* rb_define_method(jm_Module, "bitmask", m_bitmask, -1); */
|
67
|
+
/* rb_define_method(jm_Module, "leftshift", m_lshift, -1); */
|
68
|
+
/* rb_define_method(jm_Module, "rightshift", m_rshift, -1); */
|
69
|
+
/* rb_define_method(jm_Module, "[]=", m_special_pixel, -1); */
|
70
|
+
|
71
|
+
rb_define_method(jm_Module, "dup", m_dup_image, 0);
|
72
|
+
rb_define_method(jm_Module, "clone", m_clone_image, 0);
|
73
|
+
rb_define_method(jm_Module, "to_blob", m_to_blob, 0);
|
74
|
+
rb_define_method(jm_Module, "force_sync", m_force_sync, 1);
|
75
|
+
rb_define_method(jm_Module, "set_options", m_user_set_options, 1);
|
76
|
+
rb_define_method(jm_Module, "get_options", m_get_options, 0);
|
77
|
+
rb_define_method(jm_Module, "delete_options", m_user_delete_options, 0);
|
78
|
+
|
79
|
+
rb_define_method(jm_Module, "refresh_cache", m_cache_refresh, 0);
|
80
|
+
|
81
|
+
/* a constant containing the sidelength of largest allowable quad */
|
82
|
+
rb_define_const(jm_Module, "TP_MAX_QUAD_SIZE", INT2FIX(max_quad_size() - 2));
|
83
|
+
|
84
|
+
/* singleton method for creating & removing macros */
|
85
|
+
rb_define_singleton_method(jm_Module, "create_macro", M_create_macro, 1);
|
86
|
+
rb_define_singleton_method(jm_Module, "remove_macro", M_remove_macro, 1);
|
87
|
+
rb_define_singleton_method(jm_Module, "refresh_cache_all", M_refresh_cache_all, 0);
|
88
|
+
/* rb_define_singleton_method(jm_Module, "create_blank_image", M_create_blank, 3); */
|
89
|
+
|
90
|
+
/** aliases; must be made on singleton class because we're using class methods **/
|
91
|
+
rb_define_method(jm_Module, "box", m_rect, -1);
|
92
|
+
rb_define_method(jm_Module, "colour", m_color, -1);
|
93
|
+
rb_define_method(jm_Module, "composite", m_splice, -1);
|
94
|
+
rb_define_method(jm_Module, "set_pixel", m_pixel, -1);
|
95
|
+
rb_define_method(jm_Module, "[]", m_getpixel, -1);
|
96
|
+
rb_define_method(jm_Module, "cache", m_cache_refresh, 0);
|
97
|
+
/** end of aliases **/
|
98
|
+
|
99
|
+
/** basic setup **/
|
100
|
+
|
101
|
+
/* seed the random number generator */
|
102
|
+
srand(time(NULL));
|
103
|
+
|
104
|
+
monkey_patch_gosu();
|
105
|
+
/** end basic setup **/
|
106
|
+
}
|
107
|
+
|
108
|
+
/** constructor for TPPoint class **/
|
109
|
+
static VALUE
|
110
|
+
m_init_TPPoint(int argc, VALUE * argv, VALUE self)
|
111
|
+
{
|
112
|
+
if(argc == 0) {
|
113
|
+
rb_iv_set(self, "@x", INT2FIX(0));
|
114
|
+
rb_iv_set(self, "@y", INT2FIX(0));
|
115
|
+
}
|
116
|
+
else if(argc == 2){
|
117
|
+
if(is_a_num(argv[0]) && is_a_num(argv[1])) {
|
118
|
+
rb_iv_set(self, "@x", argv[0]);
|
119
|
+
rb_iv_set(self, "@y", argv[1]);
|
120
|
+
}
|
121
|
+
else
|
122
|
+
rb_raise(rb_eArgError, "must provide two numbers");
|
123
|
+
}
|
124
|
+
else
|
125
|
+
rb_raise(rb_eArgError, "please provide x and y args only");
|
126
|
+
|
127
|
+
return Qnil;
|
128
|
+
|
129
|
+
}
|
130
|
+
/** end constructor for TPPoint **/
|
131
|
+
|
132
|
+
|
133
|
+
static VALUE
|
134
|
+
gosu_window_to_blob(VALUE self, VALUE rb_x, VALUE rb_y, VALUE rb_width, VALUE rb_height)
|
135
|
+
{
|
136
|
+
int x = FIX2INT(rb_x);
|
137
|
+
int y = FIX2INT(rb_y);
|
138
|
+
int width = FIX2INT(rb_width);
|
139
|
+
int height = FIX2INT(rb_height);
|
140
|
+
int window_height = FIX2INT(rb_funcall(self, rb_intern("height"), 0));
|
141
|
+
|
142
|
+
VALUE blob = rb_str_new(NULL, 4 * width * height);
|
143
|
+
|
144
|
+
rb_funcall(self, rb_intern("flush"), 0);
|
145
|
+
glFinish();
|
146
|
+
|
147
|
+
glReadPixels(x, y, width, window_height - y, GL_RGBA,
|
148
|
+
GL_UNSIGNED_BYTE, RSTRING_PTR(blob));
|
149
|
+
|
150
|
+
return blob;
|
151
|
+
}
|
152
|
+
|
153
|
+
static VALUE
|
154
|
+
gosu_window_to_texture(VALUE self, VALUE rb_tex_name, VALUE rb_xoffset, VALUE rb_yoffset,
|
155
|
+
VALUE rb_x, VALUE rb_y, VALUE rb_width, VALUE rb_height)
|
156
|
+
{
|
157
|
+
|
158
|
+
int tex_name = FIX2INT(rb_tex_name);
|
159
|
+
int xoffset = FIX2INT(rb_xoffset);
|
160
|
+
int yoffset = FIX2INT(rb_yoffset);
|
161
|
+
int x = FIX2INT(rb_x);
|
162
|
+
int y = FIX2INT(rb_y);
|
163
|
+
int width = FIX2INT(rb_width);
|
164
|
+
int height = FIX2INT(rb_height);
|
165
|
+
|
166
|
+
rb_funcall(self, rb_intern("flush"), 0);
|
167
|
+
glFinish();
|
168
|
+
|
169
|
+
glEnable(GL_TEXTURE_2D);
|
170
|
+
glBindTexture(GL_TEXTURE_2D, tex_name);
|
171
|
+
|
172
|
+
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, x, y, width, height);
|
173
|
+
glDisable(GL_TEXTURE_2D);
|
174
|
+
|
175
|
+
return Qnil;
|
176
|
+
}
|
177
|
+
|
178
|
+
|
179
|
+
static void
|
180
|
+
monkey_patch_gosu(void)
|
181
|
+
{
|
182
|
+
rb_define_method(gosu_window(), "to_blob", gosu_window_to_blob, 4);
|
183
|
+
rb_define_method(gosu_window(), "to_texture", gosu_window_to_texture, 7);
|
184
|
+
}
|
185
|
+
|
186
|
+
static VALUE
|
187
|
+
gosu_window(void)
|
188
|
+
{
|
189
|
+
static VALUE GosuWindow = 0;
|
190
|
+
|
191
|
+
if (!GosuWindow) {
|
192
|
+
VALUE Gosu = rb_const_get(rb_cObject, rb_intern("Gosu"));
|
193
|
+
GosuWindow = rb_const_get(Gosu, rb_intern("Window"));
|
194
|
+
}
|
195
|
+
|
196
|
+
return GosuWindow;
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|