Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Extending Gosu / Screenshots using add-on libraries (snippets) [from wiki]
- By jlnr (dev) Date 2009-01-07 10:27
Two pretty cool code snippets from the wiki that mustn't get lost:

Comment by popo...@popolon.org, Jan 14, 2008
png can be replaced by jpg

to launch at the end of the window.draw() function


require 'gl'   # for gl functions
require 'gtk2' # for gdk-pixbuf functions
[...]
  def get_screenshot
    gl{}
    data = glReadPixels( 0, 0, WIDTH - 1, HEIGHT - 1, GL_RGB, GL_UNSIGNED_BYTE)
    screenbuffer = Gdk::Pixbuf.new(data, Gdk::Pixbuf::COLORSPACE_RGB, false, 8, WIDTH - 1, HEIGHT - 1, (WIDTH - 1)* 3)
    screenbuffer.flip(false).save("#{$screenshot_path}/scrinshaute_gosu.png", 'png')
  end
[...]


Comment by dgam3z, Jan 14, 2008
Same as above but instead of using gtk, it uses rmagick. (note about popolon's code: the data = getReadPixels([...]) should be inside the gl block)


require 'gl'   # for gl functions
require 'rmagick' # for rmagick functions
[...]
  def get_screenshot
        gl { data = glReadPixels( 0, 0, WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_SHORT) }
               
        screenbuffer = Magick::Image.new(WIDTH, HEIGHT);
        screenbuffer.import_pixels(0, 0, WIDTH, HEIGHT, "RGB", data, Magick::ShortPixel).flip!
        screenbuffer.write("screenshot_gosu.png");
    end
  end
[...]
Up Topic Gosu / Extending Gosu / Screenshots using add-on libraries (snippets) [from wiki]

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill