texplay 0.2.983pre1 → 0.2.983pre2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,6 +1,12 @@
1
+ *1/10/10
2
+ version 0.2.983pre2
3
+ * added Window#to_texture(...) seems to be broken! releasing pre2 so
4
+ * others can test it :)
5
+
1
6
  *27/9/10
2
7
  version 0.2.983pre1
3
8
  * added Window#to_blob(x,y,width,height), grab a screenshot region
9
+
4
10
  *24/9/10
5
11
  version 0.2.982pre1
6
12
  * added :default drawing mode (equivalent to :mode => nil)
@@ -5,7 +5,7 @@
5
5
  INSTRUCTIONS
6
6
  ============
7
7
 
8
- **TexPlay version 0.2.983pre1**
8
+ **TexPlay version 0.2.983pre2**
9
9
 
10
10
  [Read The Documentation](http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/)
11
11
 
@@ -1,6 +1,5 @@
1
1
  $LOAD_PATH.push(File.dirname(__FILE__) + '/../lib/')
2
2
 
3
- require 'rubygems'
4
3
  require 'texplay'
5
4
 
6
5
  module Common
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'common'
3
2
  require 'gosu'
4
3
  require 'texplay'
@@ -0,0 +1,55 @@
1
+ require 'common'
2
+ require 'gosu'
3
+ require 'texplay'
4
+
5
+
6
+ class W < Gosu::Window
7
+
8
+ def render_to_texture(image, x, y)
9
+ tex_name = image.gl_tex_info.tex_name
10
+ xoffset = image.gl_tex_info.left * Gosu::MAX_TEXTURE_SIZE * Gosu::MAX_TEXTURE_SIZE
11
+ yoffset = image.gl_tex_info.top * Gosu::MAX_TEXTURE_SIZE
12
+ width = image.width
13
+ height = image.height
14
+
15
+ self.to_texture(tex_name, xoffset, yoffset, x, y, width, height)
16
+ end
17
+
18
+ def initialize
19
+ super(500, 500, false, 20)
20
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/maria.png")
21
+ @img2 = TexPlay.create_image(self, 100, 100, :color => Gosu::Color::RED)
22
+
23
+ end
24
+
25
+ def update
26
+
27
+ end
28
+
29
+ def draw
30
+ @img.draw 0, 0,1
31
+ @img2.draw rand(100), rand(100),1
32
+ @img3.draw rand(300), rand(300), 1 if @img3
33
+
34
+ if button_down?(Gosu::KbEscape)
35
+ # self.flush
36
+ @img3 = TexPlay.create_image(self, Gosu::MAX_TEXTURE_SIZE - 2, Gosu::MAX_TEXTURE_SIZE - 2, :color => :purple)
37
+
38
+ render_to_texture(@img2, 0, self.height)
39
+
40
+
41
+
42
+ # if @blob
43
+ # @img3 = TexPlay.from_blob(self, @blob,50, 50 )
44
+ # end
45
+ end
46
+
47
+ 500000.times {}
48
+ end
49
+
50
+ end
51
+
52
+
53
+ w = W.new
54
+ w.show
55
+
@@ -141,29 +141,56 @@ m_init_TPPoint(int argc, VALUE * argv, VALUE self)
141
141
 
142
142
 
143
143
  static VALUE
144
- gosu_window_to_blob(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
144
+ gosu_window_to_blob(VALUE self, VALUE rb_x, VALUE rb_y, VALUE rb_width, VALUE rb_height)
145
145
  {
146
- int rb_x = FIX2INT(x);
147
- int rb_y = FIX2INT(y);
148
- int rb_width = FIX2INT(width);
149
- int rb_height = FIX2INT(height);
146
+ int x = FIX2INT(rb_x);
147
+ int y = FIX2INT(rb_y);
148
+ int width = FIX2INT(rb_width);
149
+ int height = FIX2INT(rb_height);
150
150
  int window_height = FIX2INT(rb_funcall(self, rb_intern("height"), 0));
151
151
 
152
- VALUE blob = rb_str_new(NULL, 4 * rb_width * rb_height);
152
+ VALUE blob = rb_str_new(NULL, 4 * width * height);
153
153
 
154
- glFinish();
155
154
  rb_funcall(self, rb_intern("flush"), 0);
155
+ glFinish();
156
156
 
157
- glReadPixels(rb_x, rb_y, rb_width, rb_height, GL_RGBA,
157
+ glReadPixels(x, y, width, window_height - y, GL_RGBA,
158
158
  GL_UNSIGNED_BYTE, RSTRING_PTR(blob));
159
159
 
160
160
  return blob;
161
161
  }
162
162
 
163
+ static VALUE
164
+ gosu_window_to_texture(VALUE self, VALUE rb_tex_name, VALUE rb_xoffset, VALUE rb_yoffset,
165
+ VALUE rb_x, VALUE rb_y, VALUE rb_width, VALUE rb_height)
166
+ {
167
+
168
+ int tex_name = FIX2INT(rb_tex_name);
169
+ int xoffset = FIX2INT(rb_xoffset);
170
+ int yoffset = FIX2INT(rb_yoffset);
171
+ int x = FIX2INT(rb_x);
172
+ int y = FIX2INT(rb_y);
173
+ int width = FIX2INT(rb_width);
174
+ int height = FIX2INT(rb_height);
175
+
176
+ rb_funcall(self, rb_intern("flush"), 0);
177
+ glFinish();
178
+
179
+ glEnable(GL_TEXTURE_2D);
180
+ glBindTexture(GL_TEXTURE_2D, tex_name);
181
+
182
+ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, x, y, width, height);
183
+ glDisable(GL_TEXTURE_2D);
184
+
185
+ return Qnil;
186
+ }
187
+
188
+
163
189
  static void
164
190
  monkey_patch_gosu(void)
165
191
  {
166
192
  rb_define_method(gosu_window(), "to_blob", gosu_window_to_blob, 4);
193
+ rb_define_method(gosu_window(), "to_texture", gosu_window_to_texture, 7);
167
194
  }
168
195
 
169
196
  static VALUE
@@ -1,3 +1,3 @@
1
1
  module TexPlay
2
- VERSION = "0.2.983pre1"
2
+ VERSION = "0.2.983pre2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: texplay
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1037985743
4
+ hash: 570791623
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 983pre1
10
- version: 0.2.983pre1
9
+ - 983pre2
10
+ version: 0.2.983pre2
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Mair (banisterfiend)
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-27 00:00:00 +13:00
18
+ date: 2010-10-01 00:00:00 +13:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -107,6 +107,7 @@ files:
107
107
  - examples/example_turtle.rb
108
108
  - examples/example_weird.rb
109
109
  - examples/example_window_to_blob.rb
110
+ - examples/example_window_to_texture.rb
110
111
  - examples/media/bird.png
111
112
  - examples/media/body.png
112
113
  - examples/media/empty2.png
@@ -123,7 +124,7 @@ files:
123
124
  - examples/media/texplay.png
124
125
  - spec/image_spec.rb
125
126
  - spec/texplay_spec.rb
126
- has_rdoc: true
127
+ has_rdoc: false
127
128
  homepage: http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/
128
129
  licenses: []
129
130