Module: SDL2

Defined in:
main.c,
lib/sdl2/version.rb,
main.c

Overview

Namespace module for Ruby/SDL2.

Defined Under Namespace

Modules: BlendMode, Clipboard, GL, Hints, IMG, Key, MessageBox, Mixer, Mouse, ScreenSaver, TextInput Classes: Display, Error, Event, GameController, Joystick, PixelFormat, Point, Rect, Renderer, Surface, TTF, Texture, Window

Constant Summary

VERSION =

Version string of Ruby/SDL2

"0.2.0"
VERSION_NUMBER =

Version of Ruby/SDL2, [major, minor, patch level]

[0, 2, 0]
LIBSDL_VERSION =

SDL's version string

libsdl_version()
LIBSDL_VERSION_NUMBER =

SDL's version array of numbers

libsdl_version_number()
LIBSDL_REVISION =

SDL's revision (from VCS) string

libsdl_revision()
LIBSDL_REVISION_NUMBER =

SDL's revision (from VCS) array of numbers

libsdl_revision_number()
LIBSDL_IMAGE_VERSION =

SDL_image's version string, only available if SDL_image is linked

SDL_version_to_String(version)
LIBSDL_IMAGE_VERSION_NUMBER =

SDL_image's version array of numbers

SDL_version_to_Array(version)
LIBSDL_TTF_VERSION =

SDL_ttf's version string, only available if SDL_ttf is linked

SDL_version_to_String(version)
LIBSDL_TTF_VERSION_NUMBER =

SDL_ttf's version array of numbers

SDL_version_to_Array(version)
LIBSDL_MIXER_VERSION =

SDL_mixer's version string , only available if SDL_mixer is linked

SDL_version_to_String(version)
LIBSDL_MIXER_VERSION_NUMBER =

SDL_mixer's version array of numbers

SDL_version_to_Array(version)

Class Method Summary (collapse)

Class Method Details

+ (Object) base_path



5
6
7
8
9
10
11
12
13
14
# File 'filesystem.c', line 5

static VALUE SDL2_s_base_path(VALUE self)
{
    char* path = SDL_GetBasePath();
    VALUE str;
    if (!path)
        SDL_ERROR();
    str = utf8str_new_cstr(path);
    SDL_free(path);
    return str;
}

+ (String?) current_video_driver

Get the name of current video driver

Returns:

  • (String)

    the name of the current video driver

  • (nil)

    when the video is not initialized



309
310
311
312
313
314
315
316
# File 'video.c', line 309

static VALUE SDL2_s_current_video_driver(VALUE self)
{
    const char* name = SDL_GetCurrentVideoDriver();
    if (name)
        return utf8str_new_cstr(name);
    else
        return Qnil;
}

+ (nil) delay(ms)

Wait a specified milliseconds.

This function stops all ruby threads. If you want to keep running other threads, you should use Kernel.sleep instead of this function.

Parameters:

  • ms (Integer)

    the number of milliseconds to delay

Returns:

  • (nil)


15
16
17
18
19
# File 'timer.c', line 15

static VALUE SDL_s_delay(VALUE self, VALUE ms)
{
    SDL_Delay(NUM2UINT(ms));
    return Qnil;
}

+ (Integer) get_performance_counter

Return the current value of the high resolution counter.

This method is typically used for profiling.

Returns:

  • (Integer)

    the current counter value

See Also:



39
40
41
42
# File 'timer.c', line 39

static VALUE SDL_s_get_performance_counter(VALUE self)
{
    return ULL2NUM(SDL_GetPerformanceCounter());
}

+ (Integer) get_performance_frequency

Return the frequency (count per second) of the high resolution counter.

Returns:

  • (Integer)

    a platform-specific count per second.

See Also:



50
51
52
53
# File 'timer.c', line 50

static VALUE SDL_s_get_performance_frequency(VALUE self)
{
    return ULL2NUM(SDL_GetPerformanceFrequency());
}

+ (Integer) get_ticks

Return the number of milliseconds since init is called.

Returns:

  • (Integer)

    milliseconds in 32bit unsigned value.



26
27
28
29
# File 'timer.c', line 26

static VALUE SDL_s_get_ticks(VALUE self)
{
    return UINT2NUM(SDL_GetTicks());
}

+ (nil) init(flags)

Initialize SDL. You must call this function before using any other Ruby/SDL2 methods.

You can specify initialized subsystem by flags which is bitwise OR of the following constants:

  • SDL2::INIT_TIMER - timer subsystem

  • SDL2::INIT_AUDIO - audio subsystem

  • SDL2::INIT_VIDEO - video subsystem

  • SDL2::INIT_JOYSTICK - joystick subsystem

  • SDL2::INIT_HAPTIC - haptic (force feedback) subsystem (interface is not implemented yet)

  • SDL2::INIT_GAMECONTROLLER - controller subsystem

  • SDL2::INIT_EVENTS - events subsystem

  • SDL2::INIT_EVERYTHING - all of the above flags

  • SDL2::INIT_NOPARACHUTE - this flag is ignored; for compatibility

Parameters:

  • flags (Integer)

    initializing subsystems

Returns:

  • (nil)


116
117
118
119
120
121
122
# File 'main.c', line 116

static VALUE SDL2_s_init(VALUE self, VALUE flags)
{
    SDL_SetMainReady();
    HANDLE_ERROR(SDL_Init(NUM2UINT(flags)));
    state = INITIALIZDED;
    return Qnil;
}

+ (Object) preference_path



16
17
18
19
20
21
22
23
24
25
# File 'filesystem.c', line 16

static VALUE SDL2_s_preference_path(VALUE self, VALUE org, VALUE app)
{
    char* path = SDL_GetPrefPath(StringValueCStr(org), StringValueCStr(app));
    VALUE str;
    if (!path)
        SDL_ERROR();
    str = utf8str_new_cstr(path);
    SDL_free(path);
    return str;
}

+ (Array<String>) video_drivers

Get the names of all video drivers.

You can use the name as an argument of video_init.

Returns:

  • (Array<String>)


293
294
295
296
297
298
299
300
301
# File 'video.c', line 293

static VALUE SDL2_s_video_drivers(VALUE self)
{
    int num_drivers = HANDLE_ERROR(SDL_GetNumVideoDrivers());
    int i;
    VALUE drivers = rb_ary_new();
    for (i=0; i<num_drivers; ++i)
        rb_ary_push(drivers, rb_usascii_str_new_cstr(SDL_GetVideoDriver(i)));
    return drivers;
}

+ (nil) video_init(driver_name)

Initialize the video subsystem, specifying a video driver.

init cannot specify a video driver, so you need to use this method to specify a driver.

Parameters:

  • driver_name (String)

Returns:

  • (nil)

See Also:



330
331
332
333
334
# File 'video.c', line 330

static VALUE SDL2_s_video_init(VALUE self, VALUE driver_name)
{
    HANDLE_ERROR(SDL_VideoInit(StringValueCStr(driver_name)));
    return Qnil;
}