Class: SDL2::Renderer

Inherits:
Object
  • Object
show all
Defined in:
ext/sdl2_ext/video.c,
ext/sdl2_ext/video.c

Overview

This class represents a 2D rendering context for a window.

You can create a renderer using Window#create_renderer and use it to draw figures on the window.

Defined Under Namespace

Modules: Flags Classes: Info

Constant Summary collapse

FLIP_NONE =

Do not flip, used in #copy_ex

INT2FIX(SDL_FLIP_NONE)
FLIP_HORIZONTAL =

Flip horizontally, used in #copy_ex

INT2FIX(SDL_FLIP_HORIZONTAL)
FLIP_VERTICAL =

Flip vertically, used in #copy_ex

INT2FIX(SDL_FLIP_VERTICAL)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.drivers_infoArray<SDL2::Renderer::Info>

Return information of all available rendering contexts.

Returns:



1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
# File 'ext/sdl2_ext/video.c', line 1192

static VALUE Renderer_s_drivers_info(VALUE self)
{
    int num_drivers = SDL_GetNumRenderDrivers();
    VALUE info_ary = rb_ary_new();
    int i;
    for (i=0; i<num_drivers; ++i) {
        SDL_RendererInfo info;
        HANDLE_ERROR(SDL_GetRenderDriverInfo(i, &info));
        rb_ary_push(info_ary, RendererInfo_new(&info));
    }
    return info_ary;
}

Instance Method Details

#clearnil

Crear the rendering target with the drawing color.

Returns:

  • (nil)

See Also:



1358
1359
1360
1361
1362
# File 'ext/sdl2_ext/video.c', line 1358

static VALUE Renderer_clear(VALUE self)
{
    HANDLE_ERROR(SDL_RenderClear(Get_SDL_Renderer(self)));
    return Qnil;
}

#clip_enabled?Boolean

Note:

This method is available since SDL 2.0.4.

Get whether clipping is enabled on the renderer.

Returns:

  • (Boolean)


1559
1560
1561
1562
# File 'ext/sdl2_ext/video.c', line 1559

static VALUE Render_clip_enabled_p(VALUE self)
{
    return INT2BOOL(SDL_RenderIsClipEnabled(Get_SDL_Renderer(self)));
}

#clip_rectSDL2::Rect

Get the clip rectangle for the current target.

Returns:

