sfml3.rb

Class: SFML::RenderTexture

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#new(size) ⇒ RenderTexture #new(size, settings) ⇒ RenderTexture

settings is currently accepted but ignored.

Overloads:

Raises:

  • (RuntimeError) —

    if creation fails



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.

Returns:

  • (Integer)

Returns:

  • (Integer)


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.

Returns:

  • (Boolean)

Returns:

  • (Boolean) —

    whether the operation succeeded



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).

Overloads:

  • #clear ⇒ self

    Returns:

    • (self)
  • #clear(color) ⇒ self

    Returns:

    • (self)

Returns:

  • (self)


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.

Returns:

  • (self)

#clear_stencil(value) ⇒ self

Clears the stencil buffer with the given value.

Returns:

  • (self)

#default_view ⇒ View

Returns the view covering the whole render target.

Returns:

Returns:

  • (View) —

    a copy of the view covering the render texture's full area



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.

Returns:

  • (self)

Returns:

  • (self)


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).

Overloads:

  • #draw(drawable) ⇒ self

    Returns:

    • (self)
  • #draw(drawable, state) ⇒ self

    Returns:

    • (self)

Returns:

  • (self)

Raises:

  • (ArgumentError) —

    if given no arguments or more than 2



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.

Returns:

  • (self)

#draw_vertex_buffer_range(buffer, first, count, state = nil) ⇒ self

Draws a range of vertices from a VertexBuffer.

Returns:

  • (self)

#generate_mipmap ⇒ Boolean

Generates the mipmap pyramid for the texture.

Returns:

  • (Boolean)

Returns:

  • (Boolean) —

    whether mipmap generation succeeded



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.

Returns:

#map_pixel_to_coords(point, view = nil) ⇒ Vector2

Converts a pixel position to world coordinates, using the inverse of the view transform.

Returns:

#pop_gl_states ⇒ self

Restores the OpenGL states saved by #push_gl_states.

Returns:

  • (self)

#push_gl_states ⇒ self

Saves the current OpenGL states before custom drawing.

Returns:

  • (self)

#repeated=(value) ⇒ Boolean

Enables or disables texture repeating.

Returns:

  • (Boolean)

Returns:

  • (Boolean) —

    value



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.

Returns:

  • (Boolean)

Returns:

  • (Boolean)


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.

Returns:

  • (self)

#scissor(view = nil) ⇒ Rect

Returns the current scissor rectangle in pixels; view defaults to the target's current view.

Returns:

  • (Rect) —

    the current scissor rectangle in pixels; view defaults to the target's current

#size ⇒ Vector2

Returns the object's size.

Returns:

Returns:



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.

Returns:

  • (Boolean)

Returns:

  • (Boolean) —

    value



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.

Returns:

  • (Boolean)

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)

#texture ⇒ Texture

Returns the target texture, whose contents update after each #display.

Returns:

Returns:

  • (Texture) —

    the target texture, borrowed -- its 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.

Returns:

Returns:

  • (View) —

    a copy of the 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.

Returns:

  • (self)

Returns:

  • (self)

Raises:

  • (TypeError) —

    if value is not a 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.

Returns:

  • (Rect) —

    the current viewport in pixels; view defaults to the target's current view