Class: SFML::RenderTexture
- Inherits:
-
Object
- Object
- SFML::RenderTexture
- Defined in:
- ext/graphics/render_texture.c,
ext/graphics/render_texture.c
Overview
An off-screen render target backed by a Texture: anything drawable can be drawn onto it, then read back via #texture (after #display).
The methods below are shared with Window via the render_target.inc fragment (see ext/graphics/render_target.inc) and documented here directly since the fragment hides their function bodies from the doc-comment scanner. Window's own docs restate the same list.
view
Class Method Summary collapse
-
.maximum_antialiasing_level ⇒ Integer
Returns the maximum supported antialiasing level.
Instance Method Summary collapse
-
#active=(value) ⇒ Boolean
Activates or deactivates this render texture as the current OpenGL rendering target on the calling thread.
-
#clear(*args) ⇒ self
Clears the render texture to
color(a Color, default black). -
#clear_color_and_stencil(color, stencil) ⇒ self
Clears the color and stencil buffers in one pass.
-
#clear_stencil(value) ⇒ self
Clears the stencil buffer with the given value.
-
#default_view ⇒ View
Returns the view covering the whole render target.
-
#display ⇒ self
Updates the target texture with everything drawn so far.
-
#draw(*args) ⇒ self
Draws
drawable(anything responding to#draw, i.e. including Drawable) usingstate(a RenderState, default the identity state). -
#draw_primitives(vertices, primitive, state = nil) ⇒ self
Draws raw vertex primitives using the given primitive type and render state.
-
#draw_vertex_buffer_range(buffer, first, count, state = nil) ⇒ self
Draws a range of vertices from a VertexBuffer.
-
#generate_mipmap ⇒ Boolean
Generates the mipmap pyramid for the texture.
-
#initialize(*args) ⇒ RenderTexture
constructor
settingsis currently accepted but ignored. -
#map_coords_to_pixel(point, view = nil) ⇒ Vector2
Converts a world position to pixel coordinates.
-
#map_pixel_to_coords(point, view = nil) ⇒ Vector2
Converts a pixel position to world coordinates, using the inverse of the view transform.
-
#pop_gl_states ⇒ self
Restores the OpenGL states saved by #push_gl_states.
-
#push_gl_states ⇒ self
Saves the current OpenGL states before custom drawing.
-
#repeated=(value) ⇒ Boolean
Enables or disables texture repeating.
-
#repeated? ⇒ Boolean
Returns
trueif texture repeating is enabled. -
#reset_gl_states ⇒ self
Resets the OpenGL states to those SFML expects.
-
#scissor(view = nil) ⇒ Rect
Returns the current scissor rectangle in pixels;
viewdefaults to the target's current view. -
#size ⇒ Vector2
Returns the object's size.
-
#smooth=(value) ⇒ Boolean
Enables or disables smooth rendering.
-
#smooth? ⇒ Boolean
Returns
trueif smooth rendering is enabled. -
#srgb? ⇒ Boolean
Returns
trueif the render texture uses an sRGB format. -
#texture ⇒ Texture
Returns the target texture, whose contents update after each #display.
-
#view ⇒ View
Returns the target's current view.
-
#view=(value) ⇒ self
Sets the target's current view.
-
#viewport(view = nil) ⇒ Rect
Returns the current viewport in pixels;
viewdefaults to the target's current view.
Constructor Details
#new(size) ⇒ RenderTexture #new(size, settings) ⇒ RenderTexture
settings is currently accepted but ignored.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'ext/graphics/render_texture.c', line 52
static VALUE RenderTexture_initialize(int argc, VALUE* argv, VALUE self) {
VALUE rb_size, rb_settings;
sfRenderTexture* render_texture;
rb_scan_args(argc, argv, "11", &rb_size, &rb_settings);
(void)rb_settings;
render_texture = sfRenderTexture_create(vec2u_from_rb(rb_size), NULL);
if (render_texture == NULL) {
rb_raise(rb_eRuntimeError, "failed to create render texture");
}
DATA_PTR(self) = render_texture;
return self;
}
|
Class Method Details
.maximum_antialiasing_level ⇒ Integer
Returns the maximum supported antialiasing level.
266 267 268 |
# File 'ext/graphics/render_texture.c', line 266 static VALUE RenderTexture_maximum_antialiasing_level(VALUE klass) { return UINT2NUM(sfRenderTexture_getMaximumAntiAliasingLevel()); } |
Instance Method Details
#active=(value) ⇒ Boolean
Activates or deactivates this render texture as the current OpenGL rendering target on the calling thread.
91 92 93 |
# File 'ext/graphics/render_texture.c', line 91
static VALUE RenderTexture_set_active(VALUE self, VALUE rb_active) {
return BOOL2RB(sfRenderTexture_setActive(Get_RenderTexture_Struct(self), RTEST(rb_active)));
}
|
#clear ⇒ self #clear(color) ⇒ self
Clears the render texture to color (a Color, default black).
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'ext/graphics/render_texture.c', line 115
static VALUE RenderTexture_clear(int argc, VALUE* argv, VALUE self) {
VALUE rb_color;
sfColor color = sfBlack;
rb_scan_args(argc, argv, "01", &rb_color);
if (!NIL_P(rb_color)) {
color = color_from_rb(rb_color);
}
sfRenderTexture_clear(Get_RenderTexture_Struct(self), color);
return self;
}
|
#clear_color_and_stencil(color, stencil) ⇒ self
Clears the color and stencil buffers in one pass.
#clear_stencil(value) ⇒ self
Clears the stencil buffer with the given value.
#default_view ⇒ View
Returns the view covering the whole render target.
164 165 166 167 |
# File 'ext/graphics/render_texture.c', line 164 static VALUE RenderTexture_get_default_view(VALUE self) { return Get_Casting_View( sfView_copy(sfRenderTexture_getDefaultView(Get_RenderTexture_Struct(self)))); } |
#display ⇒ self
Updates the target texture with everything drawn so far. Call this after drawing and before reading #texture.
102 103 104 105 |
# File 'ext/graphics/render_texture.c', line 102 static VALUE RenderTexture_display(VALUE self) { sfRenderTexture_display(Get_RenderTexture_Struct(self)); return self; } |
#draw(drawable) ⇒ self #draw(drawable, state) ⇒ self
Draws drawable (anything responding to #draw, i.e. including
Drawable) using state (a RenderState, default the identity state).
244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'ext/graphics/render_texture.c', line 244
static VALUE RenderTexture_draw(int argc, VALUE* argv, VALUE self) {
VALUE rb_drawable, rb_state;
if (argc == 0 || argc > 2) {
raise_invalid_arguments_excepted(-1, argc);
}
rb_drawable = argv[0];
rb_state = (argc == 2) ? argv[1] : Get_New_RenderState();
rb_funcall(rb_drawable, rb_intern("draw"), 2, self, rb_state);
return self;
}
|
#draw_primitives(vertices, primitive, state = nil) ⇒ self
Draws raw vertex primitives using the given primitive type and render state.
#draw_vertex_buffer_range(buffer, first, count, state = nil) ⇒ self
Draws a range of vertices from a VertexBuffer.
#generate_mipmap ⇒ Boolean
Generates the mipmap pyramid for the texture.
230 231 232 |
# File 'ext/graphics/render_texture.c', line 230 static VALUE RenderTexture_generate_mipmap(VALUE self) { return BOOL2RB(sfRenderTexture_generateMipmap(Get_RenderTexture_Struct(self))); } |
#map_coords_to_pixel(point, view = nil) ⇒ Vector2
Converts a world position to pixel coordinates.
#map_pixel_to_coords(point, view = nil) ⇒ Vector2
Converts a pixel position to world coordinates, using the inverse of the view transform.
#pop_gl_states ⇒ self
Restores the OpenGL states saved by #push_gl_states.
#push_gl_states ⇒ self
Saves the current OpenGL states before custom drawing.
#repeated=(value) ⇒ Boolean
Enables or disables texture repeating.
209 210 211 212 |
# File 'ext/graphics/render_texture.c', line 209
static VALUE RenderTexture_set_repeated(VALUE self, VALUE rb_repeated) {
sfRenderTexture_setRepeated(Get_RenderTexture_Struct(self), RTEST(rb_repeated));
return rb_repeated;
}
|
#repeated? ⇒ Boolean
Returns true if texture repeating is enabled.
220 221 222 |
# File 'ext/graphics/render_texture.c', line 220 static VALUE RenderTexture_is_repeated(VALUE self) { return BOOL2RB(sfRenderTexture_isRepeated(Get_RenderTexture_Struct(self))); } |
#reset_gl_states ⇒ self
Resets the OpenGL states to those SFML expects.
#scissor(view = nil) ⇒ Rect
Returns the current scissor rectangle in pixels; view defaults to the target's current view.
#size ⇒ Vector2
Returns the object's size.
77 78 79 80 81 |
# File 'ext/graphics/render_texture.c', line 77
static VALUE RenderTexture_get_size(VALUE self) {
sfVector2u size = sfRenderTexture_getSize(Get_RenderTexture_Struct(self));
return vec2f_to_rb((sfVector2f){(float)size.x, (float)size.y});
}
|
#smooth=(value) ⇒ Boolean
Enables or disables smooth rendering.
187 188 189 190 |
# File 'ext/graphics/render_texture.c', line 187
static VALUE RenderTexture_set_smooth(VALUE self, VALUE rb_smooth) {
sfRenderTexture_setSmooth(Get_RenderTexture_Struct(self), RTEST(rb_smooth));
return rb_smooth;
}
|
#smooth? ⇒ Boolean
Returns true if smooth rendering is enabled.
198 199 200 |
# File 'ext/graphics/render_texture.c', line 198 static VALUE RenderTexture_is_smooth(VALUE self) { return BOOL2RB(sfRenderTexture_isSmooth(Get_RenderTexture_Struct(self))); } |
#srgb? ⇒ Boolean
Returns true if the render texture uses an sRGB format.
#texture ⇒ Texture
Returns the target texture, whose contents update after each #display.
176 177 178 |
# File 'ext/graphics/render_texture.c', line 176 static VALUE RenderTexture_get_texture(VALUE self) { return texture_from_borrowed(sfRenderTexture_getTexture(Get_RenderTexture_Struct(self))); } |
#view ⇒ View
Returns the target's current view.
154 155 156 |
# File 'ext/graphics/render_texture.c', line 154 static VALUE RenderTexture_get_view(VALUE self) { return Get_Casting_View(sfView_copy(sfRenderTexture_getView(Get_RenderTexture_Struct(self)))); } |
#view=(value) ⇒ self
Sets the target's current view.
138 139 140 141 142 143 144 145 146 |
# File 'ext/graphics/render_texture.c', line 138
static VALUE RenderTexture_set_view(VALUE self, VALUE rb_view) {
if (!rb_obj_is_kind_of(rb_view, Get_Klass_View())) {
raise_invalid_argument_class(Get_Klass_View());
}
sfRenderTexture_setView(Get_RenderTexture_Struct(self), Get_View_Struct(rb_view));
return self;
}
|
#viewport(view = nil) ⇒ Rect
Returns the current viewport in pixels; view defaults to the target's current view.