Class: SDL2::Renderer
- Inherits:
-
Object
- Object
- SDL2::Renderer
- Defined in:
- video.c,
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
Class Method Summary (collapse)
-
+ (Array<SDL2::Renderer::Info>) drivers_info
Return information of all available rendering contexts.
Instance Method Summary (collapse)
-
- (nil) clear
Crear the rendering target with the drawing color.
- - (Boolean) clip_enabled?
-
- (SDL2::Rect) clip_rect
Get the clip rectangle for the current target.
-
- (void) copy(texture, srcrect, dstrect)
Copy a portion of the texture to the current rendering target.
-
- (void) copy_ex(texture, srcrect, dstrect, angle, center, flip)
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.
-
- (SDL2::Texture) create_texture(format, access, w, h)
Create a new texture for the rendering context.
-
- (SDL2::Texture) create_texture_from(surface)
Create a texture from an existing surface.
-
- (Hash<String=>Object>) debug_info
(GC) debug information.
-
- (nil) destroy
Destroy the rendering context and free associated textures.
-
- (Boolean) destroy?
Return true if the renderer is destroyed.
-
- (Integer) draw_blend_mode
Get the blend mode used for drawing operations like #fill_rect and #draw_line.
-
- (Object) draw_blend_mode=(mode)
Set the blend mode used for drawing operations.
-
- ([Integer,Integer,Integer,Integer]) draw_color
Get the color used for drawing operations.
-
- (color) draw_color=(color)
Set the color used for drawing operations.
-
- (nil) draw_line(x1, y1, x2, y2)
Draw a line from (x1, y1) to (x2, y2) using drawing color given by #draw_color=.
-
- (nil) draw_point(x, y)
Draw a point at (x, y) using drawing color given by #draw_color=.
-
- (nil) draw_rect(rect)
Draw a rectangle using drawing color given by #draw_color=.
-
- (nil) fill_rect(rect)
Draw a filled rectangle using drawing color given by #draw_color=.
-
- (SDL2::Renderer::Info) info
Get information about self rendering context .
-
- (SDL2::Texture) load_texture(file)
Load file and create a new Texture.
- - (Object) logical_size
- - (Object) output_size
-
- (nil) present
Update the screen with rendering performed.
-
- (SDL2::Texture?) render_target
Get the current render target.
-
- (target) render_target=(target)
Set a texture as the current render target.
-
- (nil) reset_render_target
Reset the render target to the screen.
- - (Object) scale
-
- (Boolean) support_render_target?
Return true if the renderer supports render target.
- - (Object) viewport
Class Method Details
+ (Array<SDL2::Renderer::Info>) drivers_info
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 |
# File 'video.c', line 1162
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
- (nil) clear
Crear the rendering target with the drawing color.
1328 1329 1330 1331 1332 |
# File 'video.c', line 1328
static VALUE Renderer_clear(VALUE self)
{
HANDLE_ERROR(SDL_RenderClear(Get_SDL_Renderer(self)));
return Qnil;
}
|
- (Boolean) clip_enabled?
1510 1511 1512 1513 |
# File 'video.c', line 1510
static VALUE Render_clip_enabled_p(VALUE self)
{
return INT2BOOL(SDL_RenderIsClipEnabled(Get_SDL_Renderer(self)));
}
|
- (SDL2::Rect) clip_rect
Get the clip rectangle for the current target.
1502 1503 1504 1505 1506 1507 |
# File 'video.c', line 1502
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;
}
|
- (void) copy(texture, srcrect, dstrect)
1263 1264 1265 1266 1267 1268 1269 1270 |
# File 'video.c', line 1263
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;
}
|
- (void) copy_ex(texture, srcrect, dstrect, angle, center, flip)
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 |
# File 'video.c', line 1299
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;
}
|
- (SDL2::Texture) create_texture(format, access, w, h)
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 |
# File 'video.c', line 1208
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));
}
|
- (SDL2::Texture) create_texture_from(surface)
1230 1231 1232 1233 1234 1235 1236 1237 1238 |
# File 'video.c', line 1230
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));
}
|
- (Hash<String=>Object>) debug_info
Returns (GC) debug information
1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 |
# File 'video.c', line 1605
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;
}
|
- (nil) destroy
Destroy the rendering context and free associated textures.
1181 1182 1183 1184 1185 |
# File 'video.c', line 1181
static VALUE Renderer_destroy(VALUE self)
{
Renderer_destroy_internal(Get_Renderer(self));
return Qnil;
}
|
- (Boolean) destroy?
Return true if the renderer is destroyed.
- (Integer) draw_blend_mode
Get the blend mode used for drawing operations like #fill_rect and #draw_line.
1465 1466 1467 1468 1469 1470 |
# File 'video.c', line 1465
static VALUE Renderer_draw_blend_mode(VALUE self)
{
SDL_BlendMode mode;
HANDLE_ERROR(SDL_GetRenderDrawBlendMode(Get_SDL_Renderer(self), &mode));
return INT2FIX(mode);
}
|
- (Object) draw_blend_mode=(mode)
1490 1491 1492 1493 1494 |
# File 'video.c', line 1490
static VALUE Renderer_set_draw_blend_mode(VALUE self, VALUE mode)
{
HANDLE_ERROR(SDL_SetRenderDrawBlendMode(Get_SDL_Renderer(self), NUM2INT(mode)));
return mode;
}
|
- ([Integer,Integer,Integer,Integer]) draw_color
Get the color used for drawing operations
1342 1343 1344 1345 1346 1347 |
# File 'video.c', line 1342
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));
}
|
- (color) draw_color=(color)
1373 1374 1375 1376 1377 1378 1379 1380 1381 |
# File 'video.c', line 1373
static VALUE Renderer_set_draw_color(VALUE self, VALUE rgba)
{
SDL_Color color = Array_to_SDL_Color(rgba);
HANDLE_ERROR(SDL_SetRenderDrawColor(Get_SDL_Renderer(self),
color.r, color.g, color.b, color.a));
return rgba;
}
|
- (nil) draw_line(x1, y1, x2, y2)
1394 1395 1396 1397 1398 1399 |
# File 'video.c', line 1394
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;
}
|
- (nil) draw_point(x, y)
1410 1411 1412 1413 1414 |
# File 'video.c', line 1410
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;
}
|
- (nil) draw_rect(rect)
1424 1425 1426 1427 1428 |
# File 'video.c', line 1424
static VALUE Renderer_draw_rect(VALUE self, VALUE rect)
{
HANDLE_ERROR(SDL_RenderDrawRect(Get_SDL_Renderer(self), Get_SDL_Rect(rect)));
return Qnil;
}
|
- (nil) fill_rect(rect)
1438 1439 1440 1441 1442 |
# File 'video.c', line 1438
static VALUE Renderer_fill_rect(VALUE self, VALUE rect)
{
HANDLE_ERROR(SDL_RenderFillRect(Get_SDL_Renderer(self), Get_SDL_Rect(rect)));
return Qnil;
}
|
- (SDL2::Renderer::Info) info
Get information about self rendering context .
1449 1450 1451 1452 1453 1454 |
# File 'video.c', line 1449
static VALUE Renderer_info(VALUE self)
{
SDL_RendererInfo info;
HANDLE_ERROR(SDL_GetRendererInfo(Get_SDL_Renderer(self), &info));
return RendererInfo_new(&info);
}
|
- (SDL2::Texture) load_texture(file)
3236 3237 3238 3239 3240 3241 3242 3243 3244 |
# File 'video.c', line 3236
static VALUE Renderer_load_texture(VALUE self, VALUE fname)
{
SDL_Texture* texture = IMG_LoadTexture(Get_SDL_Renderer(self), StringValueCStr(fname));
if (!texture) {
SDL_SetError(IMG_GetError());
SDL_ERROR();
}
return Texture_new(texture, Get_Renderer(self));
}
|
- (Object) logical_size
1516 1517 1518 1519 1520 1521 |
# File 'video.c', line 1516
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));
}
|
- (Object) output_size
1547 1548 1549 1550 1551 1552 |
# File 'video.c', line 1547
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));
}
|
- (nil) present
Update the screen with rendering performed
1316 1317 1318 1319 1320 |
# File 'video.c', line 1316
static VALUE Renderer_present(VALUE self)
{
SDL_RenderPresent(Get_SDL_Renderer(self));
return Qnil;
}
|
- (SDL2::Texture?) render_target
Get the current render target.
1589 1590 1591 1592 |
# File 'video.c', line 1589
static VALUE Renderer_render_target(VALUE self)
{
return rb_iv_get(self, "render_target");
}
|
- (target) render_target=(target)
1572 1573 1574 1575 1576 1577 1578 |
# File 'video.c', line 1572
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;
}
|
- (nil) reset_render_target
Reset the render target to the screen.
1599 1600 1601 1602 |
# File 'video.c', line 1599
static VALUE Renderer_reset_render_target(VALUE self)
{
return Renderer_set_render_target(self, Qnil);
}
|
- (Object) scale
1523 1524 1525 1526 1527 1528 |
# File 'video.c', line 1523
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));
}
|
- (Boolean) support_render_target?
Return true if the renderer supports render target.
1542 1543 1544 1545 |
# File 'video.c', line 1542
static VALUE Renderer_support_render_target_p(VALUE self)
{
return INT2BOOL(SDL_RenderTargetSupported(Get_SDL_Renderer(self)));
}
|
- (Object) viewport
1530 1531 1532 1533 1534 1535 |
# File 'video.c', line 1530
static VALUE Renderer_viewport(VALUE self)
{
VALUE rect = rb_obj_alloc(cRect);
SDL_RenderGetViewport(Get_SDL_Renderer(self), Get_SDL_Rect(rect));
return rect;
}
|