class SDL2::Renderer

Render: Interface for 2D accelerated rendering. Supports the following:

- pixel points
- pixel lines
- filled rectangles
- texture images

Also supports:

- additive modes
- blending/opaqueness

Note: Does not support threading, single thread only.

wiki.libsdl.org/CategoryRender

Public Class Methods

create(window, flags = 0, driver_idx = -1) click to toggle source

Constructs a Renderer for a window. @param flags: Combination of RENDERER flags requested

# File lib/sdl2/renderer.rb, line 99
def self.create(window, flags = 0, driver_idx = -1)
  SDL2.create_renderer!(window, driver_idx, flags)
end
create_software(surface) click to toggle source

Create a 2D software rendering context to be able to write directly to a surface (not a window).

# File lib/sdl2/renderer.rb, line 112
def self.create_software(surface)
  SDL2.create_software_renderer(surface)
end
get(window) click to toggle source

Returns the rendering context for a window

# File lib/sdl2/renderer.rb, line 105
def self.get(window)
  SDL2.get_renderer!(window)
end
release(pointer) click to toggle source

Release a render

# File lib/sdl2/renderer.rb, line 118
def self.release(pointer)
  SDL2.destroy_renderer(pointer)
end

Public Instance Methods

clear() click to toggle source

This writes draw_color to entire rendering volume

# File lib/sdl2/renderer.rb, line 198
def clear
  SDL2.render_clear(self)
end
clip_rect() click to toggle source

Get the clipping rectangle

# File lib/sdl2/renderer.rb, line 291
def clip_rect
  rect = SDL2::Rect.new
  SDL2.render_get_clip_rect(self, rect)
  rect
end
clip_rect=(cords) click to toggle source

Set the clipping rectangle

# File lib/sdl2/renderer.rb, line 299
def clip_rect=(cords)
  rect = SDL2::Rect.cast(cords)
  SDL2.render_set_clip_rect!(self, rect)
  rect
end
copy(texture, src_cords = nil, dst_cords = nil) click to toggle source

Render a Texture or a portion of a texture to the rendering target

# File lib/sdl2/renderer.rb, line 210
def copy(texture, src_cords = nil, dst_cords = nil)
  src_rect = SDL2::Rect.cast(src_cords)
  dst_rect = SDL2::Rect.cast(dst_cords)
  SDL2.render_copy!(self, texture, src_rect, dst_rect)
end
copy_ex(texture, src_cords = nil, dst_cords = nil, angle = 0.0, center_cords = nil, flip = :NONE) click to toggle source

Render a Texture or a portion of a texture to the rendering target optionally rotating it by an angle around the given center and also flipping it top-bottom and/or left-right

# File lib/sdl2/renderer.rb, line 220
def copy_ex(texture, src_cords = nil, dst_cords = nil, angle = 0.0, center_cords = nil, flip = :NONE)
  src_rect = SDL2::Rect.cast(src_cords)
  dst_rect = SDL2::Rect.cast(dst_cords)
  center_point = SDL2::Point.cast(center_cords)
  SDL2.render_copy_ex(self, texture, src_rect, dst_rect, angle, center_point, flip)
end
destroy() click to toggle source
# File lib/sdl2/renderer.rb, line 124
def destroy
  SDL2.destroy_renderer(self)
end
draw_blend_mode() click to toggle source

Return the Draw Blend Mode

# File lib/sdl2/renderer.rb, line 135
def draw_blend_mode
  blend_mode = SDL2::TypedPointer::BlendMode.new
  SDL2.get_render_draw_blend_mode!(self, blend_mode)
  blend_mode.value
end
draw_blend_mode=(blend_mode) click to toggle source

Change the Draw Blend Mode

# File lib/sdl2/renderer.rb, line 143
def draw_blend_mode=(blend_mode)
  SDL2.set_render_draw_blend_mode!(self, blend_mode)
end
draw_color() click to toggle source

Get the Draw Color Returns an SDL2::Color

# File lib/sdl2/renderer.rb, line 150
def draw_color
  colors = 4.times.map{SDL2::TypedPointer::UInt8.new}
  SDL2.get_render_draw_color!(self, *colors)
  colors = colors.map(&:value)
  SDL2::Color.cast(colors)
end
draw_color=(color) click to toggle source

Set the Draw Color

# File lib/sdl2/renderer.rb, line 159
def draw_color=(color)
  color = SDL2::Color.cast(color)
  SDL2.set_render_draw_color!(self, *color.to_a)
end
draw_line(x1, y1, x2, y2) click to toggle source

Draw a single pixel line

# File lib/sdl2/renderer.rb, line 229
def draw_line(x1, y1, x2, y2)
  SDL2.render_draw_line!(self, x1, y1, x2, y2)
end
draw_lines(*cords) click to toggle source

Draw lines connecting all points specified. Each individual point should either be an SDL2::Point or something that can be cast into one.

# File lib/sdl2/renderer.rb, line 237
def draw_lines(*cords)
  points = SDL2::StructArray.clone_from(cords, SDL2::Point)
  SDL2.render_draw_lines!(self, points.first, points.count)
