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.
Public Class Methods
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
Returns the rendering context for a window
# File lib/sdl2/renderer.rb, line 105 def self.get(window) SDL2.get_renderer!(window) end
Release a render
# File lib/sdl2/renderer.rb, line 118 def self.release(pointer) SDL2.destroy_renderer(pointer) end
Public Instance Methods
This writes draw_color
to entire rendering volume
# File lib/sdl2/renderer.rb, line 198 def clear SDL2.render_clear(self) end
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
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
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
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
# File lib/sdl2/renderer.rb, line 124 def destroy SDL2.destroy_renderer(self) end
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
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
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
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 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 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 a point
# File lib/sdl2/renderer.rb, line 244 def draw_point(x,y) SDL2.render_draw_point!(self, x, y) end
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 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 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 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 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
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
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
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
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 the renderer (AKA: Draw/Flip/Update/Flush)
# File lib/sdl2/renderer.rb, line 129 def present SDL2.render_present(self) end
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
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
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
Set the target
# File lib/sdl2/renderer.rb, line 175 def target=(texture) SDL2.set_render_target!(self, texture) end
Indicates if Targeted Rendering is supported.
# File lib/sdl2/renderer.rb, line 353 def target_supported? SDL2.render_target_supported?(self) end
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
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
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