See Also:

  • SDL2::Renderer.{{#clip_rect=}


1532
1533
1534
1535
1536
1537
# File 'ext/sdl2_ext/video.c', line 1532

static VALUE Renderer_clip_rect(VALUE self)
{
    VALUE rect = rb_obj_alloc(cRect);
    SDL_RenderGetClipRect(Get_SDL_Renderer(self), Get_SDL_Rect(rect));
    return rect;
}

#clip_rect=(rect) ⇒ rect

Set the clip rectangle for the current target.

Returns:

  • (rect)

See Also:



1547
1548
1549
1550
1551
# File 'ext/sdl2_ext/video.c', line 1547

static VALUE Renderer_set_clip_rect(VALUE self, VALUE rect)
{
    HANDLE_ERROR(SDL_RenderSetClipRect(Get_SDL_Renderer(self), Get_SDL_Rect(rect)));
    return rect;
}

#copy(texture, srcrect, dstrect) ⇒ void

This method returns an undefined value.

Copy a portion of the texture to the current rendering target.

Parameters:

  • texture (SDL2::Texture)

    the source texture

  • srcrect (SDL2::Rect, nil)

    the source rectangle, or nil for the entire texture

  • dstrect (SDL2::Rect, nil)

    the destination rectangle, or nil for the entire rendering target; the texture will be stretched to fill the given rectangle

See Also:



1293
1294
1295
1296
1297
1298
1299
1300
# File 'ext/sdl2_ext/video.c', line 1293

static VALUE Renderer_copy(VALUE self, VALUE texture, VALUE srcrect, VALUE dstrect)
{
    HANDLE_ERROR(SDL_RenderCopy(Get_SDL_Renderer(self),
                                Get_SDL_Texture(texture),
                                Get_SDL_Rect_or_NULL(srcrect),
                                Get_SDL_Rect_or_NULL(dstrect)));
    return Qnil;
}

#copy_ex(texture, srcrect, dstrect, angle, center, flip) ⇒ void

This method returns an undefined value.

Copy a portion of the texture to the current rendering target, rotating it by angle around the given center and also flipping it top-bottom and/or left-right.

You can use the following constants to specify the horizontal/vertical flip:

Parameters:

  • texture (SDL2::Texture)

    the source texture

  • srcrect (SDL2::Rect, nil)

    the source rectangle, or nil for the entire texture

  • dstrect (SDL2::Rect, nil)

    the destination rectangle, or nil for the entire rendering target; the texture will be stretched to fill the given rectangle

  • angle (Float)

    an angle in degree indicating the rotation that will be applied to dstrect

  • center (SDL2::Point, nil)

    the point around which dstrect will be rotated, (if nil, rotation will be done around the center of dstrect)

  • flip (Integer)

    bits OR'd of the flip consntants

See Also:



1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
# File 'ext/sdl2_ext/video.c', line 1329

static VALUE Renderer_copy_ex(VALUE self, VALUE texture, VALUE srcrect, VALUE dstrect,
                              VALUE angle, VALUE center, VALUE flip)
{
    HANDLE_ERROR(SDL_RenderCopyEx(Get_SDL_Renderer(self),
                                  Get_SDL_Texture(texture),
                                  Get_SDL_Rect_or_NULL(srcrect),
                                  Get_SDL_Rect_or_NULL(dstrect),
                                  NUM2DBL(angle),
                                  Get_SDL_Point_or_NULL(center),
                                  NUM2INT(flip)));
    return Qnil;
}

#create_texture(format, access, w, h) ⇒ SDL2::Texture

Create a new texture for the rendering context.

You can use the following constants to specify access pattern

Parameters:

  • format (SDL2::PixelFormat, Integer)

    format of the texture

  • access (Integer)

    texture access pattern

  • w (Integer)

    the width ofthe texture in pixels

  • h (Integer)

    the height ofthe texture in pixels

Returns:

Raises:

  • (SDL2::Error)

    raised when the texture cannot be created

See Also:



1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
# File 'ext/sdl2_ext/video.c', line 1238

static VALUE Renderer_create_texture(VALUE self, VALUE format, VALUE access,
                                     VALUE w, VALUE h)
{
    SDL_Texture* texture = SDL_CreateTexture(Get_SDL_Renderer(self),
                                             uint32_for_format(format),
                                             NUM2INT(access), NUM2INT(w), NUM2INT(h));
    if (!texture)
        SDL_ERROR();
    return Texture_new(texture, Get_Renderer(self));
}

#create_texture_from(surface) ⇒ SDL2::Texture

Create a texture from an existing surface.

Parameters:

  • surface (SDL2::Surface)

    the surface containing pixels for the texture

Returns:

Raises:

  • (SDL2::Error)

    raised when the texture cannot be created

See Also:



1260
1261
1262
1263
1264
1265
1266
1267
1268
# File 'ext/sdl2_ext/video.c', line 1260

static VALUE Renderer_create_texture_from(VALUE self, VALUE surface)
{
    SDL_Texture* texture = SDL_CreateTextureFromSurface(Get_SDL_Renderer(self),
                                                        Get_SDL_Surface(surface));
    if (texture == NULL)
        SDL_ERROR();

    return Texture_new(texture, Get_Renderer(self));
}

#debug_infoHash<String=>Object>

Returns (GC) debug information.

Returns:

  • (Hash<String=>Object>)

    (GC) debug information



1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
# File 'ext/sdl2_ext/video.c', line 1733

static VALUE Renderer_debug_info(VALUE self)
{
    Renderer* r = Get_Renderer(self);
    VALUE info = rb_hash_new();
    int num_active_textures = 0;
    int i;
    rb_hash_aset(info, rb_str_new2("destroy?"), INT2BOOL(r->renderer == NULL));
    rb_hash_aset(info, rb_str_new2("max_textures"), INT2NUM(r->max_textures));
    rb_hash_aset(info, rb_str_new2("num_textures"), INT2NUM(r->num_textures));
    for (i=0; i<r->num_textures; ++i)
        if (r->textures[i]->texture)
            ++num_active_textures;
    rb_hash_aset(info, rb_str_new2("num_active_textures"), INT2NUM(num_active_textures));
    rb_hash_aset(info, rb_str_new2("refcount"), INT2NUM(r->refcount));

    return info;
}

#destroynil

Destroy the rendering context and free associated textures.

Returns:

  • (nil)

See Also:



1211
1212
1213
1214
1215
# File 'ext/sdl2_ext/video.c', line 1211

static VALUE Renderer_destroy(VALUE self)
{
    Renderer_destroy_internal(Get_Renderer(self));
    return Qnil;
}

#destroy?Boolean

Return true if the renderer is destroyed.

Returns:

  • (Boolean)

#draw_arc(x, y, rad, start, end) ⇒ Object

Arc with blending.



1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
# File 'ext/sdl2_ext/video.c', line 1936

static VALUE Renderer_draw_arc(VALUE self, VALUE x, VALUE y, VALUE rad, VALUE start, VALUE end)
{
    SDL_BlendMode mode;
    Uint8 r, g, b, a;
    HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
    HANDLE_ERROR(SDL_GetRenderDrawColor(Get_SDL_Renderer(self), &r, &g, &b, &a));
    HANDLE_ERROR(arcRGBA(Get_SDL_Renderer(self), NUM2INT(x), NUM2INT(y), NUM2INT(rad), NUM2INT(start), NUM2INT(end), r, g, b, a));
    HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), mode));
    return Qnil;
}

