Class: SFML::RenderTexture
- Inherits:
-
Object
- Object
- SFML::RenderTexture
- Includes:
- Graphics::RenderTarget
- Defined in:
- lib/sfml/graphics/render_texture.rb
Overview
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.
Constant Summary collapse
- CSFML_PREFIX =
:sfRenderTexture
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
:nodoc:.
Class Method Summary collapse
-
.maximum_anti_aliasing_level ⇒ Object
Maximum MSAA level the driver can apply to a RenderTexture at this moment.
Instance Method Summary collapse
-
#active=(value) ⇒ Object
—- GL interop (mirror of RenderWindow’s) —-.
-
#generate_mipmap ⇒ Object
Generate mipmaps for the underlying texture.
-
#initialize(width, height, smooth: false, repeated: false) ⇒ RenderTexture
constructor
A new instance of RenderTexture.
- #pop_gl_states ⇒ Object
- #push_gl_states ⇒ Object
- #repeated=(value) ⇒ Object
- #repeated? ⇒ Boolean
- #reset_gl_states ⇒ Object
- #scissor(view = self.view) ⇒ Object
- #size ⇒ Object
- #smooth=(value) ⇒ Object
- #smooth? ⇒ Boolean
-
#srgb? ⇒ Boolean
‘true` if the framebuffer is sRGB-capable.
-
#texture ⇒ Object
The Texture this RenderTexture is rendering into.
-
#viewport(view = self.view) ⇒ Object
Pixel-space viewport / scissor for the given view (defaults to the active view).
Methods included from Graphics::RenderTarget
#clear, #default_view, #display, #draw, #draw_primitives, #map_coords_to_pixel, #map_pixel_to_coords, #view, #view=
Constructor Details
#initialize(width, height, smooth: false, repeated: false) ⇒ RenderTexture
Returns a new instance of RenderTexture.
24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 Error, "sfRenderTexture_create returned NULL" if ptr.null? @handle = FFI::AutoPointer.new(ptr, C::Graphics.method(:sfRenderTexture_destroy)) self.smooth = smooth self.repeated = repeated end |
Instance Attribute Details
#handle ⇒ Object (readonly)
:nodoc:
109 110 111 |
# File 'lib/sfml/graphics/render_texture.rb', line 109 def handle @handle end |
Class Method Details
.maximum_anti_aliasing_level ⇒ Object
Maximum MSAA level the driver can apply to a RenderTexture at this moment. Class-level — independent of the instance.
68 69 70 |
# File 'lib/sfml/graphics/render_texture.rb', line 68 def self.maximum_anti_aliasing_level C::Graphics.sfRenderTexture_getMaximumAntiAliasingLevel end |
Instance Method Details
#active=(value) ⇒ Object
—- GL interop (mirror of RenderWindow’s) —-
74 75 76 |
# File 'lib/sfml/graphics/render_texture.rb', line 74 def active=(value) C::Graphics.sfRenderTexture_setActive(@handle, value ? true : false) end |
#generate_mipmap ⇒ Object
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`).
62 63 64 |
# File 'lib/sfml/graphics/render_texture.rb', line 62 def generate_mipmap C::Graphics.sfRenderTexture_generateMipmap(@handle) end |
#pop_gl_states ⇒ Object
78 |
# File 'lib/sfml/graphics/render_texture.rb', line 78 def pop_gl_states = C::Graphics.sfRenderTexture_popGLStates(@handle) |
#push_gl_states ⇒ Object
77 |
# File 'lib/sfml/graphics/render_texture.rb', line 77 def push_gl_states = C::Graphics.sfRenderTexture_pushGLStates(@handle) |
#repeated=(value) ⇒ Object
50 51 52 |
# File 'lib/sfml/graphics/render_texture.rb', line 50 def repeated=(value) C::Graphics.sfRenderTexture_setRepeated(@handle, !!value) end |
#repeated? ⇒ Boolean
48 |
# File 'lib/sfml/graphics/render_texture.rb', line 48 def repeated? = C::Graphics.sfRenderTexture_isRepeated(@handle) |
#reset_gl_states ⇒ Object
79 |
# File 'lib/sfml/graphics/render_texture.rb', line 79 def reset_gl_states = C::Graphics.sfRenderTexture_resetGLStates(@handle) |
#scissor(view = self.view) ⇒ Object
88 89 90 91 |
# File 'lib/sfml/graphics/render_texture.rb', line 88 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 |
#size ⇒ Object
37 38 39 40 |
# File 'lib/sfml/graphics/render_texture.rb', line 37 def size v = C::Graphics.sfRenderTexture_getSize(@handle) Vector2.new(v[:x], v[:y]) end |
#smooth=(value) ⇒ Object
44 45 46 |
# File 'lib/sfml/graphics/render_texture.rb', line 44 def smooth=(value) C::Graphics.sfRenderTexture_setSmooth(@handle, !!value) end |
#smooth? ⇒ Boolean
42 |
# File 'lib/sfml/graphics/render_texture.rb', line 42 def smooth? = C::Graphics.sfRenderTexture_isSmooth(@handle) |
#srgb? ⇒ Boolean
‘true` if the framebuffer is sRGB-capable.
55 |
# File 'lib/sfml/graphics/render_texture.rb', line 55 def srgb? = C::Graphics.sfRenderTexture_isSrgb(@handle) |
#texture ⇒ Object
The Texture this RenderTexture is rendering into. Borrowed — its lifetime is bounded by ‘self`. Memoised so repeated calls return the same Ruby wrapper.
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/sfml/graphics/render_texture.rb', line 96 def texture @texture ||= begin ptr = C::Graphics.sfRenderTexture_getTexture(@handle) raise Error, "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 |
#viewport(view = self.view) ⇒ Object
Pixel-space viewport / scissor for the given view (defaults to the active view). Same shape as RenderWindow’s.
83 84 85 86 |
# File 'lib/sfml/graphics/render_texture.rb', line 83 def (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 |