Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Extending Gosu / TexPlay, drawing and hit-testing for Gosu::Image [from wiki]
1 2 Previous Next  
- By jlnr (dev) Date 2009-02-10 03:17 Edited 2009-02-10 03:24
As originally posted on the Wiki by jrmair, Aug 26, 2008:

> if anyone is interested in trying out or bugtesting TexPlay (a c extension for gosu for manipulating images) go here: http://banisterfiend.wordpress.com/
>
> it currently supports get_pixel and the ability to manipulate gosu images at runtime (the drawing of circles, lines boxes etc).
>
> Perfect for fast pixel-perfect collision detection in games, and fast image manipulation.


The library is explained in great detail here: http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/
- By banister Date 2009-02-12 16:16 Edited 2009-02-13 17:19
i just updated TexPlay, it's now at version 0.1.0. I've changed the API and the syntax:

* To get the color of a pixel on your image:

    image.get_pixel(60,60)

* To modify your image:

    image.paint {
        circle 20, 20
        pixel 10, 10
    }

image is just any Gosu::Image.

For full information and download go here: http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/

TexPlay supports Windows, Linux and MacOsx systems.

Please get back to me with any feedback, suggestions or bug reports :)
- By awright Date 2009-02-15 05:16
wow cool! now i can write my lemmings clone! get_pixel was just what i was looking for!! thanks for the lib!
- By philomory Date 2009-05-29 01:51
I really like TexPlay, but I have a problem... the performance of the refresh_cache call you add to the instantiation of images (i.e. Gosu::Image.new(args)) is very, very bad for me. It adds anywhere from 0.5 seconds to nearly 0.9 seconds per image instantiation, and since I load more than a hundred images in my game, all at once, I've had to comment out the call to refresh_cache.

Interestingly, commenting out that call hasn't had any negative effect, so I've not been able to figure out exactly what it was supposed to do in the first place...
- By banister Date 2009-06-01 15:11 Edited 2009-06-01 15:49
hehe yes. 90% of the time you will be able to use TexPlay just fine without the automatic caching in the Gosu::Image::new method...however in certain rare situations (see below) TexPlay will not do what you want unless auto-caching is enabled.

The rare situation is when two or more Gosu images are stored internally on the same quad yet you invoke the TexPlay#paint method on one of those images BEFORE you've finished loading the other images.. In this situation all TexPlay manipulations will work fine for the images loaded prior to the first TexPlay#paint call (TexPlay lazily caches the quad on #paint if the quad is not already cached) but will produce weird results for all image manipulation on the images loaded AFTER (since they missed out on being cached.)

(sorry that was convoluted, it's 3am here :/)

You've convinced me that since this case is so rare I will remove auto-caching from the next version of TexPlay and come up with another way of resolving the weird edge-case .

thanks
- By jlnr (dev) Date 2009-06-01 19:18
I think you could get the OpenGL id of the texture in Image::new and see if you need to redo/merge(?) your painting? :)
- By banister Date 2009-06-01 19:42
ah yes :)
- By banister Date 2009-06-08 16:37 Edited 2009-06-08 19:24
hey,

I fixed the issue with refresh_cache in the new (0.1.4) release of TexPlay. I also added some useful error messages for when you encounter the quirk with gl_tex_info (fixed in Gosu 0.7.13.4 ?)

also added a few more methods and constants:
* TexPlay#quad_cached?    -  returns true if the quad the texture is located on has already been cached
* TexPlay::TP_MAX_QUAD_SIZE    - returns the sidelength of the largest quad that can be allocated. (taken directly from max_texture_size() method in Gosu's Texture.cpp)

You can get the new TexPlay 0.1.4 binaries and source from here:
http://code.google.com/p/texplay/downloads/list?saved=1&ts=1244477834

Note: It is better to use TexPlay with versions of Gosu that do not have the quirk in gl_tex_info or you may be limited to a texture size of 254 x 254

banister