#draw_blend_modeInteger

Get the blend mode used for drawing operations like #fill_rect and #draw_line.

Returns:

  • (Integer)

See Also:



1495
1496
1497
1498
1499
1500
# File 'ext/sdl2_ext/video.c', line 1495

static VALUE Renderer_draw_blend_mode(VALUE self)
{
    SDL_BlendMode mode;
    HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
    return INT2FIX(mode);
}

#draw_blend_mode=(mode) ⇒ Object

Set the blend mode used for drawing operations.

This method effects the following methods.

Parameters:

  • mode (Integer)

    the blending mode

Returns:

  • mode

See Also:



1520
1521
1522
1523
1524
# File 'ext/sdl2_ext/video.c', line 1520

static VALUE Renderer_set_draw_blend_mode(VALUE self, VALUE mode)
{
    HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), NUM2INT(mode)));
    return mode;
}

#draw_color[Integer,Integer,Integer,Integer]

Get the color used for drawing operations

Returns:

  • ([Integer,Integer,Integer,Integer])

    red, green, blue, and alpha components of the drawing color (all components are more than or equal to 0 and less than and equal to 255)

See Also:



1372
1373
1374
1375
1376
1377
# File 'ext/sdl2_ext/video.c', line 1372

static VALUE Renderer_draw_color(VALUE self)
{
    Uint8 r, g, b, a;
    HANDLE_ERROR(SDL_GetRenderDrawColor(Get_SDL_Renderer(self), &r, &g, &b, &a));
    return rb_ary_new3(4, INT2FIX(r), INT2FIX(g), INT2FIX(b), INT2FIX(a));
}

#draw_color=(color) ⇒ color

Set the color used for drawing operations

All color components (including alpha) must be more than or equal to 0 and less than and equal to 255

This method effects the following methods.

Parameters:

  • color (Integer)

    red, green, and blue components used for drawing

  • color ([Integer, Integer, Integer, Integer])

    red, green, blue, and alpha components used for drawing

Returns:

  • (color)

See Also:



1403
1404
1405
1406
1407
1408
1409
1410
1411
# File 'ext/sdl2_ext/video.c', line 1403

static VALUE Renderer_set_draw_color(VALUE self, VALUE rgba)
{
    SDL_Color color = Color_to_SDL_Color(rgba);

    HANDLE_ERROR(SDL_SetRenderDrawColor(Get_SDL_Renderer(self),
                                        color.r, color.g, color.b, color.a));

    return rgba;
}

#draw_ellipse(x, y, rx, ry) ⇒ Object

Draw ellipse with blending.



1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
# File 'ext/sdl2_ext/video.c', line 1948

static VALUE Renderer_draw_ellipse(VALUE self, VALUE x, VALUE y, VALUE rx, VALUE ry)
{
    SDL_BlendMode mode;
    Uint8 r, g, b, a;
    HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
    HANDLE_ERROR(SDL_GetRenderDrawColor(Get_SDL_Renderer(self), &r, &g, &b, &a));
    HANDLE_ERROR(ellipseRGBA(Get_SDL_Renderer(self), NUM2INT(x), NUM2INT(y), NUM2INT(rx), NUM2INT(ry), r, g, b, a));
    HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), mode));
    return Qnil;
}

#draw_ellipse_aa(x, y, rx, ry) ⇒ Object

Draw anti-aliased ellipse with blending.



1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
# File 'ext/sdl2_ext/video.c', line 1960

