Class: SFML::Texture
- Inherits:
-
Object
- Object
- SFML::Texture
- Defined in:
- lib/sfml/graphics/texture.rb
Overview
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
:nodoc:.
Class Method Summary collapse
-
.from_image(image, smooth: false, repeated: false) ⇒ Object
Upload a CPU-side SFML::Image to the GPU as a new Texture.
- .load(path, smooth: false, repeated: false) ⇒ Object
Instance Method Summary collapse
- #repeated=(value) ⇒ Object
- #repeated? ⇒ Boolean
- #size ⇒ Object
- #smooth=(value) ⇒ Object
- #smooth? ⇒ Boolean
-
#to_image ⇒ Object
Read the texture back from the GPU into a fresh SFML::Image.
-
#update(image) ⇒ Object
Re-upload an Image’s pixels to this texture in place.
Instance Attribute Details
#handle ⇒ Object (readonly)
:nodoc:
71 72 73 |
# File 'lib/sfml/graphics/texture.rb', line 71 def handle @handle end |
Class Method Details
.from_image(image, smooth: false, repeated: false) ⇒ Object
Upload a CPU-side SFML::Image to the GPU as a new Texture. Keeps the RGBA byte order and dimensions of the source image.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sfml/graphics/texture.rb', line 21 def self.from_image(image, smooth: false, repeated: false) raise ArgumentError, "Texture.from_image needs a SFML::Image" unless image.is_a?(Image) ptr = C::Graphics.sfTexture_createFromImage(image.handle, nil) raise Error, "sfTexture_createFromImage returned NULL" if ptr.null? tex = allocate tex.send(:_take_ownership, ptr) tex.smooth = smooth tex.repeated = repeated tex end |
.load(path, smooth: false, repeated: false) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/sfml/graphics/texture.rb', line 8 def self.load(path, smooth: false, repeated: false) ptr = C::Graphics.sfTexture_createFromFile(path.to_s, nil) raise Error, "Could not load texture from #{path.inspect}" if ptr.null? tex = allocate tex.send(:_take_ownership, ptr) tex.smooth = smooth tex.repeated = repeated tex end |
Instance Method Details
#repeated=(value) ⇒ Object
67 68 69 |
# File 'lib/sfml/graphics/texture.rb', line 67 def repeated=(value) C::Graphics.sfTexture_setRepeated(@handle, !!value) end |
#repeated? ⇒ Boolean
65 |
# File 'lib/sfml/graphics/texture.rb', line 65 def repeated? = C::Graphics.sfTexture_isRepeated(@handle) |
#size ⇒ Object
55 56 57 |
# File 'lib/sfml/graphics/texture.rb', line 55 def size Vector2.from_native(C::Graphics.sfTexture_getSize(@handle)) end |
#smooth=(value) ⇒ Object
61 62 63 |
# File 'lib/sfml/graphics/texture.rb', line 61 def smooth=(value) C::Graphics.sfTexture_setSmooth(@handle, !!value) end |
#smooth? ⇒ Boolean
59 |
# File 'lib/sfml/graphics/texture.rb', line 59 def smooth? = C::Graphics.sfTexture_isSmooth(@handle) |
#to_image ⇒ Object
Read the texture back from the GPU into a fresh SFML::Image. Slow — useful for screenshots or post-processing inspection.
47 48 49 50 51 52 53 |
# File 'lib/sfml/graphics/texture.rb', line 47 def to_image ptr = C::Graphics.sfTexture_copyToImage(@handle) raise Error, "sfTexture_copyToImage returned NULL" if ptr.null? img = Image.allocate img.send(:_take_ownership, ptr) img end |
#update(image) ⇒ Object
Re-upload an Image’s pixels to this texture in place. The image must match the texture’s size — use this for animated procedural textures (paint-buffer style) without re-allocating GPU memory.
37 38 39 40 41 42 43 |
# File 'lib/sfml/graphics/texture.rb', line 37 def update(image) raise ArgumentError, "Texture#update needs a SFML::Image" unless image.is_a?(Image) offset = C::System::Vector2u.new offset[:x] = 0; offset[:y] = 0 C::Graphics.sfTexture_updateFromImage(@handle, image.handle, offset) self end |