texplay 0.3.5 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/CHANGELOG +222 -222
  2. data/README.markdown +43 -43
  3. data/Rakefile +3 -99
  4. data/examples/common.rb +18 -18
  5. data/examples/example_alpha_blend.rb +29 -29
  6. data/examples/example_bezier.rb +41 -41
  7. data/examples/example_blank.rb +37 -37
  8. data/examples/example_cache.rb +21 -21
  9. data/examples/example_color_control.rb +69 -69
  10. data/examples/example_color_transform.rb +62 -62
  11. data/examples/example_color_transform_circle.rb +34 -34
  12. data/examples/example_darken.rb +24 -24
  13. data/examples/example_dup.rb +73 -73
  14. data/examples/example_each.rb +39 -39
  15. data/examples/example_effect.rb +34 -34
  16. data/examples/example_fill.rb +43 -43
  17. data/examples/example_fill_old.rb +48 -48
  18. data/examples/example_fluent.rb +29 -29
  19. data/examples/example_font.rb +31 -31
  20. data/examples/example_hash_arguments.rb +46 -46
  21. data/examples/example_ippa.rb +23 -23
  22. data/examples/example_light.rb +75 -75
  23. data/examples/example_light_multiply.rb +18 -18
  24. data/examples/example_lsystem.rb +61 -61
  25. data/examples/example_melt.rb +25 -25
  26. data/examples/example_meyet.rb +62 -62
  27. data/examples/example_polyline.rb +42 -42
  28. data/examples/example_scale.rb +27 -27
  29. data/examples/example_select.rb +36 -36
  30. data/examples/example_select2.rb +25 -25
  31. data/examples/example_simple.rb +46 -46
  32. data/examples/example_splice.rb +26 -26
  33. data/examples/example_sync.rb +59 -59
  34. data/examples/example_tiles.rb +41 -41
  35. data/examples/example_trace.rb +22 -22
  36. data/examples/example_transparent.rb +28 -28
  37. data/examples/example_transparent2.rb +24 -24
  38. data/examples/example_transparent3.rb +20 -20
  39. data/examples/example_turtle.rb +39 -39
  40. data/examples/example_weird.rb +22 -22
  41. data/examples/example_window_render_to_image.rb +41 -41
  42. data/examples/example_window_to_blob.rb +35 -35
  43. data/examples/media/maria.png +0 -0
  44. data/examples/media/rose.bmp +0 -0
  45. data/ext/texplay/actions.c +1006 -1006
  46. data/ext/texplay/actions.h +60 -60
  47. data/ext/texplay/bindings.c +1125 -1186
  48. data/ext/texplay/bindings.h +46 -46
  49. data/ext/texplay/cache.c +118 -118
  50. data/ext/texplay/cache.h +24 -24
  51. data/ext/texplay/compat.h +27 -27
  52. data/ext/texplay/extconf.rb +28 -28
  53. data/ext/texplay/graphics_utils.c +1313 -1313
  54. data/ext/texplay/graphics_utils.h +22 -22
  55. data/ext/texplay/texplay.c +201 -216
  56. data/ext/texplay/texplay.h +153 -153
  57. data/ext/texplay/utils.c +891 -891
  58. data/ext/texplay/utils.h +153 -153
  59. data/lib/texplay-contrib.rb +147 -164
  60. data/lib/texplay.rb +341 -356
  61. data/lib/texplay/alone.rb +20 -20
  62. data/lib/texplay/c_function_docs.rb +178 -190
  63. data/lib/texplay/live.rb +84 -84
  64. data/lib/texplay/version.rb +3 -3
  65. data/live/live.rb +85 -85
  66. data/test/image_spec.rb +45 -45
  67. data/test/texplay_spec.rb +144 -141
  68. metadata +54 -42
  69. data/examples/example_gen_eval.rb +0 -32
  70. data/ext/texplay/gen_eval.c +0 -211
  71. data/ext/texplay/gen_eval.h +0 -20
  72. data/ext/texplay/object2module.c +0 -171
  73. data/ext/texplay/object2module.h +0 -11
@@ -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/texplay')