texplay 0.2.800 → 0.2.900

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.
Files changed (51) hide show
  1. data/CHANGELOG +138 -119
  2. data/README.markdown +43 -41
  3. data/Rakefile +68 -68
  4. data/examples/common.rb +8 -8
  5. data/examples/example_alpha_blend.rb +31 -31
  6. data/examples/example_bezier.rb +42 -42
  7. data/examples/example_color_control.rb +69 -69
  8. data/examples/example_color_transform.rb +64 -67
  9. data/examples/example_color_transform_circle.rb +65 -0
  10. data/examples/example_dup.rb +75 -75
  11. data/examples/example_each.rb +42 -42
  12. data/examples/example_effect.rb +35 -35
  13. data/examples/example_fill.rb +44 -44
  14. data/examples/example_fill_old.rb +49 -49
  15. data/examples/example_fluent.rb +31 -31
  16. data/examples/example_gen_eval.rb +34 -34
  17. data/examples/example_hash_arguments.rb +47 -47
  18. data/examples/example_light.rb +77 -0
  19. data/examples/example_lsystem.rb +61 -61
  20. data/examples/example_melt.rb +27 -27
  21. data/examples/example_meyet.rb +64 -0
  22. data/examples/example_polyline.rb +43 -43
  23. data/examples/example_scale.rb +29 -29
  24. data/examples/example_simple.rb +48 -38
  25. data/examples/example_sync.rb +60 -60
  26. data/examples/example_trace.rb +1 -1
  27. data/examples/example_turtle.rb +40 -40
  28. data/examples/example_weird.rb +3 -1
  29. data/examples/media/Thumbs.db +0 -0
  30. data/ext/texplay/actions.c +999 -1001
  31. data/ext/texplay/actions.h +60 -60
  32. data/ext/texplay/bindings.c +1162 -1149
  33. data/ext/texplay/bindings.h +46 -46
  34. data/ext/texplay/cache.c +118 -118
  35. data/ext/texplay/cache.h +24 -24
  36. data/ext/texplay/compat.h +27 -27
  37. data/ext/texplay/extconf.rb +28 -28
  38. data/ext/texplay/gen_eval.c +211 -211
  39. data/ext/texplay/gen_eval.h +20 -20
  40. data/ext/texplay/graphics_utils.c +188 -63
  41. data/ext/texplay/graphics_utils.h +0 -1
  42. data/ext/texplay/object2module.c +171 -171
  43. data/ext/texplay/object2module.h +11 -11
  44. data/ext/texplay/texplay.c +169 -169
  45. data/ext/texplay/texplay.h +147 -130
  46. data/ext/texplay/utils.c +816 -752
  47. data/ext/texplay/utils.h +151 -145
  48. data/lib/texplay-contrib.rb +171 -171
  49. data/lib/texplay.rb +162 -137
  50. data/lib/texplay/version.rb +1 -1
  51. metadata +9 -5