static VALUE Renderer_draw_ellipse_aa(VALUE self, VALUE x, VALUE y, VALUE rx, VALUE ry)
{
    SDL_BlendMode mode;
    Uint8 r, g, b, a;
    HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
    HANDLE_ERROR(SDL_GetRenderDrawColor(Get_SDL_Renderer(self), &r, &g, &b, &a));
    HANDLE_ERROR(aaellipseRGBA(Get_SDL_Renderer(self), NUM2INT(x), NUM2INT(y), NUM2INT(rx), NUM2INT(ry), r, g, b, a));
    HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), mode));
    return Qnil;
}

#draw_line(x1, y1, x2, y2) ⇒ nil

Draw a line from (x1, y1) to (x2, y2) using drawing color given by #draw_color=.

Parameters:

  • x1 (Integer)

    the x coordinate of the start point

  • y1 (Integer)

    the y coordinate of the start point

  • x2 (Integer)

    the x coordinate of the end point

  • y2 (Integer)

    the y coordinate of the end point

Returns:

  • (nil)


1424
1425
1426
1427
1428
1429
# File 'ext/sdl2_ext/video.c', line 1424

static VALUE Renderer_draw_line(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
{
    HANDLE_ERROR(SDL_RenderDrawLine(Get_SDL_Renderer(self),
                                    NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2)));
    return Qnil;
}

#draw_line_aa(x1, y1, x2, y2) ⇒ Object

Draw anti-aliased line with alpha blending.



1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
# File 'ext/sdl2_ext/video.c', line 1752

static VALUE Renderer_draw_line_aa(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
{
    SDL_BlendMode mode;
    Uint8 r, g, b, a;
    HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
    HANDLE_ERROR(SDL_GetRenderDrawColor(Get_SDL_Renderer(self), &r, &g, &b, &a));
    HANDLE_ERROR(aalineRGBA(Get_SDL_Renderer(self), NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2), r, g, b, a));
    HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), mode));
    return Qnil;
}

#draw_line_thick(x1, y1, x2, y2, width) ⇒ Object

Draw a thick line with alpha blending.



1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
# File 'ext/sdl2_ext/video.c', line 1764

static VALUE Renderer_draw_line_thick(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE width)
{
    SDL_BlendMode mode;
    Uint8 r, g, b, a;
    HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
    HANDLE_ERROR(SDL_GetRenderDrawColor(Get_SDL_Renderer(self), &r, &g, &b, &a));
    HANDLE_ERROR(thickLineRGBA(Get_SDL_Renderer(self), NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2), NUM2INT(width), r, g, b, a));
    HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), mode));
    return Qnil;
}

#draw_pie(x, y, rad, start, end) ⇒ Object

Draw pie (outline) with alpha blending.



1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
# File 'ext/sdl2_ext/video.c', line 1984

static VALUE Renderer_draw_pie(VALUE self, VALUE x, VALUE y, VALUE rad, VALUE start, VALUE end)
{
    SDL_BlendMode mode;
    Uint8 r, g, b, a;
    HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
    HANDLE_ERROR(SDL_GetRenderDrawColor(Get_SDL_Renderer(self), &r, &g, &b, &a));
    HANDLE_ERROR(pieRGBA(Get_SDL_Renderer(self), NUM2INT(x), NUM2INT(y), NUM2INT(rad), NUM2INT(start), NUM2INT(end), r, g, b, a));
    HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), mode));
    return Qnil;
}

#draw_point(x, y) ⇒ nil

Draw a point at (x, y) using drawing color given by #draw_color=.

Parameters:

  • x (Integer)

    the x coordinate of the point

  • y (Integer)

    the y coordinate of the point

Returns:

  • (nil)


1440
1441
1442
1443
1444
# File 'ext/sdl2_ext/video.c', line 1440

static VALUE Renderer_draw_point(VALUE self, VALUE x, VALUE y)
{
    HANDLE_ERROR(SDL_RenderDrawPoint(Get_SDL_Renderer(self), NUM2INT(x), NUM2INT(y)));
    return Qnil;
}

#draw_polygon(vertices_x, vertices_y) ⇒ Object

Draw polygon with the currently set color and blend mode.



1865
1866
1867
1868
# File 'ext/sdl2_ext/video.c', line 1865

static VALUE Renderer_draw_polygon(VALUE self, VALUE vertices_x, VALUE vertices_y)
{
    return Renderer_draw_polygon_generic(self, vertices_x, vertices_y, polygonRGBA);
}

#draw_polygon_aa(vertices_x, vertices_y) ⇒ Object

Draw anti-aliased polygon with alpha blending.



