Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Capture window to image?
- - By bigtunacan Date 2016-02-20 05:02
I'm currently building a font editing tool in Gosu and I need to be able to capture rectangle from within the window object into an image and then save this to disk.  Is there a way to do this directly in Gosu? 

I did look into using Devil as an option with Gosu, but that is dependent on the TexPlay gem which has not been maintained in quite a long time and it is not working with the latest version of Mac OS X El Capitan.
Parent - By bestguigui Date 2016-02-20 09:45
If you're OK to use opengl you can have a solution. Using glreadpixels to modify a texture set in an empty gosu image maybe, and png writer for example. Never did it but could be a lead to your need !
Parent - - By jlnr (dev) Date 2016-02-20 10:37
Saving a Gosu::Image to disk is easy, image.save('filename.png').

Capturing the screen is not possible with Gosu alone. Spooner has written the Ashton gem which can do it:

https://github.com/Spooner/ashton

...but I'm not sure if it still works. It has been unmaintained for a while.
Parent - - By lol_o2 Date 2016-02-20 10:55
Sadly, Spooner said in one topic that Ashton is discontinued. Some of its features are not compatible with Gosu 0.9+, but framebuffers (feature you look for) should work.
Parent - - By bigtunacan Date 2016-02-20 16:47
It looks like Ashton never implemented the Window#to_image it was on the TODO list on the wiki https://github.com/Spooner/ashton/wiki

I cloned the project and took a look hoping it was there, but sadly no.

Maybe the opengl gem could be used to do this piece as bestguigui suggested, although I have not worked with that gem in the past and am not quite clear on how I would convert that to a Gosu image so as to be able to save it.
Parent - - By lol_o2 Date 2016-02-20 16:53
Instead of rendering to window, you can just render to texture (Ashton::Texture) and draw the texture in window. Then you can also convert texture to image and save it.
Parent - - By bigtunacan Date 2016-02-20 20:21
Even if this would work, I don't think it would solve the issue in my case.  It appears that Ashton has a dependency on TexPlay gem as well; which is the same reason I'm unable able to use Devil.  TexPlay won't compile on El Capitan.
Parent - By lol_o2 Date 2016-02-21 11:43
Has it? I always used Ashton without TexPlay. I don't even have the TexPlay gem.
Parent - - By bigtunacan Date 2016-02-20 20:19
Is there a way in Gosu to render an image onto another image rather than directly onto the window?  In this way I could dynamically build the image and then save the image to file.  This seems like something would be a pretty popular feature.
Parent - By nietzschette Date 2016-02-20 22:15
I second this.  Something equivocal to Surface.blit from SDL would be handy
Parent - - By jlnr (dev) Date 2016-02-20 23:49
2D graphics operations are outside of Gosu's scope. Implementing Window#to_image would be much easier than replicating all of Gosu's drawing operations in software :)

I've opened a ticket: https://github.com/gosu/gosu/issues/317

...but progress is suuuper sloooow right now. =/
Parent - By bigtunacan Date 2016-02-21 02:02
Thanks.  I've added myself as a watcher on that one.
Up Topic Gosu / Gosu Exchange / Capture window to image?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill