texplay 0.4.3 → 0.4.4.pre

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 (71) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +225 -222
  3. data/README.markdown +48 -48
  4. data/Rakefile +16 -16
  5. data/examples/common.rb +18 -18
  6. data/examples/example_alpha_blend.rb +29 -29
  7. data/examples/example_bezier.rb +41 -41
  8. data/examples/example_blank.rb +37 -37
  9. data/examples/example_cache.rb +21 -21
  10. data/examples/example_color_control.rb +69 -69
  11. data/examples/example_color_transform.rb +62 -62
  12. data/examples/example_color_transform_circle.rb +34 -34
  13. data/examples/example_darken.rb +24 -24
  14. data/examples/example_dup.rb +73 -73
  15. data/examples/example_each.rb +39 -39
  16. data/examples/example_effect.rb +34 -34
  17. data/examples/example_fill.rb +43 -43
  18. data/examples/example_fill_old.rb +48 -48
  19. data/examples/example_fluent.rb +29 -29
  20. data/examples/example_font.rb +31 -31
  21. data/examples/example_hash_arguments.rb +46 -46
  22. data/examples/example_ippa.rb +23 -23
  23. data/examples/example_light.rb +75 -75
  24. data/examples/example_light_multiply.rb +18 -18
  25. data/examples/example_lsystem.rb +61 -61
  26. data/examples/example_melt.rb +25 -25
  27. data/examples/example_meyet.rb +62 -62
  28. data/examples/example_polyline.rb +42 -42
  29. data/examples/example_scale.rb +27 -27
  30. data/examples/example_select.rb +36 -36
  31. data/examples/example_select2.rb +25 -25
  32. data/examples/example_simple.rb +46 -46
  33. data/examples/example_splice.rb +26 -26
  34. data/examples/example_sync.rb +59 -59
  35. data/examples/example_tiles.rb +41 -41
  36. data/examples/example_trace.rb +22 -22
  37. data/examples/example_transparent.rb +28 -28
  38. data/examples/example_transparent2.rb +24 -24
  39. data/examples/example_transparent3.rb +20 -20
  40. data/examples/example_turtle.rb +39 -39
  41. data/examples/example_weird.rb +22 -22
  42. data/examples/example_window_render_to_image.rb +41 -41
  43. data/examples/example_window_to_blob.rb +35 -35
  44. data/examples/media/maria.png +0 -0
  45. data/examples/media/rose.bmp +0 -0
  46. data/ext/texplay/actions.c +1011 -1006
  47. data/ext/texplay/actions.h +60 -60
  48. data/ext/texplay/bindings.c +1130 -1125
  49. data/ext/texplay/bindings.h +46 -46
  50. data/ext/texplay/cache.c +123 -118
  51. data/ext/texplay/cache.h +24 -24
  52. data/ext/texplay/compat.h +21 -27
  53. data/ext/texplay/extconf.rb +38 -38
  54. data/ext/texplay/graphics_utils.c +1318 -1313
  55. data/ext/texplay/graphics_utils.h +22 -22
  56. data/ext/texplay/texplay.c +206 -201
  57. data/ext/texplay/texplay.h +153 -153
  58. data/ext/texplay/utils.c +896 -891
  59. data/ext/texplay/utils.h +153 -153
  60. data/lib/texplay-contrib.rb +147 -147
  61. data/lib/texplay.rb +347 -347
  62. data/lib/texplay/alone.rb +20 -20
  63. data/lib/texplay/c_function_docs.rb +178 -178
  64. data/lib/texplay/live.rb +84 -84
  65. data/lib/texplay/version.rb +3 -3
  66. data/live/live.rb +85 -85
  67. data/test/image_spec.rb +45 -45
  68. data/test/texplay_spec.rb +144 -144
  69. metadata +42 -52
  70. data/lib/texplay/1.8/texplay.so +0 -0
  71. data/lib/texplay/1.9/texplay.so +0 -0