1871
1872
1873
1874
# File 'ext/sdl2_ext/video.c', line 1871

static VALUE Renderer_draw_polygon_aa(VALUE self, VALUE vertices_x, VALUE vertices_y)
{
    return Renderer_draw_polygon_generic(self, vertices_x, vertices_y, aapolygonRGBA);
}

#draw_quad_bezier(x1, y1, x2, y2, x3, y3, x4, y4, resolution) ⇒ Object

Draw a cubic bezier curve with alpha blending.



2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
# File 'ext/sdl2_ext/video.c', line 2216

static VALUE Renderer_draw_quad_bezier(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3, VALUE x4, VALUE y4, VALUE resolution)
{
    SDL_BlendMode mode;
    Uint8 r, g, b, a;
    Sint16 vx[] = { NUM2INT(x1), NUM2INT(x2), NUM2INT(x3), NUM2INT(x4) };
    Sint16 vy[] = { NUM2INT(y1), NUM2INT(y2), NUM2INT(y3), NUM2INT(y4) };
    HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
    HANDLE_ERROR(SDL_GetRenderDrawColor(Get_SDL_Renderer(self), &r, &g, &b, &a));
    HANDLE_ERROR(bezierRGBA(Get_SDL_Renderer(self), vx, vy, 4, NUM2INT(resolution), r, g, b, a));
    HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), mode));
    return Qnil;
}

#draw_rect(rect) ⇒ nil

Draw a rectangle using drawing color given by #draw_color=.

Parameters:

Returns:

  • (nil)


1454
1455
1456
1457
1458
# File 'ext/sdl2_ext/video.c', line 1454

static VALUE Renderer_draw_rect(VALUE self, VALUE rect)
{
    HANDLE_ERROR(SDL_RenderDrawRect(Get_SDL_Renderer(self), Get_SDL_Rect(rect)));
    return Qnil;
}

#draw_rounded_rect(x, y, w, h, rad) ⇒ Object

Draw rounded-corner rectangle with blending.



2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
# File 'ext/sdl2_ext/video.c', line 2011

static VALUE Renderer_draw_rounded_rect(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h, VALUE rad)
{
    SDL_BlendMode mode;
    Uint8 r, g, b, a;
    HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
    HANDLE_ERROR(SDL_GetRenderDrawColor(Get_SDL_Renderer(self), &r, &g, &b, &a));
    HANDLE_ERROR(internal_roundedRectangleRGBA(Get_SDL_Renderer(self),
        NUM2INT(x), NUM2INT(y),
        NUM2INT(x) + NUM2INT(w), NUM2INT(y) + NUM2INT(h),
        NUM2INT(rad), r, g, b, a));
    HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), mode));
    return Qnil;
}

#draw_triangle(x1, y1, x2, y2, x3, y3) ⇒ Object

Draw trigon (triangle outline) with alpha blending.



1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
# File 'ext/sdl2_ext/video.c', line 1776

static VALUE Renderer_draw_triangle(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3)
{
    SDL_BlendMode mode;
    Uint8 r, g, b, a;
    HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
    HANDLE_ERROR(SDL_GetRenderDrawColor(Get_SDL_Renderer(self), &r, &g, &b, &a));
    HANDLE_ERROR(trigonRGBA(Get_SDL_Renderer(self), NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2), NUM2INT(x3), NUM2INT(y3), r, g, b, a));
    HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), mode));
    return Qnil;
}

#draw_triangle_aa(x1, y1, x2, y2, x3, y3) ⇒ Object

Draw anti-aliased trigon (triangle outline) with alpha blending.



1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
# File 'ext/sdl2_ext/video.c', line 1788

static VALUE Renderer_draw_triangle_aa(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3)
{
    SDL_BlendMode mode;
    Uint8 r, g, b, a;
    HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
    HANDLE_ERROR(SDL_GetRenderDrawColor(Get_SDL_Renderer(self), &r, &g, &b, &a));
    HANDLE_ERROR(aatrigonRGBA(Get_SDL_Renderer(self), NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2), NUM2INT(x3), NUM2INT(y3), r, g, b, a));
    HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), mode));
    return Qnil;
}

#fill_ellipse(x, y, rx, ry) ⇒ Object

Draw filled ellipse with blending.



1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
# File 'ext/sdl2_ext/video.c', line 1972

