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.



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

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.



8
9
10
# File 'lib/ehb_game_lib/window/gl_read_pixels_image.rb', line 8

def columns
  @columns
end

#rowsObject (readonly)

Returns the value of attribute rows.



8
9
10
# File 'lib/ehb_game_lib/window/gl_read_pixels_image.rb', line 8

def rows
  @rows
end

Instance Method Details

#to_blobObject



21
22
23
# File 'lib/ehb_game_lib/window/gl_read_pixels_image.rb', line 21

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