end
draw_point(x,y) click to toggle source

Draw a point

# File lib/sdl2/renderer.rb, line 244
def draw_point(x,y)
  SDL2.render_draw_point!(self, x, y)
end
draw_points(*cords) click to toggle source

Draw each specified point. Each argument must be an X/Y point, either as an arrray [2,3], hash {x: 2, y: 3} or an SDL2::Point

# File lib/sdl2/renderer.rb, line 251
def draw_points(*cords)
  points = SDL2::StructArray.clone_from(cords, SDL2::Point)
  SDL2.render_draw_points!(self, points.first, points.count)
end
draw_rect(cords) click to toggle source

Draw a rectangle. Should be able to accept an: SDL2::Rect, A hash with :x, :y, :w, :h An array with 2 or 4 integer values.

# File lib/sdl2/renderer.rb, line 261
def draw_rect(cords)
  rect = SDL2::Rect.cast(cords)
  SDL2.render_draw_rect(self, rect)
end
draw_rects(*cords) click to toggle source

Draw many rectangles at once.. each parameter should be something that SDL2::Renderer#draw_rect can take, however this routine sends all points to SDL directly.

# File lib/sdl2/renderer.rb, line 270
def draw_rects(*cords)
  rects = SDL2::StructArray.clone_from(cords, SDL2::Rect)
  SDL2.render_draw_rects!(self, rects.first(), rects.count)
end
fill_rect(cord) click to toggle source

Fill a rectangle

# File lib/sdl2/renderer.rb, line 277
def fill_rect(cord)
  rect = SDL2::Rect.cast(cord)
  SDL2.render_fill_rect!(self, rect)
end
fill_rects(*cords) click to toggle source

Fill many rectangles at once

# File lib/sdl2/renderer.rb, line 284
def fill_rects(*cords)
  rects = SDL2::StructArray.clone_from(cords, SDL2::Rect)
  SDL2.render_fill_rects!(self, rects.first(), rects.count)
end
info() click to toggle source

Retrive the Render Driver Info for this Renderer

# File lib/sdl2/renderer.rb, line 181
def info
  render_info = SDL2::RendererInfo.new
  SDL2.get_renderer_info!(self, render_info)
  render_info
end
logical_size() click to toggle source

Get the logical size of the renderer, returns [w, h]

# File lib/sdl2/renderer.rb, line 307
def logical_size
  size = 2.times.map{SDL2::TypedPointer::Int.new}
  SDL2.render_get_logical_size(self, *size)
  size.map(&:value)
end
logical_size=(wh) click to toggle source

Set the logical size of the renderer, expects [w, h]

# File lib/sdl2/renderer.rb, line 315
def logical_size=(wh)
  SDL2.render_set_logical_size!(self, *wh)
  wh
end
output_size() click to toggle source

Get the output size @returns the [width, height]

# File lib/sdl2/renderer.rb, line 190
def output_size
  wh = 2.times.map{SDL2::TypedPointer::Int.new}
  SDL2.get_renderer_output_size!(self, *wh)
  wh.map(&:value)
end
present() click to toggle source

Present the renderer (AKA: Draw/Flip/Update/Flush)

# File lib/sdl2/renderer.rb, line 129
def present
  SDL2.render_present(self)
end
scale() click to toggle source

Get the scale of the renderer, returns [x,y] floats

# File lib/sdl2/renderer.rb, line 322
def scale
  scale = 2.times.map{SDL2::TypedPointer::Float.new}
  SDL2.render_get_scale(self, *scale)
  scale.map(&:value)
end
scale=(scale) click to toggle source

Set the scale of the renderer, expects [x,y] floats

# File lib/sdl2/renderer.rb, line 330
def scale=(scale)
  SDL2.render_set_scale!(self, *scale)
  scale
end
target() click to toggle source

Get the target Returns nil if default when ‘default’ render target set

# File lib/sdl2/renderer.rb, line 167
def target
  target = SDL2.get_render_target(self)
  target.null? ? nil : target
end
target=(texture) click to toggle source

Set the target

# File lib/sdl2/renderer.rb, line 175
def target=(texture)
  SDL2.set_render_target!(self, texture)
end
target_supported?() click to toggle source

Indicates if Targeted Rendering is supported.

# File lib/sdl2/renderer.rb, line 353
def target_supported?
  SDL2.render_target_supported?(self)
end
texture_from_surface(surface) click to toggle source

Create a texture from a surface

# File lib/sdl2/renderer.rb, line 204
def texture_from_surface(surface)
  SDL2.create_texture_from_surface!(self, surface)
end
viewport() click to toggle source

Get the viewport rect

# File lib/sdl2/renderer.rb, line 337
def viewport
  viewport = SDL2::Rect.new
  SDL2.render_get_viewport(self, viewport)
  viewport
end
viewport=(cords) click to toggle source

Set the viewport rect

# File lib/sdl2/renderer.rb, line 345
def viewport=(cords)
  viewport = SDL2::Rect.cast(cords)
  SDL2.render_set_viewport!(self, viewport)
  viewport
end