static VALUE Renderer_fill_ellipse(VALUE self, VALUE x, VALUE y, VALUE rx, VALUE ry)
{
    SDL_BlendMode mode;
    Uint8 r, g, b, a;
    HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
    HANDLE_ERROR(SDL_GetRenderDrawColor(Get_SDL_Renderer(self), &r, &g, &b, &a));
    HANDLE_ERROR(filledEllipseRGBA(Get_SDL_Renderer(self), NUM2INT(x), NUM2INT(y), NUM2INT(rx), NUM2INT(ry), r, g, b, a));
    HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), mode));
    return Qnil;
}

#fill_pie(x, y, rad, start, end) ⇒ Object

Draw filled pie with alpha blending.



1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
# File 'ext/sdl2_ext/video.c', line 1996

static VALUE Renderer_fill_pie(VALUE self, VALUE x, VALUE y, VALUE rad, VALUE start, VALUE end)
{
    SDL_BlendMode mode;
    Uint8 r, g, b, a;
    HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
    HANDLE_ERROR(SDL_GetRenderDrawColor(Get_SDL_Renderer(self), &r, &g, &b, &a));
    HANDLE_ERROR(filledPieRGBA(Get_SDL_Renderer(self), NUM2INT(x), NUM2INT(y), NUM2INT(rad), NUM2INT(start), NUM2INT(end), r, g, b, a));
    HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), mode));
    return Qnil;
    return Qnil;
}

#fill_polygon(vertices_x, vertices_y) ⇒ Object

Draw filled polygon with alpha blending.



1877
1878
1879
1880
# File 'ext/sdl2_ext/video.c', line 1877

static VALUE Renderer_fill_polygon(VALUE self, VALUE vertices_x, VALUE vertices_y)
{
    return Renderer_draw_polygon_generic(self, vertices_x, vertices_y, filledPolygonRGBA);
}

#fill_polygon_textured(vertices_x, vertices_y, surface, surface_dx, surface_dy) ⇒ Object

Draws a polygon filled with the given texture.



1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
# File 'ext/sdl2_ext/video.c', line 1910

static VALUE Renderer_fill_polygon_textured(VALUE self, VALUE vertices_x, VALUE vertices_y, VALUE surface, VALUE surface_dx, VALUE surface_dy)
{
    struct draw_polygon_textured_closure closure;

    Check_Type(vertices_x, T_ARRAY);
    Check_Type(vertices_y, T_ARRAY);

    closure.renderer = Get_SDL_Renderer(self);
    closure.texture = Get_SDL_Surface(surface);
    closure.texture_dx = NUM2INT(surface_dx);
    closure.texture_dy = NUM2INT(surface_dy);

    closure.point_count = RARRAY_LEN(vertices_x);
    if (RARRAY_LEN(vertices_y) == closure.point_count)
        rb_raise(rb_eArgError, "Both arrays must be of same size");
    closure.vx = ruby_xmalloc2(closure.point_count, sizeof(*closure.vx));
    closure.vy = ruby_xmalloc2(closure.point_count, sizeof(*closure.vy));
    for (long i = 0; i < closure.point_count; i++) {
        closure.vx[i] = NUM2INT(rb_ary_entry(vertices_x, i));
        closure.vy[i] = NUM2INT(rb_ary_entry(vertices_y, i));
    }

    return rb_ensure(draw_polygon_textured, (VALUE) &closure, draw_polygon_textured_cleanup, (VALUE) &closure);
}

#fill_rect(rect) ⇒ nil

Draw a filled rectangle using drawing color given by #draw_color=.

Parameters:

Returns:

  • (nil)


1468
1469
1470
1471
1472
# File 'ext/sdl2_ext/video.c', line 1468

static VALUE Renderer_fill_rect(VALUE self, VALUE rect)
{
    HANDLE_ERROR(SDL_RenderFillRect(Get_SDL_Renderer(self), Get_SDL_Rect(rect)));
    return Qnil;
}

#fill_rounded_rect(x, y, w, h, rad) ⇒ Object

Draw rounded-corner box (filled rectangle) with blending.



2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
# File 'ext/sdl2_ext/video.c', line 2101

static VALUE Renderer_fill_rounded_rect(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h, VALUE rad)
{
    SDL_BlendMode mode;
    Uint8 r, g, b, a;
    HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
    HANDLE_ERROR(SDL_GetRenderDrawColor(Get_SDL_Renderer(self), &r, &g, &b, &a));
    HANDLE_ERROR(internal_roundedBoxRGBA(Get_SDL_Renderer(self),
        NUM2INT(x), NUM2INT(y),
        NUM2INT(x) + NUM2INT(w), NUM2INT(y) + NUM2INT(h),
        NUM2INT(rad), r, g, b, a));
    HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), mode));
    return Qnil;
}

