Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Extending Gosu / DevIL imaging library now works with Gosu
- By banister Date 2009-10-13 04:42 Edited 2009-10-13 16:23
Heya,

I've been working on ruby bindings for the DevIL imaging library these last few days and I think i've finally finished the first iteration.
DevIL provides the following functionality for Gosu users:

* lets you load any file format into Gosu, .jpg, .gif, .tga and more
* lets you *save* Gosu::Images (only really useful if you've manipulated them first in some way, using TexPlay for example)
* lets you convert between Gosu::Images and Devil::Images (using #to_devil and #to_gosu)
* lets you take screenshots of the current state of the Gosu Window, manipulate it using Devil, and save to a file (or import back into Gosu if you wish, using #to_gosu)
* Of course DevIL also works independently of Gosu (though that's not relevant to this forum... hehe :)

GEMS YOU NEED:
==========

* The very latest version of TexPlay (0.2.666)  (gem install texplay)
* ruby-opengl (gem install ruby-opengl)

INITIAL SETUP:
=========

To use DevIL on *nix sysems (incl. macosx) you should first install the 'devil' library and development packages.
On Debian-based systems:
* you can find the name of these using apt-cache search devil. The packages have names such as libdevil-dev, etc

On Gentoo:
*  emerge "media-libs/devil"

On Windows:
* simply extract the following zip file into c:\windows\system:
* http://cloud.github.com/downloads/banister/devil/devil-dlls.zip    (it should include devil.dll and ilu.dll)

INSTALLING THE GEM:
============

Once you've done the above it's just a matter of going
* gem install devil

and you're good to go!

Just have a look at the rdoc and the test/ directory for examples on how to use it. Also feel free to ask questions on this thread!

RDOC:
====

http://rdoc.info/projects/banister/devil

GITHUB:
====

here's the project page: http://github.com/banister/devil

thanks,

banister
- By Wurstinator Date 2009-12-21 20:12
Hi again,
I have a problem with DevIL ^^'
When I call gem install devil I get the error:

gem install devil
Building native extensions.  This could take a while...
ERROR:  Error installing devil:
        ERROR: Failed to build gem native extension.

D:/Programme/Ruby/bin/ruby.exe extconf.rb
checking for main() in -lDevIL... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=D:/Programme/Ruby/bin/ruby
        --with-DevILlib
        --without-DevILlib

Gem files will remain installed in D:/Programme/Ruby/lib/ruby/gems/1.9.1/gems/de
vil-0.1.9.1 for inspection.
Results logged to D:/Programme/Ruby/lib/ruby/gems/1.9.1/gems/devil-0.1.9.1/ext/d
evil/gem_make.out
- By jlnr (dev) Date 2009-12-22 01:11
AFAIK DevIL should be precompiled on Win32 and the fix should be the same as last time:

http://www.libgosu.org/cgi-bin/mwf/topic_show.pl?pid=1876#pid1876
- By Wurstinator Date 2009-12-22 16:17
Oh, yes sorry.
I totally forgot that.
- By RunnerPack Date 2010-04-21 04:59 Edited 2010-04-21 05:29
(A little late, but...)

This is an incredibly cool addition to Gosu and TexPlay! Now I can save my algorithmically generated pixels to a file! (Well, I already could, but now it's way easier...) Not to mention the plethora of other image manipulations...

I'm off to write a Gosu+TexPlay ray-tracer, now! (j/k, of course, but I do want to make some kind of paint program...)

(BTW, I left a "possible bug" report about TexPlay in the comments on the TexPlay entry of your blog.)
- By banister Date 2010-04-22 20:45
hey, sorry man i dont have time to test that at the moment. But i really do not think it's a bug in the line drawing code...

if you could isolate the 'bug' into a simple code that i can run some tests on, ill have another look at it. :)
- By RunnerPack Date 2010-04-23 08:50
I agree, the bug may not be in the "line" code itself. It's more likely that it's in the "paint" block code.

I just changed the paint block into two directly invoked "line" statements and it works fine (I can't believe I didn't test that... Anyway, most of the IM I sent is still relevant).

Well, I'll stop hijacking this thread now...
- By banister Date 2010-04-23 13:16
Cool. I'll check up on it. Thanks :)
- - By Spooner Date 2010-08-19 00:01
As far as I can tell, Gosu::Image.to_devil is broken, since it does a vertical flip on the new image (Devil.from_blob seems to work fine).

  devil_image = Devil.from_blob(gosu_image.to_blob, gosu_image.width, gosu_image.height)

is equivalent in effect to:

  devil_image = gosu_image.to_devil
  devil_image.flip

(note that in both cases, I get the same red/blue colour shifting, but that is a known problem with Gosu::Image.to_blob).
Parent - - By banister Date 2010-08-19 01:38
i remember i had huge problems with this....sometimes the flip was required and other times it wasn't, and i could never exactly determine the situations when it was/wasn't required....

i could try taking another look at it, but iirc the issue was kinda related to the fact that opengl image coordinates are bottom-right, whereas gosu image coords are topleft, and there was some kind of weird interaction when attempting to switch between them

as for the color switching, you could TRY this temporary fix:
class Gosu::Image; remove_method :to_blob; end

let me know if that fix above works, as personally i couldn't get it working in windows (though it worked in linux)

thx
Parent - - By kyonides Date 2010-08-19 01:45 Edited 2010-08-19 01:48
Or try...

class Gosu::Image; undef :to_blob; end

or...

class Gosu::Image; undef to_blob; end
Parent - - By banister Date 2010-08-19 01:48
i dont think undef would work as it not only removes the method but it prevents look-up further up the inheritance chain. What we want is the method looked up in TexPlay, which is a superclass of Gosu::Image
Parent - By kyonides Date 2010-08-19 02:04
Interesting, I didn't know that's what remove_method could actually do that undef couldn't do.
Parent - - By Spooner Date 2010-08-19 09:14
Sadly, your color switching fix doesn't work so well. Leads to a nice little segfault (Win7x64 / Ruby 1.9.2)! I know jnlr has fixed it, so I'll just wait for the fix to get pushed out, presumably after LD.

I managed to overcome the color bug myself, though in a messy way, which also needs from_blob. It will do for now!

I would have thought the to_gosu fix would be easy though, since all you need to do is call the correctly working Devil::from_blob code. Still, since from_blob works fine I don't really need to_gosu; it is just cleaner. Oh, while I'm causing trouble, to_gosu probably needs a :tileable option (I really don't need it; just pointing it out in case others see this and suddenly realise they need it).
Parent - - By banister Date 2010-08-19 09:32
Yeah  I got a segfault in windows too; I don't understand it. Have to wait until guys at rubyinstaller.org push a debuggable win release before I can figure out what's going on

Can you explain in more detail the tileable option?
Parent - - By Spooner Date 2010-08-19 09:41
Gosu::Image::new takes a option which is whether the new image is tileable. When you blob/unblob an image this info is lost. Actually, thinking about it, might be worth putting on your create_image to. If you want, I could fork/patch it for you, adding a Gosu::Image::from_blob too, since I found that quite useful. Texplay has already been invaluable to me (and Devil is becoming more important), so I'd be happy to do it if you are feeling lazy for a change :)
Parent - - By banister Date 2010-08-19 11:12
yes you better patch it :) since there is very little explanatino for the tileable option in the docs and i dont understand it
Parent - - By Spooner Date 2010-08-19 11:22 Edited 2010-08-21 00:10
Basically, if you draw a tileable image bigger than its actual size (Image#draw with factor > 1), it will anti-alias the inside of it, but ensure that the edge is sharp, so that it can be used as a background tile. A standard (untileable) image may have anti-aliased edges in this situation, which looks fine for sprites but will not tile perfectly. If you look at the example images, the right-hand version is tilable and the right-hand edge of that image is perfectly sharp; the left hand version has slightly blurred edges, most apparent on its left edge). jlnr would probably be better able to explain what this is doing in terms of actual OpenGL commands. 

Mm, another github fork. I should have kept my mouth shut :)
Parent - - By jlnr (dev) Date 2010-08-19 11:29
Nothing on the OpenGL side, but when I put images onto a texture, I can either pad them with transparent pixels (untileable) or manually repeat the last pixel (tileable). If I wouldn't pad them at all, they would bleed into each other.

Of course, you can just always use tileable and manually pad your images. :)
Parent - By Spooner Date 2010-08-19 12:33
Hmm, that means that tileable is not really compatible with "Texplayed" images, since the edge pixels can change after creation without updating that padding (unless Banister wants to do a _lot_ of work in the C code). Thanks for the explanation!
Up Topic Gosu / Extending Gosu / DevIL imaging library now works with Gosu

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill