class SFML::RenderTexture
Off-screen rendering target. Anything you can draw on a RenderWindow— sprites, shapes, text, vertex arrays — you can also draw on a RenderTexture and then use its texture as a Sprite source. Typical uses: minimaps, post-processing, motion-blur trails, custom UIs that composite multiple layers.
rt = SFML::RenderTexture.new(400, 300) rt.clear(SFML::Color.cornflower_blue) rt.draw(sprite) rt.draw(text) rt.display
sprite = SFML::Sprite.new(rt.texture) window.draw(sprite)
Note: rt.texture returns a borrowed reference owned by the RenderTexture. Keep the RenderTexture alive for as long as anything uses its texture.
Constants
- CSFML_PREFIX
Public Class Methods
Source
# File lib/sfml/graphics/render_texture.rb, line 73 def self.maximum_anti_aliasing_level C::Graphics.sfRenderTexture_getMaximumAntiAliasingLevel end
Maximum MSAA level the driver can apply to a RenderTexture at this moment. Class-level — independent of the instance.
Source
# File lib/sfml/graphics/render_texture.rb, line 24 def initialize(width, height, smooth: false, repeated: false) size = C::System::Vector2u.new size[:x] = Integer(width) size[:y] = Integer(height) ptr = C::Graphics.sfRenderTexture_create(size, nil) raise GraphicsError, "sfRenderTexture_create returned NULL" if ptr.null? @handle = FFI::AutoPointer.new(ptr, C::Graphics.method(:sfRenderTexture_destroy)) self.smooth = smooth self.repeated = repeated end
Public Instance Methods
Source
# File lib/sfml/graphics/render_texture.rb, line 79 def active=(value) C::Graphics.sfRenderTexture_setActive(@handle, value ? true : false) end
—- GL interop (mirror of RenderWindow’s) —-
Source
# File lib/sfml/graphics/render_texture.rb, line 67 def generate_mipmap C::Graphics.sfRenderTexture_generateMipmap(@handle) end
Generate mipmaps for the underlying texture. Useful when the texture will be sampled at a downscaled size — without mipmaps you get aliasing on minification. Returns true if the GPU honoured the request (NPOT or unsupported drivers return false).
Source
# File lib/sfml/graphics/render_texture.rb, line 85 def pop_gl_states = C::Graphics.sfRenderTexture_popGLStates(@handle) # Returns the reset gl states. def reset_gl_states = C::Graphics.sfRenderTexture_resetGLStates(@handle) # Pixel-space viewport / scissor for the given view (defaults # to the active view). Same shape as RenderWindow's. def viewport(view = self.view) raise ArgumentError, "expected a SFML::View" unless view.is_a?(View) Rect.from_native(C::Graphics.sfRenderTexture_getViewport(@handle, view.handle)) end # Returns the scissor. def scissor(view = self.view) raise ArgumentError, "expected a SFML::View" unless view.is_a?(View) Rect.from_native(C::Graphics.sfRenderTexture_getScissor(@handle, view.handle)) end # The Texture this RenderTexture is rendering into. Borrowed — its # lifetime is bounded by `self`. Memoised so repeated calls return # the same Ruby wrapper. def texture @texture ||= begin ptr = C::Graphics.sfRenderTexture_getTexture(@handle) raise GraphicsError, "sfRenderTexture_getTexture returned NULL" if ptr.null? # Borrowed — RenderTexture owns the underlying sf::Texture, so # we wrap with a raw pointer (no AutoPointer / no destructor). # Sprite.new(@texture) will still get a valid handle through it. tex = Texture.allocate tex.instance_variable_set(:@handle, ptr) tex end end attr_reader :handle # :nodoc: end end
Source
# File lib/sfml/graphics/render_texture.rb, line 83 def push_gl_states = C::Graphics.sfRenderTexture_pushGLStates(@handle) # Returns the pop gl states. def pop_gl_states = C::Graphics.sfRenderTexture_popGLStates(@handle) # Returns the reset gl states. def reset_gl_states = C::Graphics.sfRenderTexture_resetGLStates(@handle) # Pixel-space viewport / scissor for the given view (defaults # to the active view). Same shape as RenderWindow's. def viewport(view = self.view) raise ArgumentError, "expected a SFML::View" unless view.is_a?(View) Rect.from_native(C::Graphics.sfRenderTexture_getViewport(@handle, view.handle)) end # Returns the scissor. def scissor(view = self.view) raise ArgumentError, "expected a SFML::View" unless view.is_a?(View) Rect.from_native(C::Graphics.sfRenderTexture_getScissor(@handle, view.handle)) end # The Texture this RenderTexture is rendering into. Borrowed — its # lifetime is bounded by `self`. Memoised so repeated calls return # the same Ruby wrapper. def texture @texture ||= begin ptr = C::Graphics.sfRenderTexture_getTexture(@handle) raise GraphicsError, "sfRenderTexture_getTexture returned NULL" if ptr.null? # Borrowed — RenderTexture owns the underlying sf::Texture, so # we wrap with a raw pointer (no AutoPointer / no destructor). # Sprite.new(@texture) will still get a valid handle through it. tex = Texture.allocate tex.instance_variable_set(:@handle, ptr) tex end end attr_reader :handle # :nodoc: end
Returns the push gl states.
Source
# File lib/sfml/graphics/render_texture.rb, line 55 def repeated=(value) C::Graphics.sfRenderTexture_setRepeated(@handle, !!value) end
Set the repeated.
Source
# File lib/sfml/graphics/render_texture.rb, line 52 def repeated? = C::Graphics.sfRenderTexture_isRepeated(@handle) # Set the repeated. def repeated=(value) C::Graphics.sfRenderTexture_setRepeated(@handle, !!value) end # `true` if the framebuffer is sRGB-capable. def srgb? = C::Graphics.sfRenderTexture_isSrgb(@handle) # Generate mipmaps for the underlying texture. Useful when the # texture will be sampled at a downscaled size — without # mipmaps you get aliasing on minification. Returns `true` if # the GPU honoured the request (NPOT or unsupported drivers # return `false`). def generate_mipmap C::Graphics.sfRenderTexture_generateMipmap(@handle) end # Maximum MSAA level the driver can apply to a RenderTexture # at this moment. Class-level — independent of the instance. def self.maximum_anti_aliasing_level C::Graphics.sfRenderTexture_getMaximumAntiAliasingLevel end # ---- GL interop (mirror of RenderWindow's) ---- def active=(value) C::Graphics.sfRenderTexture_setActive(@handle, value ? true : false) end # Returns the push gl states. def push_gl_states = C::Graphics.sfRenderTexture_pushGLStates(@handle) # Returns the pop gl states. def pop_gl_states = C::Graphics.sfRenderTexture_popGLStates(@handle) # Returns the reset gl states. def reset_gl_states = C::Graphics.sfRenderTexture_resetGLStates(@handle) # Pixel-space viewport / scissor for the given view (defaults # to the active view). Same shape as RenderWindow's. def viewport(view = self.view) raise ArgumentError, "expected a SFML::View" unless view.is_a?(View) Rect.from_native(C::Graphics.sfRenderTexture_getViewport(@handle, view.handle)) end # Returns the scissor. def scissor(view = self.view) raise ArgumentError, "expected a SFML::View" unless view.is_a?(View) Rect.from_native(C::Graphics.sfRenderTexture_getScissor(@handle, view.handle)) end # The Texture this RenderTexture is rendering into. Borrowed — its # lifetime is bounded by `self`. Memoised so repeated calls return # the same Ruby wrapper. def texture @texture ||= begin ptr = C::Graphics.sfRenderTexture_getTexture(@handle) raise GraphicsError, "sfRenderTexture_getTexture returned NULL" if ptr.null? # Borrowed — RenderTexture owns the underlying sf::Texture, so # we wrap with a raw pointer (no AutoPointer / no destructor). # Sprite.new(@texture) will still get a valid handle through it. tex = Texture.allocate tex.instance_variable_set(:@handle, ptr) tex end end attr_reader :handle
true if repeated.
Source
# File lib/sfml/graphics/render_texture.rb, line 87 def reset_gl_states = C::Graphics.sfRenderTexture_resetGLStates(@handle) # Pixel-space viewport / scissor for the given view (defaults # to the active view). Same shape as RenderWindow's. def viewport(view = self.view) raise ArgumentError, "expected a SFML::View" unless view.is_a?(View) Rect.from_native(C::Graphics.sfRenderTexture_getViewport(@handle, view.handle)) end # Returns the scissor. def scissor(view = self.view) raise ArgumentError, "expected a SFML::View" unless view.is_a?(View) Rect.from_native(C::Graphics.sfRenderTexture_getScissor(@handle, view.handle)) end # The Texture this RenderTexture is rendering into. Borrowed — its # lifetime is bounded by `self`. Memoised so repeated calls return # the same Ruby wrapper. def texture @texture ||= begin ptr = C::Graphics.sfRenderTexture_getTexture(@handle) raise GraphicsError, "sfRenderTexture_getTexture returned NULL" if ptr.null? # Borrowed — RenderTexture owns the underlying sf::Texture, so # we wrap with a raw pointer (no AutoPointer / no destructor). # Sprite.new(@texture) will still get a valid handle through it. tex = Texture.allocate tex.instance_variable_set(:@handle, ptr) tex end end attr_reader :handle # :nodoc: end
Source
# File lib/sfml/graphics/render_texture.rb, line 97 def scissor(view = self.view) raise ArgumentError, "expected a SFML::View" unless view.is_a?(View) Rect.from_native(C::Graphics.sfRenderTexture_getScissor(@handle, view.handle)) end
Returns the scissor.
Source
# File lib/sfml/graphics/render_texture.rb, line 38 def size v = C::Graphics.sfRenderTexture_getSize(@handle) Vector2.new(v[:x], v[:y]) end
Returns the size.
Source
# File lib/sfml/graphics/render_texture.rb, line 47 def smooth=(value) C::Graphics.sfRenderTexture_setSmooth(@handle, !!value) end
Set the smooth.
Source
# File lib/sfml/graphics/render_texture.rb, line 44 def smooth? = C::Graphics.sfRenderTexture_isSmooth(@handle) # Set the smooth. def smooth=(value) C::Graphics.sfRenderTexture_setSmooth(@handle, !!value) end # `true` if repeated. def repeated? = C::Graphics.sfRenderTexture_isRepeated(@handle) # Set the repeated. def repeated=(value) C::Graphics.sfRenderTexture_setRepeated(@handle, !!value) end # `true` if the framebuffer is sRGB-capable. def srgb? = C::Graphics.sfRenderTexture_isSrgb(@handle) # Generate mipmaps for the underlying texture. Useful when the # texture will be sampled at a downscaled size — without # mipmaps you get aliasing on minification. Returns `true` if # the GPU honoured the request (NPOT or unsupported drivers # return `false`). def generate_mipmap C::Graphics.sfRenderTexture_generateMipmap(@handle) end # Maximum MSAA level the driver can apply to a RenderTexture # at this moment. Class-level — independent of the instance. def self.maximum_anti_aliasing_level C::Graphics.sfRenderTexture_getMaximumAntiAliasingLevel end # ---- GL interop (mirror of RenderWindow's) ---- def active=(value) C::Graphics.sfRenderTexture_setActive(@handle, value ? true : false) end # Returns the push gl states. def push_gl_states = C::Graphics.sfRenderTexture_pushGLStates(@handle) # Returns the pop gl states. def pop_gl_states = C::Graphics.sfRenderTexture_popGLStates(@handle) # Returns the reset gl states. def reset_gl_states = C::Graphics.sfRenderTexture_resetGLStates(@handle) # Pixel-space viewport / scissor for the given view (defaults # to the active view). Same shape as RenderWindow's. def viewport(view = self.view) raise ArgumentError, "expected a SFML::View" unless view.is_a?(View) Rect.from_native(C::Graphics.sfRenderTexture_getViewport(@handle, view.handle)) end # Returns the scissor. def scissor(view = self.view) raise ArgumentError, "expected a SFML::View" unless view.is_a?(View) Rect.from_native(C::Graphics.sfRenderTexture_getScissor(@handle, view.handle)) end # The Texture this RenderTexture is rendering into. Borrowed — its # lifetime is bounded by `self`. Memoised so repeated calls return # the same Ruby wrapper. def texture @texture ||= begin ptr = C::Graphics.sfRenderTexture_getTexture(@handle) raise GraphicsError, "sfRenderTexture_getTexture returned NULL" if ptr.null? # Borrowed — RenderTexture owns the underlying sf::Texture, so # we wrap with a raw pointer (no AutoPointer / no destructor). # Sprite.new(@texture) will still get a valid handle through it. tex = Texture.allocate tex.instance_variable_set(:@handle, ptr) tex end end attr_reader
true if smooth.
Source
# File lib/sfml/graphics/render_texture.rb, line 60 def srgb? = C::Graphics.sfRenderTexture_isSrgb(@handle) # Generate mipmaps for the underlying texture. Useful when the # texture will be sampled at a downscaled size — without # mipmaps you get aliasing on minification. Returns `true` if # the GPU honoured the request (NPOT or unsupported drivers # return `false`). def generate_mipmap C::Graphics.sfRenderTexture_generateMipmap(@handle) end # Maximum MSAA level the driver can apply to a RenderTexture # at this moment. Class-level — independent of the instance. def self.maximum_anti_aliasing_level C::Graphics.sfRenderTexture_getMaximumAntiAliasingLevel end # ---- GL interop (mirror of RenderWindow's) ---- def active=(value) C::Graphics.sfRenderTexture_setActive(@handle, value ? true : false) end # Returns the push gl states. def push_gl_states = C::Graphics.sfRenderTexture_pushGLStates(@handle) # Returns the pop gl states. def pop_gl_states = C::Graphics.sfRenderTexture_popGLStates(@handle) # Returns the reset gl states. def reset_gl_states = C::Graphics.sfRenderTexture_resetGLStates(@handle) # Pixel-space viewport / scissor for the given view (defaults # to the active view). Same shape as RenderWindow's. def viewport(view = self.view) raise ArgumentError, "expected a SFML::View" unless view.is_a?(View) Rect.from_native(C::Graphics.sfRenderTexture_getViewport(@handle, view.handle)) end # Returns the scissor. def scissor(view = self.view) raise ArgumentError, "expected a SFML::View" unless view.is_a?(View) Rect.from_native(C::Graphics.sfRenderTexture_getScissor(@handle, view.handle)) end # The Texture this RenderTexture is rendering into. Borrowed — its # lifetime is bounded by `self`. Memoised so repeated calls return # the same Ruby wrapper. def texture @texture ||= begin ptr = C::Graphics.sfRenderTexture_getTexture(@handle) raise GraphicsError, "sfRenderTexture_getTexture returned NULL" if ptr.null? # Borrowed — RenderTexture owns the underlying sf::Texture, so # we wrap with a raw pointer (no AutoPointer / no destructor). # Sprite.new(@texture) will still get a valid handle through it. tex = Texture.allocate tex.instance_variable_set(:@handle, ptr) tex end end attr_reader :handle # :nodoc:
true if the framebuffer is sRGB-capable.
Source
# File lib/sfml/graphics/render_texture.rb, line 105 def texture @texture ||= begin ptr = C::Graphics.sfRenderTexture_getTexture(@handle) raise GraphicsError, "sfRenderTexture_getTexture returned NULL" if ptr.null? # Borrowed — RenderTexture owns the underlying sf::Texture, so # we wrap with a raw pointer (no AutoPointer / no destructor). # Sprite.new(@texture) will still get a valid handle through it. tex = Texture.allocate tex.instance_variable_set(:@handle, ptr) tex end end
The Texture this RenderTexture is rendering into. Borrowed — its lifetime is bounded by self. Memoised so repeated calls return the same Ruby wrapper.
Source
# File lib/sfml/graphics/render_texture.rb, line 91 def viewport(view = self.view) raise ArgumentError, "expected a SFML::View" unless view.is_a?(View) Rect.from_native(C::Graphics.sfRenderTexture_getViewport(@handle, view.handle)) end
Pixel-space viewport / scissor for the given view (defaults to the active view). Same shape as RenderWindow’s.