Module: Quake::Debug::Screenshot
- Defined in:
- lib/quake/debug/screenshot.rb
Overview
Captures the current GL framebuffer to a PNG file via glReadPixels.
Class Method Summary collapse
-
.capture(width, height) ⇒ Object
Read the current framebuffer as RGB bytes (bottom-up).
-
.save(filename, width, height) ⇒ Object
Save the current framebuffer as a PNG file.
Class Method Details
.capture(width, height) ⇒ Object
Read the current framebuffer as RGB bytes (bottom-up).
11 12 13 14 15 16 |
# File 'lib/quake/debug/screenshot.rb', line 11 def self.capture(width, height) buf = ("\x00".b * (width * height * 3)) GL.PixelStorei(GL::PACK_ALIGNMENT, 1) GL.ReadPixels(0, 0, width, height, GL::RGB, GL::UNSIGNED_BYTE, buf) buf end |
.save(filename, width, height) ⇒ Object
Save the current framebuffer as a PNG file.
19 20 21 22 23 |
# File 'lib/quake/debug/screenshot.rb', line 19 def self.save(filename, width, height) raw = capture(width, height) flipped = PngWriter.flip_rows(raw, width, height) PngWriter.write(filename, width, height, flipped) end |