@@ -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
@@ -1,118 +1,123 @@
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 <AvailabilityMacros.h>
7
+ #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9
8
+ # include <GLUT/glut.h>
9
+ #else
10
+ # include <GL/glut.h>
11
+ #endif
12
+ #else
13
+ # include <GL/glut.h>
14
+ #endif
15
+
16
+ #include "cache.h"
17
+ #include "texplay.h"
18
+
19
+ typedef struct {
20
+ int len;
21
+ cache_entry entry[CACHE_SIZE];
22
+ } cache_t;
23
+
24
+ /* var has internal linkage, static duration */
25
+ /* contains cache data */
26
+ static cache_t cache = {0};
27
+
28
+ /* create a new cache entry */
29
+ cache_entry*
30
+ cache_create_entry(int tname) {
31
+ float * new_array;
32
+ int sidelength, new_element = cache.len;
33
+
34
+ if(cache.len >= CACHE_SIZE) { rb_raise(rb_eRuntimeError, "cache is full! increase CACHE_SIZE"); }
35
+
36
+ /* opengl initialization code */
37
+ glEnable(GL_TEXTURE_2D);
38
+ glBindTexture(GL_TEXTURE_2D, tname);
39
+
40
+ /* get length of a side, since square texture */
41
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &sidelength);
42
+
43
+ /* initialize texture data array, mult. by 4 because {rgba} */
44
+ new_array = malloc(sidelength * sidelength * 4 * sizeof(float));
45
+
46
+ /* get texture data from video memory */
47
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT,(void*)(new_array));
48
+
49
+ /* save texture data in the cache */
50
+ cache.entry[new_element].tname = tname;
51
+ cache.entry[new_element].sidelength = sidelength;
52
+ cache.entry[new_element].tdata = new_array;
53
+
54
+ /* update size of cache */
55
+ cache.len++;
56
+
57
+ glDisable(GL_TEXTURE_2D);
58
+
59
+ return &cache.entry[new_element];
60
+ }
61
+
62
+ /* return the entry if it exists, otherwise return NULL */
63
+ cache_entry*
64
+ find_in_cache(int tname) {
65
+ /* check if entry exists in cache */
66
+ int index;
67
+ for(index = 0; index < cache.len; index++)
68
+ if(cache.entry[index].tname == tname)
69
+ return &cache.entry[index];
70
+
71
+
72
+ return NULL;
73
+ }
74
+
75
+ /* if the entry doesn't exist then create it and return it.
76
+ otherwise just return it */
77
+ cache_entry*
78
+ find_or_create_cache_entry(int tname) {
79
+ cache_entry * entry;
80
+
81
+ if((entry=find_in_cache(tname)))
82
+ return entry;
83
+ else
84
+ return cache_create_entry(tname);
85
+ }
86
+
87
+ /* refresh the cache for all quads */
88
+ void
89
+ cache_refresh_all(void) {
90
+ float * tdata;
91
+ int tname, index;
92
+
93
+ /* opengl initialization code */
94
+ glEnable(GL_TEXTURE_2D);
95
+
96
+ for(index = 0; index < cache.len; index++) {
97
+ tdata = cache.entry[index].tdata;
98
+ tname = cache.entry[index].tname;
99
+
100
+ glBindTexture(GL_TEXTURE_2D, tname);
101
+
102
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, (void*)(tdata));
103
+ }
104
+
105
+ glDisable(GL_TEXTURE_2D);
106
+ }
107
+
108
+ /* refresh the cache for a specific quad */
109
+ void
110
+ cache_refresh_entry(int tname) {
111
+ cache_entry * entry;
112
+
113
+ entry = find_in_cache(tname);
114
+
115
+ /* opengl initialization code */
116
+ glEnable(GL_TEXTURE_2D);
117
+ glBindTexture(GL_TEXTURE_2D, entry->tname);
118
+
119
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, (void*)(entry->tdata));
120
+
121
+ glDisable(GL_TEXTURE_2D);
122
+ }
123
+
@@ -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
@@ -1,27 +1,21 @@
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
+ /* macros for backwards compatibility with 1.8 */
9
+ #ifndef RCLASS_M_TBL
10
+ # define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
11
+ #endif
12
+
13
+ #ifndef RCLASS_SUPER
14
+ # define RCLASS_SUPER(c) (RCLASS(c)->super)
15
+ #endif
16
+
17
+ #ifndef RCLASS_IV_TBL
18
+ # define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
19
+ #endif
20
+
21
+ #endif
@@ -1,38 +1,38 @@
1
- require 'mkmf'
2
-
3
- name = 'texplay/texplay'
4
-
5
- dir_config name
6
-
7
-
8
- # linux
9
- if RUBY_PLATFORM =~ /linux/
10
- exit unless have_library("glut")
11
- exit unless have_library("GL")
12
-
13
- # macosx
14
- elsif RUBY_PLATFORM =~ /darwin/
15
- $LDFLAGS += " -framework GLUT"
16
- $CFLAGS += " -I/System/Library/Frameworks/GLUT.framework/Headers"
17
-
18
- # windows
19
- else
20
- freeglut_path = File.expand_path "vendor/freeglut", File.dirname(__FILE__)
21
-
22
- $CFLAGS << " -I#{File.join freeglut_path, "include"}"
23
-
24
- exit unless find_library "freeglut_static", 'main', File.join(freeglut_path, "lib")
25
- exit unless have_library "opengl32"
26
-
27
- end
28
-
29
- # Stop getting annoying warnings for valid C99 code.
30
- $warnflags.gsub!('-Wdeclaration-after-statement', '') if $warnflags
31
-
32
- # 1.9 compatibility
33
- $CFLAGS += " -DRUBY_19" if RUBY_VERSION =~ /^1\.9/
34
-
35
- # let's use c99
36
- $CFLAGS += " -std=c99"
37
-
38
- create_makefile name
1
+ require 'mkmf'
2
+
3
+ name = 'texplay/texplay'
4
+
5
+ dir_config name
6
+
7
+
8
+ # linux
9
+ if RUBY_PLATFORM =~ /linux/
10
+ exit unless have_library("glut")
11
+ exit unless have_library("GL")
12
+
13
+ # macosx
14
+ elsif RUBY_PLATFORM =~ /darwin/
15
+ $LDFLAGS += " -framework GLUT"
16
+ $CFLAGS += " -I/System/Library/Frameworks/GLUT.framework/Headers"
17
+
18
+ # windows
19
+ else
20
+ freeglut_path = File.expand_path "vendor/freeglut", File.dirname(__FILE__)
21
+
22
+ $CFLAGS << " -I#{File.join freeglut_path, "include"}"
23
+
24
+ exit unless find_library "freeglut_static", 'main', File.join(freeglut_path, "lib")
25
+ exit unless have_library "opengl32"
26
+
27
+ end
28
+
29
+ # Stop getting annoying warnings for valid C99 code.
30
+ $warnflags.gsub!('-Wdeclaration-after-statement', '') if $warnflags
31
+
32
+ # 1.9 compatibility
33
+ $CFLAGS += " -DRUBY_19" if RUBY_VERSION =~ /^1\.9/
34
+
35
+ # let's use c99
36
+ $CFLAGS += " -std=c99"
37
+
38
+ create_makefile name