#fill_triangle(x1, y1, x2, y2, x3, y3) ⇒ Object

Draw filled trigon (triangle) with alpha blending.



1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
# File 'ext/sdl2_ext/video.c', line 1800

static VALUE Renderer_fill_triangle(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3)
{
    SDL_BlendMode mode;
    Uint8 r, g, b, a;
    HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
    HANDLE_ERROR(SDL_GetRenderDrawColor(Get_SDL_Renderer(self), &r, &g, &b, &a));
    HANDLE_ERROR(filledTrigonRGBA(Get_SDL_Renderer(self), NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2), NUM2INT(x3), NUM2INT(y3), r, g, b, a));
    HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), mode));
    return Qnil;
}

#infoSDL2::Renderer::Info

Get information about self rendering context .

Returns:



1479
1480
1481
1482
1483
1484
# File 'ext/sdl2_ext/video.c', line 1479

static VALUE Renderer_info(VALUE self)
{
    SDL_RendererInfo info;
    HANDLE_ERROR(SDL_GetRendererInfo(Get_SDL_Renderer(self), &info));
    return RendererInfo_new(&info);
}

#load_texture(file) ⇒ SDL2::Texture

Load file and create a new Texture.

This method uses SDL_image. SDL_image supports following formats: BMP, CUR, GIF, ICO, JPG, LBP, PCX, PNG, PNM, TGA, TIF, XCF, XPM, and XV.

Parameters:

  • file (String)

    the image file name to load a texture from

Returns:

Raises:

  • (SDL2::Error)

    raised when you fail to load (for example, you have a wrong file name, or the file is broken)

See Also:



4060
4061
4062
4063
4064
4065
4066
4067
4068
# File 'ext/sdl2_ext/video.c', line 4060

static VALUE Renderer_load_texture(VALUE self, VALUE fname)
{
    SDL_Texture* texture = IMG_LoadTexture(Get_SDL_Renderer(self), StringValueCStr(fname));
    if (!texture) {
        SDL_SetError("%s", IMG_GetError());
        SDL_ERROR();
    }
    return Texture_new(texture, Get_Renderer(self));
}

#logical_size[Integer, Integer]

Get device indepndent resolution for rendering.

Returns:

  • ([Integer, Integer])

    the logical width and height

See Also:



1571
1572
1573
1574
1575
1576
# File 'ext/sdl2_ext/video.c', line 1571

static VALUE Renderer_logical_size(VALUE self)
{
    int w, h;
    SDL_RenderGetLogicalSize(Get_SDL_Renderer(self), &w, &h);
    return rb_ary_new3(2, INT2FIX(w), INT2FIX(h));
}

#logical_size=(w_and_h) ⇒ w_and_h

Set a device indepndent resolution for rendering.

Parameters:

  • w_and_h ([Integer, Integer])

    the width and height of the logical resolution

Returns:

  • (w_and_h)

See Also:



1587
1588
1589
1590
1591
1592
1593
# File 'ext/sdl2_ext/video.c', line 1587

static VALUE Renderer_set_logical_size(VALUE self, VALUE wh)
{
    HANDLE_ERROR(SDL_RenderSetLogicalSize(Get_SDL_Renderer(self),
                                          NUM2DBL(rb_ary_entry(wh, 0)),
                                          NUM2DBL(rb_ary_entry(wh, 1))));
    return wh;
}

#output_size[Integer, Integer]

Get the output size of a rendering context.

Returns:

  • ([Integer, Integer])

    the width and the height



1675
1676
1677
1678
1679
1680
# File 'ext/sdl2_ext/video.c', line 1675

static VALUE Renderer_output_size(VALUE self)
{
    int w, h;
    HANDLE_ERROR(SDL_GetRendererOutputSize(Get_SDL_Renderer(self), &w, &h));
    return rb_ary_new3(2, INT2FIX(w), INT2FIX(h));
}

#presentnil

Update the screen with rendering performed

Returns:

  • (nil)


1346
1347
1348
1349
1350
# File 'ext/sdl2_ext/video.c', line 1346

static VALUE Renderer_present(VALUE self)
{
    SDL_RenderPresent(Get_SDL_Renderer(self));
    return Qnil;
}

#render_targetSDL2::Texture?

Get the current render target.

Returns:

  • (SDL2::Texture)

    the current rendering target

  • (nil)

    for the default render target (i.e. screen)