@@ -1,46 +1,46 @@
1
- #ifndef GUARD_BINDINGS_H
2
- #define GUARD_BINDINGS_H
3
-
4
- /* class methods */
5
- VALUE M_create_macro(VALUE self , VALUE method_name);
6
- VALUE M_remove_macro(VALUE self, VALUE method_name);
7
- VALUE M_refresh_cache_all(VALUE self);
8
- VALUE M_create_blank(VALUE self, VALUE window, VALUE width, VALUE height);
9
-
10
- /* instance methods */
11
- VALUE m_paint(int argc, VALUE * argv, VALUE self);
12
- VALUE m_getpixel(int argc, VALUE * argv, VALUE self);
13
- VALUE m_circle(int argc, VALUE * argv, VALUE self);
14
- VALUE m_line(int argc, VALUE * argv, VALUE self);
15
- VALUE m_rect(int argc, VALUE * argv, VALUE self);
16
- VALUE m_pixel(int argc, VALUE * argv, VALUE self);
17
- VALUE m_flood_fill(int argc, VALUE * argv, VALUE self);
18
- VALUE m_bezier(int argc, VALUE * argv, VALUE self);
19
- VALUE m_polyline(int argc, VALUE * argv, VALUE self);
20
- VALUE m_ngon(int argc, VALUE * argv, VALUE self);
21
- VALUE m_special_pixel(int argc, VALUE * argv, VALUE self);
22
- VALUE m_splice(int argc, VALUE * argv, VALUE self);
23
- VALUE m_clear(int argc, VALUE * argv, VALUE self);
24
- VALUE m_offset(int argc, VALUE * argv, VALUE self);
25
- VALUE m_color(int argc, VALUE * argv, VALUE self);
26
- VALUE m_missing(int argc, VALUE * argv, VALUE self);
27
- VALUE m_bitmask(int argc, VALUE * argv, VALUE self);
28
- VALUE m_lshift(int argc, VALUE * argv, VALUE self);
29
- VALUE m_rshift(int argc, VALUE * argv, VALUE self);
30
-
31
- VALUE m_each(int argc, VALUE * argv, VALUE self);
32
-
33
- VALUE m_quad_cached(VALUE self);
34
- VALUE m_cache_refresh(VALUE self);
35
-
36
- VALUE m_user_set_options(VALUE self, VALUE options);
37
- VALUE m_user_delete_options(VALUE self);
38
- VALUE m_get_options(VALUE self);
39
- VALUE m_force_sync(VALUE self, VALUE ary);
40
-
41
- VALUE m_dup_image(VALUE self);
42
- VALUE m_clone_image(VALUE self);
43
-
44
- VALUE m_to_blob(VALUE self);
45
-
46
- #endif
1
+ #ifndef GUARD_BINDINGS_H
2
+ #define GUARD_BINDINGS_H
3
+
4
+ /* class methods */
5
+ VALUE M_create_macro(VALUE self , VALUE method_name);
6
+ VALUE M_remove_macro(VALUE self, VALUE method_name);
7
+ VALUE M_refresh_cache_all(VALUE self);
8
+ VALUE M_create_blank(VALUE self, VALUE window, VALUE width, VALUE height);
9
+
10
+ /* instance methods */
11
+ VALUE m_paint(int argc, VALUE * argv, VALUE self);
12
+ VALUE m_getpixel(int argc, VALUE * argv, VALUE self);
13
+ VALUE m_circle(int argc, VALUE * argv, VALUE self);
14
+ VALUE m_line(int argc, VALUE * argv, VALUE self);
15
+ VALUE m_rect(int argc, VALUE * argv, VALUE self);
16
+ VALUE m_pixel(int argc, VALUE * argv, VALUE self);
17
+ VALUE m_flood_fill(int argc, VALUE * argv, VALUE self);
18
+ VALUE m_bezier(int argc, VALUE * argv, VALUE self);
19
+ VALUE m_polyline(int argc, VALUE * argv, VALUE self);
20
+ VALUE m_ngon(int argc, VALUE * argv, VALUE self);
21
+ VALUE m_special_pixel(int argc, VALUE * argv, VALUE self);
22
+ VALUE m_splice(int argc, VALUE * argv, VALUE self);
23
+ VALUE m_clear(int argc, VALUE * argv, VALUE self);
24
+ VALUE m_offset(int argc, VALUE * argv, VALUE self);
25
+ VALUE m_color(int argc, VALUE * argv, VALUE self);
26
+ VALUE m_missing(int argc, VALUE * argv, VALUE self);
27
+ VALUE m_bitmask(int argc, VALUE * argv, VALUE self);
28
+ VALUE m_lshift(int argc, VALUE * argv, VALUE self);
29
+ VALUE m_rshift(int argc, VALUE * argv, VALUE self);
30
+
31
+ VALUE m_each(int argc, VALUE * argv, VALUE self);
32
+
33
+ VALUE m_quad_cached(VALUE self);
34
+ VALUE m_cache_refresh(VALUE self);
35
+
36
+ VALUE m_user_set_options(VALUE self, VALUE options);
37
+ VALUE m_user_delete_options(VALUE self);
38
+ VALUE m_get_options(VALUE self);
39
+ VALUE m_force_sync(VALUE self, VALUE ary);
40
+
41
+ VALUE m_dup_image(VALUE self);
42
+ VALUE m_clone_image(VALUE self);
43
+
44
+ VALUE m_to_blob(VALUE self);
45
+
46
+ #endif
data/ext/texplay/cache.c CHANGED
@@ -1,118 +1,118 @@
1
- /* cache.c */
2
-
3
- #include <ruby.h>
4
-
5
- #ifdef __APPLE__
6
- #include <glut.h>
7
- #else
8
- #include <GL/glut.h>
9
- #endif
10
-
11
- #include "cache.h"
12
- #include "texplay.h"
13
-
14
- typedef struct {
15
- int len;
16
- cache_entry entry[CACHE_SIZE];
17
- } cache_t;
18
-
19
- /* var has internal linkage, static duration */
20
- /* contains cache data */
21
- static cache_t cache = {0};
22
-
23
- /* create a new cache entry */
24
- cache_entry*
25
- cache_create_entry(int tname) {
26
- float * new_array;
27
- int sidelength, new_element = cache.len;
28
-
29
- if(cache.len >= CACHE_SIZE) { rb_raise(rb_eRuntimeError, "cache is full! increase CACHE_SIZE"); }
30
-
31
- /* opengl initialization code */
32
- glEnable(GL_TEXTURE_2D);
33
- glBindTexture(GL_TEXTURE_2D, tname);
34
-
35
- /* get length of a side, since square texture */
36
- glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &sidelength);
37
-
38
- /* initialize texture data array, mult. by 4 because {rgba} */
39
- new_array = malloc(sidelength * sidelength * 4 * sizeof(float));
40
-
41
- /* get texture data from video memory */
42
- glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT,(void*)(new_array));
43
-
44
- /* save texture data in the cache */
45
- cache.entry[new_element].tname = tname;
46
- cache.entry[new_element].sidelength = sidelength;
47
- cache.entry[new_element].tdata = new_array;
48
-
49
- /* update size of cache */
50
- cache.len++;
51
-
52
- glDisable(GL_TEXTURE_2D);
53
-
54
- return &cache.entry[new_element];
55
- }
56
-
57
- /* return the entry if it exists, otherwise return NULL */
58
- cache_entry*
59
- find_in_cache(int tname) {
60
- /* check if entry exists in cache */
61
- int index;
62
- for(index = 0; index < cache.len; index++)
63
- if(cache.entry[index].tname == tname)
64
- return &cache.entry[index];
65
-
66
-
67
- return NULL;
68
- }
69
-
70
- /* if the entry doesn't exist then create it and return it.
71
- otherwise just return it */
72
- cache_entry*
73
- find_or_create_cache_entry(int tname) {
74
- cache_entry * entry;
75
-
76
- if((entry=find_in_cache(tname)))
77
- return entry;
78
- else
79
- return cache_create_entry(tname);
80
- }
81
-
82
- /* refresh the cache for all quads */
83
- void
84
- cache_refresh_all(void) {
85
- float * tdata;
86
- int tname, index;
87
-
88
- /* opengl initialization code */
89
- glEnable(GL_TEXTURE_2D);
90
-
91
- for(index = 0; index < cache.len; index++) {
92
- tdata = cache.entry[index].tdata;
93
- tname = cache.entry[index].tname;
94
-
95
- glBindTexture(GL_TEXTURE_2D, tname);
96
-
97
- glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, (void*)(tdata));
98
- }
99
-
100
- glDisable(GL_TEXTURE_2D);
101
- }
102
-
103
- /* refresh the cache for a specific quad */
104
- void
105
- cache_refresh_entry(int tname) {
106
- cache_entry * entry;
107
-
108
- entry = find_in_cache(tname);
109
-
110
- /* opengl initialization code */
111
- glEnable(GL_TEXTURE_2D);
112
- glBindTexture(GL_TEXTURE_2D, entry->tname);
113
-
114
- glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, (void*)(entry->tdata));
115
-
116
- glDisable(GL_TEXTURE_2D);
117
- }
118
-
1
+ /* cache.c */
2
+
3
+ #include <ruby.h>
4
+
5
+ #ifdef __APPLE__
6
+ #include <glut.h>
7
+ #else
8
+ #include <GL/glut.h>
9
+ #endif
10
+
11
+ #include "cache.h"
12
+ #include "texplay.h"
13
+
14
+ typedef struct {
15
+ int len;
16
+ cache_entry entry[CACHE_SIZE];
17
+ } cache_t;
18
+
19
+ /* var has internal linkage, static duration */
20
+ /* contains cache data */
21
+ static cache_t cache = {0};
22
+
23
+ /* create a new cache entry */
24
+ cache_entry*
25
+ cache_create_entry(int tname) {
26
+ float * new_array;
27
+ int sidelength, new_element = cache.len;
28
+
29
+ if(cache.len >= CACHE_SIZE) { rb_raise(rb_eRuntimeError, "cache is full! increase CACHE_SIZE"); }
30
+
31
+ /* opengl initialization code */
32
+ glEnable(GL_TEXTURE_2D);
33
+ glBindTexture(GL_TEXTURE_2D, tname);
34
+
35
+ /* get length of a side, since square texture */
36
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &sidelength);
37
+
38
+ /* initialize texture data array, mult. by 4 because {rgba} */
39
+ new_array = malloc(sidelength * sidelength * 4 * sizeof(float));
40
+
41
+ /* get texture data from video memory */
42
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT,(void*)(new_array));
43
+
44
+ /* save texture data in the cache */
45
+ cache.entry[new_element].tname = tname;
46
+ cache.entry[new_element].sidelength = sidelength;
47
+ cache.entry[new_element].tdata = new_array;
48
+
49
+ /* update size of cache */
50
+ cache.len++;
51
+
52
+ glDisable(GL_TEXTURE_2D);
53
+
54
+ return &cache.entry[new_element];
55
+ }
56
+
57
+ /* return the entry if it exists, otherwise return NULL */
58
+ cache_entry*
59
+ find_in_cache(int tname) {
60
+ /* check if entry exists in cache */
61
+ int index;
62
+ for(index = 0; index < cache.len; index++)
63
+ if(cache.entry[index].tname == tname)
64
+ return &cache.entry[index];
65
+
66
+
67
+ return NULL;
68
+ }
69
+
70
+ /* if the entry doesn't exist then create it and return it.
71
+ otherwise just return it */
72
+ cache_entry*
73
+ find_or_create_cache_entry(int tname) {
74
+ cache_entry * entry;
75
+
76
+ if((entry=find_in_cache(tname)))
77
+ return entry;
78
+ else
79
+ return cache_create_entry(tname);
80
+ }
81
+
82
+ /* refresh the cache for all quads */
83
+ void
84
+ cache_refresh_all(void) {
85
+ float * tdata;
86
+ int tname, index;
87
+
88
+ /* opengl initialization code */
89
+ glEnable(GL_TEXTURE_2D);
90
+
91
+ for(index = 0; index < cache.len; index++) {
92
+ tdata = cache.entry[index].tdata;
93
+ tname = cache.entry[index].tname;
94
+
95
+ glBindTexture(GL_TEXTURE_2D, tname);
96
+
97
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, (void*)(tdata));
98
+ }
99
+
100
+ glDisable(GL_TEXTURE_2D);
101
+ }
102
+
103
+ /* refresh the cache for a specific quad */
104
+ void
105
+ cache_refresh_entry(int tname) {
106
+ cache_entry * entry;
107
+
108
+ entry = find_in_cache(tname);
109
+
110
+ /* opengl initialization code */
111
+ glEnable(GL_TEXTURE_2D);
112
+ glBindTexture(GL_TEXTURE_2D, entry->tname);
113
+
114
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, (void*)(entry->tdata));
115
+
116
+ glDisable(GL_TEXTURE_2D);
117
+ }
118
+
data/ext/texplay/cache.h CHANGED
@@ -1,24 +1,24 @@
1
- /* cache.h */
2
- /* see cache.c for annotations */
3
-
4
- #ifndef GUARD_CACHE_H
5
- #define GUARD_CACHE_H
6
-
7
- /* defines */
8
- #define CACHE_SIZE 10000
9
-
10
- /* data types */
11
- typedef struct {
12
- int tname;
13
- int sidelength;
14
- float * tdata;
15
- } cache_entry;
16
-
17
- /* functions */
18
- void cache_refresh_all(void);
19
- void cache_refresh_entry(int tname);
20
- cache_entry * cache_create_entry(int texture_name);
21
- cache_entry * find_in_cache(int texture_name);
22
- cache_entry * find_or_create_cache_entry(int texture_name);
23
-
24
- #endif
1
+ /* cache.h */
2
+ /* see cache.c for annotations */
3
+
4
+ #ifndef GUARD_CACHE_H
5
+ #define GUARD_CACHE_H
6
+
7
+ /* defines */
8
+ #define CACHE_SIZE 10000
9
+
10
+ /* data types */
11
+ typedef struct {
12
+ int tname;
13
+ int sidelength;
14
+ float * tdata;
15
+ } cache_entry;
16
+
17
+ /* functions */
18
+ void cache_refresh_all(void);
19
+ void cache_refresh_entry(int tname);
20
+ cache_entry * cache_create_entry(int texture_name);
21
+ cache_entry * find_in_cache(int texture_name);
22
+ cache_entry * find_or_create_cache_entry(int texture_name);
23
+
24
+ #endif
data/ext/texplay/compat.h CHANGED
@@ -1,27 +1,27 @@
1
- /* contains basic macros to facilitate ruby 1.8 and ruby 1.9 compatibility */
2
-
3
- #ifndef GUARD_COMPAT_H
4
- #define GUARD_COMPAT_H
5
-
6
- #include <ruby.h>
7
-
8
- /* this is the test we use to identify ruby 1.9.1 */
9
-
10
- /* commenting out this test because it doesn't seem to work in 1.8.7 */
11
- /*
12
- #ifdef RCLASS_M_TBL
13
- # define RUBY_19
14
- #endif
15
- */
16
-
17
- /* macros for backwards compatibility with 1.8 */
18
- #ifndef RUBY_19
19
- # define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
20
- # define RCLASS_SUPER(c) (RCLASS(c)->super)
21
- # define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
22
- #endif
23
-
24
- /* a useful macro. cannot use ordinary CLASS_OF as it does not return an lvalue */
25
- #define KLASS_OF(c) (RBASIC(c)->klass)
26
-
27
- #endif
1
+ /* contains basic macros to facilitate ruby 1.8 and ruby 1.9 compatibility */
2
+
3
+ #ifndef GUARD_COMPAT_H
4
+ #define GUARD_COMPAT_H
5
+
6
+ #include <ruby.h>
7
+
8
+ /* this is the test we use to identify ruby 1.9.1 */
9
+
10
+ /* commenting out this test because it doesn't seem to work in 1.8.7 */
11
+ /*
12
+ #ifdef RCLASS_M_TBL
13
+ # define RUBY_19
14
+ #endif
15
+ */
16
+
17
+ /* macros for backwards compatibility with 1.8 */
18
+ #ifndef RUBY_19
19
+ # define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
20
+ # define RCLASS_SUPER(c) (RCLASS(c)->super)
21
+ # define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
22
+ #endif
23
+
24
+ /* a useful macro. cannot use ordinary CLASS_OF as it does not return an lvalue */
25
+ #define KLASS_OF(c) (RBASIC(c)->klass)
26
+
27
+ #endif
@@ -1,28 +1,28 @@
1
- require 'mkmf'
2
-
3
-
4
- # linux
5
- if RUBY_PLATFORM =~ /linux/ then
6
- exit unless have_library("glut")
7
- exit unless have_library("GL")
8
-
9
- # macosx
10
- elsif RUBY_PLATFORM =~ /darwin/
11
- $LDFLAGS += " -framework GLUT"
12
- $CFLAGS += " -I/System/Library/Frameworks/GLUT.framework/Headers"
13
-
14
- # windows
15
- else
16
-
17
- exit unless have_library("freeglut_static")
18
- exit unless have_library("opengl32")
19
-
20
- end
21
-
22
- # 1.9 compatibility
23
- $CFLAGS += " -DRUBY_19" if RUBY_VERSION =~ /1.9/
24
-
25
- # let's use c99
26
- $CFLAGS += " -std=c99"
27
-
28
- create_makefile('texplay')
1
+ require 'mkmf'
2
+
3
+
4
+ # linux
5
+ if RUBY_PLATFORM =~ /linux/ then
6
+ exit unless have_library("glut")
7
+ exit unless have_library("GL")
8
+
9
+ # macosx
10
+ elsif RUBY_PLATFORM =~ /darwin/
11
+ $LDFLAGS += " -framework GLUT"
12
+ $CFLAGS += " -I/System/Library/Frameworks/GLUT.framework/Headers"
13
+
14
+ # windows
15
+ else
16
+
17
+ exit unless have_library("freeglut_static")
18
+ exit unless have_library("opengl32")
19
+
20
+ end
21
+
22
+ # 1.9 compatibility
23
+ $CFLAGS += " -DRUBY_19" if RUBY_VERSION =~ /1.9/
24
+
25
+ # let's use c99
26
+ $CFLAGS += " -std=c99"
27
+
28
+ create_makefile('texplay')