Class: SDL2::GL::Context

Inherits:
Object
  • Object
show all
Defined in:
ext/sdl2_ext/gl.c,
ext/sdl2_ext/gl.c

Overview

This class represents an OpenGL context.

You must create a new OpenGL context before using OpenGL functions.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(window) ⇒ SDL2::GL::Context

Create an OpenGL context for use with an OpenGL window, and make it current.

Examples:


SDL2.init(SDL2::INIT_EVERYTHING)
# You need to create a window with `OPENGL' flag
window = SDL2::Window.create("testgl", 0, 0, WINDOW_W, WINDOW_H,
                             SDL2::Window::Flags::OPENGL)

# Create a OpenGL context attached to the window
context = SDL2::GL::Context.create(window)

# You can use OpenGL functions
     :

# Delete the context after using OpenGL functions
context.destroy

Parameters:

  • window (SDL2::Window)

    the window associate with a new context

Returns:

See Also:

  • #delete


76
77
78
79
80
81
82
83
# File 'ext/sdl2_ext/gl.c', line 76

static VALUE GLContext_s_create(VALUE self, VALUE window)
{
    SDL_GLContext context = SDL_GL_CreateContext(Get_SDL_Window(window));
    if (!context)
        SDL_ERROR();

    return (current_context = GLContext_new(context));
}

.currentSDL2::GL::Context?

Get the current OpenGL context.

Returns:

  • (SDL2::GL::Context)

    the curren context

  • (nil)

    if there is no current context

See Also:



123
124
125
126
# File 'ext/sdl2_ext/gl.c', line 123

static VALUE GLContext_s_current(VALUE self)
{
    return current_context;
}

Instance Method Details

#destroynil

Delete the OpenGL context.

Returns:

  • (nil)

See Also:



92
93
94
95
96
97
98
99
# File 'ext/sdl2_ext/gl.c', line 92

static VALUE GLContext_destroy(VALUE self)
{
    GLContext* c = Get_GLContext(self);
    if (c->context)
        SDL_GL_DeleteContext(c->context);
    c->context = NULL;
    return Qnil;
}

#destroy?Boolean

Return true if the context is destroyed.

Returns:

  • (Boolean)

#make_current(window) ⇒ nil

Set the OpenGL context for rendering into an OpenGL window.

Parameters:

  • window (SDL2::Window)

    the window to associate with the context

Returns:

  • (nil)


108
109
110
111
112
113
# File 'ext/sdl2_ext/gl.c', line 108

static VALUE GLContext_make_current(VALUE self, VALUE window)
{
    HANDLE_ERROR(SDL_GL_MakeCurrent(Get_SDL_Window(window), Get_SDL_GLContext(self)));
    current_context = self;
    return Qnil;
}