Class: SDL2::Texture
- Inherits:
-
FFI::Struct
- Object
- FFI::Struct
- SDL2::Texture
- Defined in:
- lib/sdl2/texture.rb
Class Method Summary collapse
-
.create(renderer, format, access, w, h) ⇒ Object
Constructs a texture within a renderer.
-
.release(pointer) ⇒ Object
Ensures the texture is properly disposed of.
Instance Method Summary collapse
-
#alpha_mod ⇒ Object
Returns the alpha modulation (0~255).
-
#alpha_mod=(uInt8) ⇒ Object
Sets the alpha modulation (0~255).
-
#blend_mode ⇒ Object
Returns the blend mode NOTE: This will be a symbol of the constant value.
-
#blend_mode=(blend_mode) ⇒ Object
Accepts a new blend mode value.
-
#color_mod ⇒ Object
Returns the color modulation, an array of 3 integers (0~255).
-
#color_mod=(colors) ⇒ Object
Sets the color modulation, expects an array of 3 integers (0~255).
-
#destroy ⇒ Object
Destroy this texture.
-
#lock(rect = nil) ⇒ Object
Lock a portion (or all) of a texture for write access Returns: [pointer, pitch] pointer - An FFI::Pointer to the locked pixels pitch - An integer pitch value.
-
#query ⇒ Object
Query the texture about itself: Returns: [format, access, w, h] format - An SDL2::PIXELFORMAT value access - AN SDL2::TEXTUREACCESS value w - an integer representing the width h - an integer representing the height.
-
#unlock ⇒ Object
Unlock.
Class Method Details
.create(renderer, format, access, w, h) ⇒ Object
Constructs a texture within a renderer
33 34 35 |
# File 'lib/sdl2/texture.rb', line 33 def self.create(renderer, format, access, w, h) SDL2.create_texture!(renderer, format, access, w, h) end |
.release(pointer) ⇒ Object
Ensures the texture is properly disposed of
28 29 30 |
# File 'lib/sdl2/texture.rb', line 28 def self.release(pointer) SDL2.destroy_texture(pointer) end |
Instance Method Details
#alpha_mod ⇒ Object
Returns the alpha modulation (0~255)
43 44 45 46 47 |
# File 'lib/sdl2/texture.rb', line 43 def alpha_mod alpha = SDL2::TypedPointer::UInt8.new SDL2.get_texture_alpha_mod!(self, alpha) alpha.value end |
#alpha_mod=(uInt8) ⇒ Object
Sets the alpha modulation (0~255)
50 51 52 |
# File 'lib/sdl2/texture.rb', line 50 def alpha_mod=(uInt8) SDL2.set_texture_alpha_mod!(self, uInt8) end |
#blend_mode ⇒ Object
Returns the blend mode NOTE: This will be a symbol of the constant value.
56 57 58 59 60 |
# File 'lib/sdl2/texture.rb', line 56 def blend_mode blend_mode = SDL2::TypedPointer::BlendMode.new SDL2.get_texture_blend_mode!(self, blend_mode) blend_mode.value end |
#blend_mode=(blend_mode) ⇒ Object
Accepts a new blend mode value. NOTE: Accepts symbol or SDL2::BLENDMODE constant values.
64 65 66 |
# File 'lib/sdl2/texture.rb', line 64 def blend_mode=(blend_mode) SDL2.set_texture_blend_mode!(self, blend_mode) end |
#color_mod ⇒ Object
Returns the color modulation, an array of 3 integers (0~255)
69 70 71 72 73 |
# File 'lib/sdl2/texture.rb', line 69 def color_mod colors = 3.times.map{SDL2::TypedPointer::UInt8.new} SDL2.get_texture_color_mod!(self, *colors) colors.map(&:value) end |
#color_mod=(colors) ⇒ Object
Sets the color modulation, expects an array of 3 integers (0~255)
76 77 78 79 80 |
# File 'lib/sdl2/texture.rb', line 76 def color_mod=(colors) raise "At least 3 for RGB, not #{colors.count}" if colors.count < 3 SDL2.set_texture_color_mod!(self, *colors.first(3)) colors end |
#destroy ⇒ Object
Destroy this texture
38 39 40 |
# File 'lib/sdl2/texture.rb', line 38 def destroy SDL2.destroy_texture(self) end |
#lock(rect = nil) ⇒ Object
Lock a portion (or all) of a texture for write access Returns: [pointer, pitch]
pointer - An FFI::Pointer to the locked pixels
pitch - An integer pitch value
86 87 88 89 90 91 |
# File 'lib/sdl2/texture.rb', line 86 def lock(rect = nil) pointer = SDL2::TypedPointer::Pointer.new pitch = SDL2::TypedPointer::Int.new SDL2.lock_texture!(self, rect, pointer, pitch) [pointer.value, pitch.value] end |
#query ⇒ Object
Query the texture about itself: Returns: [format, access, w, h]
format - An SDL2::PIXELFORMAT value
access - AN SDL2::TEXTUREACCESS value
w - an integer representing the width
h - an integer representing the height
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/sdl2/texture.rb', line 104 def query() query = [ SDL2::TypedPointer::PixelFormat.new, SDL2::TypedPointer::TextureAccess.new, SDL2::TypedPointer::Int.new, SDL2::TypedPointer::Int.new ] SDL2.query_texture!(self, *query) query.map(&:value) end |
#unlock ⇒ Object
Unlock
94 95 96 |
# File 'lib/sdl2/texture.rb', line 94 def unlock() SDL2.unlock_texture(self) end |