Module: RedBird::Render

Defined in:
ext/red_bird/render.c,
ext/red_bird/render.c

Overview

This module contains basic rendering functionalities.

Author:

  • Frederico Linhares

Class Method Summary collapse

Class Method Details

.clear_screenRedBird::Render

Fill the entire screen with a single color defined by RedBird::Render.set_color.

Returns:

See Also:

Author:

  • Frederico Linhares



86
87
88
89
90
91
92
# File 'ext/red_bird/render.c', line 86

VALUE
bird_mRender_clear_screen(VALUE self)
{
  SDL_RenderClear(bird_core.renderer);

  return self;
}

.fill_rect(x, y, width, height) ⇒ RedBird::Render

Draw a rectangle filled with a color defined by RedBird::Render.set_color.

Parameters:

  • x (Integer)
  • y (Integer)
  • width (Integer)
  • height (Integer)

Returns:

See Also:

Author:

  • Frederico Linhares



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'ext/red_bird/render.c', line 58

VALUE
bird_mRender_fill_rect(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
{
  SDL_Rect rect;

  RB_INTEGER_TYPE_P(x);
  RB_INTEGER_TYPE_P(y);
  RB_INTEGER_TYPE_P(width);
  RB_INTEGER_TYPE_P(height);

  rect.x = x;
  rect.y = y;
  rect.w = width;
  rect.h = height;

  SDL_RenderFillRect(bird_core.renderer, &rect);

  return self;
}

.set_color(color) ⇒ RedBird::Render

Use this method to define the color that will be used by some drawing methods.

Parameters:

Returns:

Author:

  • Frederico Linhares



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'ext/red_bird/render.c', line 25

VALUE
bird_mRender_set_color(VALUE self, VALUE color)
{
  struct bird_color_data *color_ptr;

  if(!rb_obj_is_kind_of(color, bird_cColor))
  {
    rb_raise(rb_eTypeError, "%s",
             "color must be an instance of RedBird::Color");

    return self;
  }

  color_ptr = bird_cColor_get_data(color);

  SDL_SetRenderDrawColor(
      bird_core.renderer, color_ptr->data.r, color_ptr->data.g,
      color_ptr->data.b, color_ptr->data.a);

  return self;
}

.update_screenRedBird::Render

Every time you draw anything, this drawing is not applied directly to the screen; instead, the command draws to a buffer. This procedure allows you to do all the drawing before you present it to the user. After you finish all updates you want into the buffer, you must call this method to send the final buffer to the screen.

Returns:

Author:

  • Frederico Linhares



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'ext/red_bird/render.c', line 104

VALUE
bird_mRender_update_screen(VALUE self)
{
  SDL_SetRenderTarget(bird_core.renderer, NULL);

  SDL_RenderCopy(bird_core.renderer, bird_core.pre_screen_buffer, NULL,
                 &bird_core.screen_rect);
  SDL_RenderPresent(bird_core.renderer);

  SDL_SetRenderTarget(bird_core.renderer, bird_core.pre_screen_buffer);

  return self;
}