Class: SDL2::Renderer
- Includes:
- RENDERER
- Defined in:
- lib/sdl2/renderer.rb
Overview
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.
Defined Under Namespace
Classes: Drivers
Constant Summary
Constants included from RENDERER
SDL2::RENDERER::ACCELERATED, SDL2::RENDERER::PRESENTVSYNC, SDL2::RENDERER::SOFTWARE, SDL2::RENDERER::TARGETTEXTURE
Class Method Summary collapse
-
.create(window, flags = 0, driver_idx = -1)) ⇒ Object
Constructs a Renderer for a window.
-
.create_software(surface) ⇒ Object
Create a 2D software rendering context to be able to write directly to a surface (not a window).
-
.get(window) ⇒ Object
Returns the rendering context for a window.
-
.release(pointer) ⇒ Object
Release a render.
Instance Method Summary collapse
-
#clear ⇒ Object
This writes draw_color to entire rendering volume.
-
#clip_rect ⇒ Object
Get the clipping rectangle.
-
#clip_rect=(cords) ⇒ Object
Set the clipping rectangle.
-
#copy(texture, src_cords = nil, dst_cords = nil) ⇒ Object
Render a Texture or a portion of a texture to the rendering target.
-
#copy_ex(texture, src_cords = nil, dst_cords = nil, angle = 0.0, center_cords = nil, flip = :NONE) ⇒ Object
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.
- #destroy ⇒ Object
-
#draw_blend_mode ⇒ Object
Return the Draw Blend Mode.
-
#draw_blend_mode=(blend_mode) ⇒ Object
Change the Draw Blend Mode.
-
#draw_color ⇒ Object
Get the Draw Color Returns an SDL2::Color.
-
#draw_color=(color) ⇒ Object
Set the Draw Color.
-
#draw_line(x1, y1, x2, y2) ⇒ Object
Draw a single pixel line.
-
#draw_lines(*cords) ⇒ Object
Draw lines connecting all points specified.
-
#draw_point(x, y) ⇒ Object
Draw a point.
-
#draw_points(*cords) ⇒ Object
Draw each specified point.
-
#draw_rect(cords) ⇒ Object
Draw a rectangle.
-
#draw_rects(*cords) ⇒ Object
Draw many rectangles at once..
-
#fill_rect(cord) ⇒ Object
Fill a rectangle.
-
#fill_rects(*cords) ⇒ Object
Fill many rectangles at once.
-
#info ⇒ Object
Retrive the Render Driver Info for this Renderer.
-
#logical_size ⇒ Object
Get the logical size of the renderer, returns [w, h].
-
#logical_size=(wh) ⇒ Object
Set the logical size of the renderer, expects [w, h].
-
#output_size ⇒ Object
Get the output size.
-
#present ⇒ Object
Present the renderer (AKA: Draw/Flip/Update/Flush).
-
#scale ⇒ Object
Get the scale of the renderer, returns [x,y] floats.
-
#scale=(scale) ⇒ Object
Set the scale of the renderer, expects [x,y] floats.
-
#target ⇒ Object
Get the target Returns nil if default when ‘default’ render target set.
-
#target=(texture) ⇒ Object
Set the target.
-
#target_supported? ⇒ Boolean
Indicates if Targeted Rendering is supported.
-
#texture_from_surface(surface) ⇒ Object
Create a texture from a surface.
-
#viewport ⇒ Object
Get the viewport rect.
-
#viewport=(cords) ⇒ Object
Set the viewport rect.
Methods included from EnumerableConstants
Methods inherited from Struct
#==, cast, #free, #initialize, #to_s, #update_members
Methods included from StructHelper
#member_readers, #member_writers
Constructor Details
This class inherits a constructor from SDL2::Struct
Class Method Details
.create(window, flags = 0, driver_idx = -1)) ⇒ Object
Constructs a Renderer for a window.
99 100 101 |
# 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) ⇒ Object
Create a 2D software rendering context to be able to write directly to a surface (not a window).
112 113 114 |
# File 'lib/sdl2/renderer.rb', line 112 def self.create_software(surface) SDL2.create_software_renderer(surface) end |
.get(window) ⇒ Object
Returns the rendering context for a window
105 106 107 |
# File 'lib/sdl2/renderer.rb', line 105 def self.get(window) SDL2.get_renderer!(window) end |
.release(pointer) ⇒ Object
Release a render
118 119 120 |
# File 'lib/sdl2/renderer.rb', line 118 def self.release(pointer) SDL2.destroy_renderer(pointer) end |
Instance Method Details
#clear ⇒ Object
This writes draw_color to entire rendering volume
198 199 200 |
# File 'lib/sdl2/renderer.rb', line 198 def clear SDL2.render_clear(self) end |
#clip_rect ⇒ Object
Get the clipping rectangle
291 292 293 294 295 |
# 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) ⇒ Object
Set the clipping rectangle
299 300 301 302 303 |
# 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) ⇒ Object
Render a Texture or a portion of a texture to the rendering target
210 211 212 213 214 |
# 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) ⇒ Object
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
220 221 222 223 224 225 |
# 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 ⇒ Object
124 125 126 |
# File 'lib/sdl2/renderer.rb', line 124 def destroy SDL2.destroy_renderer(self) end |
#draw_blend_mode ⇒ Object
Return the Draw Blend Mode
135 136 137 138 139 |
# 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) ⇒ Object
Change the Draw Blend Mode
143 144 145 |
# 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 ⇒ Object
Get the Draw Color Returns an SDL2::Color
150 151 152 153 154 155 |
# 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) ⇒ Object
Set the Draw Color
159 160 161 162 |
# 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) ⇒ Object
Draw a single pixel line
229 230 231 |
# 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) ⇒ Object
Draw lines connecting all points specified. Each individual point should either be an SDL2::Point or something that can be cast into one.
237 238 239 240 |
# 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) ⇒ Object
Draw a point
244 245 246 |
# File 'lib/sdl2/renderer.rb', line 244 def draw_point(x,y) SDL2.render_draw_point!(self, x, y) end |
#draw_points(*cords) ⇒ Object
Draw each specified point. Each argument must be an X/Y point, either as an arrray [2,3], hash 2, y: 3 or an SDL2::Point
251 252 253 254 |
# 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) ⇒ Object
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.
261 262 263 264 |
# 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) ⇒ Object
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.
270 271 272 273 |
# 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) ⇒ Object
Fill a rectangle
277 278 279 280 |
# 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) ⇒ Object
Fill many rectangles at once
284 285 286 287 |
# 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 ⇒ Object
Retrive the Render Driver Info for this Renderer
181 182 183 184 185 |
# 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 ⇒ Object
Get the logical size of the renderer, returns [w, h]
307 308 309 310 311 |
# 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) ⇒ Object
Set the logical size of the renderer, expects [w, h]
315 316 317 318 |
# File 'lib/sdl2/renderer.rb', line 315 def logical_size=(wh) SDL2.render_set_logical_size!(self, *wh) wh end |
#output_size ⇒ Object
Get the output size
190 191 192 193 194 |
# 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 ⇒ Object
Present the renderer (AKA: Draw/Flip/Update/Flush)
129 130 131 |
# File 'lib/sdl2/renderer.rb', line 129 def present SDL2.render_present(self) end |
#scale ⇒ Object
Get the scale of the renderer, returns [x,y] floats
322 323 324 325 326 |
# 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) ⇒ Object
Set the scale of the renderer, expects [x,y] floats
330 331 332 333 |
# File 'lib/sdl2/renderer.rb', line 330 def scale=(scale) SDL2.render_set_scale!(self, *scale) scale end |
#target ⇒ Object
Get the target Returns nil if default when ‘default’ render target set
167 168 169 170 |
# File 'lib/sdl2/renderer.rb', line 167 def target target = SDL2.get_render_target(self) target.null? ? nil : target end |
#target=(texture) ⇒ Object
Set the target
175 176 177 |
# File 'lib/sdl2/renderer.rb', line 175 def target=(texture) SDL2.set_render_target!(self, texture) end |
#target_supported? ⇒ Boolean
Indicates if Targeted Rendering is supported.
353 354 355 |
# File 'lib/sdl2/renderer.rb', line 353 def target_supported? SDL2.render_target_supported?(self) end |
#texture_from_surface(surface) ⇒ Object
Create a texture from a surface
204 205 206 |
# File 'lib/sdl2/renderer.rb', line 204 def texture_from_surface(surface) SDL2.create_texture_from_surface!(self, surface) end |
#viewport ⇒ Object
Get the viewport rect
337 338 339 340 341 |
# File 'lib/sdl2/renderer.rb', line 337 def = SDL2::Rect.new SDL2.(self, ) end |
#viewport=(cords) ⇒ Object
Set the viewport rect
345 346 347 348 349 |
# File 'lib/sdl2/renderer.rb', line 345 def (cords) = SDL2::Rect.cast(cords) SDL2.(self, ) end |