See Also:



1717
1718
1719
1720
# File 'ext/sdl2_ext/video.c', line 1717

static VALUE Renderer_render_target(VALUE self)
{
    return rb_iv_get(self, "render_target");
}

#render_target=(target) ⇒ target

Set a texture as the current render target.

Some renderers have ability to render to a texture instead of a screen. You can judge whether your renderer has this ability using #support_render_target?.

The target texture musbe be created with the Texture::ACCESS_TARGET flag.

Parameters:

  • target (SDL2::Texture, nil)

    the targeted texture, or nil for the default render target(i.e. screen)

Returns:

  • (target)

See Also:



1700
1701
1702
1703
1704
1705
1706
# File 'ext/sdl2_ext/video.c', line 1700

static VALUE Renderer_set_render_target(VALUE self, VALUE target)
{
    HANDLE_ERROR(SDL_SetRenderTarget(Get_SDL_Renderer(self),
                                     (target == Qnil) ? NULL : Get_SDL_Texture(target)));
    rb_iv_set(self, "render_target", target);
    return target;
}

#reset_render_targetnil

Reset the render target to the screen.

Returns:

  • (nil)


1727
1728
1729
1730
# File 'ext/sdl2_ext/video.c', line 1727

static VALUE Renderer_reset_render_target(VALUE self)
{
    return Renderer_set_render_target(self, Qnil);
}

#scale[Integer, Integer]

Get the drawing scale for the current target.

Returns:

  • ([Integer, Integer])

    horizontal and vertical scale factor

See Also:



1601
1602
1603
1604
1605
1606
# File 'ext/sdl2_ext/video.c', line 1601

static VALUE Renderer_scale(VALUE self)
{
    float scaleX, scaleY;
    SDL_RenderGetScale(Get_SDL_Renderer(self), &scaleX, &scaleY);
    return rb_ary_new3(2, DBL2NUM(scaleX), DBL2NUM(scaleY));
}

#scale=(scaleX_and_scaleY) ⇒ scaleX_and_scaleY

Set the drawing scale for rendering.

The drawing coordinates are scaled by the x/y scaling factors before they are used by the renderer. This allows resolution independent drawing with a single coordinate system.

If this results in scaling or subpixel drawing by the rendering backend, it will be handled using the appropriate quality hints. For best results use integer scaling factors.

Parameters:

  • scaleX_and_scaleY ([Float, Float])

    the horizontal and vertical scaling factors

Returns:

  • (scaleX_and_scaleY)

See Also:



1624
1625
1626
1627
1628
1629
1630
1631
# File 'ext/sdl2_ext/video.c', line 1624

static VALUE Renderer_set_scale(VALUE self, VALUE xy)
{
    float scaleX, scaleY;
    scaleX = NUM2DBL(rb_ary_entry(xy, 0));
    scaleY = NUM2DBL(rb_ary_entry(xy, 1));
    HANDLE_ERROR(SDL_RenderSetScale(Get_SDL_Renderer(self), scaleX, scaleY));
    return xy;
}

#support_render_target?Boolean

Return true if the renderer supports render target.

Returns:

  • (Boolean)

See Also:



1665
1666
1667
1668
# File 'ext/sdl2_ext/video.c', line 1665

static VALUE Renderer_support_render_target_p(VALUE self)
{
    return INT2BOOL(SDL_RenderTargetSupported(Get_SDL_Renderer(self)));
}

#viewportSDL2::Rect

Get the drawing area for the current target.

Returns:

See Also:



1639
1640
1641
1642
1643
1644
# File 'ext/sdl2_ext/video.c', line 1639

static VALUE Renderer_viewport(VALUE self)
{
    VALUE rect = rb_obj_alloc(cRect);
    SDL_RenderGetViewport(Get_SDL_Renderer(self), Get_SDL_Rect(rect));
    return rect;
}

#viewport=(area) ⇒ area

Set the drawing area for rendering on the current target.

Parameters:

  • area (SDL2::Rect, nil)

    the drawing area, or nil to set the viewport to the entire target

Returns:

  • (area)

See Also:



1654
1655
1656
1657
1658
# File 'ext/sdl2_ext/video.c', line 1654

static VALUE Renderer_set_viewport(VALUE self, VALUE rect)
{
    HANDLE_ERROR(SDL_RenderSetClipRect(Get_SDL_Renderer(self), Get_SDL_Rect_or_NULL(rect)));
    return rect;
}