Class: Ruby2D::Texture
- Inherits:
-
Object
- Object
- Ruby2D::Texture
- Defined in:
- lib/ruby2d/texture.rb
Overview
This internal class is used to hold raw pixel data which in turn is used to render textures via openGL rendering code.
Constant Summary collapse
- WHITE_OPAQUE_AR =
[1.0, 1.0, 1.0, 1.0].freeze
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#texture_id ⇒ Object
readonly
Returns the value of attribute texture_id.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #delete ⇒ Object
-
#draw(coordinates, texture_coordinates, color = nil) ⇒ Object
Draw the texture.
-
#initialize(pixel_data, width, height) ⇒ Texture
constructor
A new instance of Texture.
Constructor Details
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
9 10 11 |
# File 'lib/ruby2d/texture.rb', line 9 def height @height end |
#texture_id ⇒ Object (readonly)
Returns the value of attribute texture_id.
9 10 11 |
# File 'lib/ruby2d/texture.rb', line 9 def texture_id @texture_id end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
9 10 11 |
# File 'lib/ruby2d/texture.rb', line 9 def width @width end |
Instance Method Details
#delete ⇒ Object
34 35 36 |
# File 'lib/ruby2d/texture.rb', line 34 def delete ext_delete(@texture_id) end |
#draw(coordinates, texture_coordinates, color = nil) ⇒ Object
Draw the texture
24 25 26 27 28 29 30 31 32 |
# File 'lib/ruby2d/texture.rb', line 24 def draw(coordinates, texture_coordinates, color = nil) if @texture_id.zero? @texture_id = ext_create(@pixel_data, @width, @height) @pixel_data = nil end color = color.nil? ? WHITE_OPAQUE_AR : [color.r, color.g, color.b, color.a] ext_draw(coordinates, texture_coordinates, color, @texture_id) end |