Class: EhbGameLib::Window::GlReadPixelsImage

Inherits:
Object
  • Object
show all
Defined in:
lib/ehb_game_lib/window/gl_read_pixels_image.rb

Constant Summary collapse

DEPTH =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, width, height) ⇒ GlReadPixelsImage

Returns a new instance of GlReadPixelsImage.



10
11
12
13
14
15
16
17
# File 'lib/ehb_game_lib/window/gl_read_pixels_image.rb', line 10

def initialize(x, y, width, height)
  @columns = width
  @rows = height
  Gosu.flush
  Gosu.gl do
    @blob = ::Gl.glReadPixels(x, y, width, height, Gl::GL_RGBA, Gl::GL_UNSIGNED_BYTE)
  end
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



6
7
8
# File 'lib/ehb_game_lib/window/gl_read_pixels_image.rb', line 6

def columns
  @columns
end

#rowsObject (readonly)

Returns the value of attribute rows.



6
7
8
# File 'lib/ehb_game_lib/window/gl_read_pixels_image.rb', line 6

def rows
  @rows
end

Instance Method Details

#to_blobObject



19
20
21
# File 'lib/ehb_game_lib/window/gl_read_pixels_image.rb', line 19

def to_blob
  @blob.force_encoding('binary').scan(/.{#{columns * 4}}/m).reverse.join
end