Class: SDL::Screen

Inherits:
Surface show all
Defined in:
ext/sdl/sdl.c

Class Method Summary collapse

Methods inherited from Surface

#[], #format, #h, load, #make_collision_map, #transform, #w

Class Method Details

.open(w_, h_, bpp_, flags_) ⇒ Object

// SDL::Screen methods:



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# File 'ext/sdl/sdl.c', line 402

static VALUE Screen_s_open(VALUE klass, VALUE w_, VALUE h_, VALUE bpp_, VALUE flags_) {
  UNUSED(klass);

  int w        = NUM2INT(w_);
  int h        = NUM2INT(h_);
  int bpp      = NUM2INT(bpp_);
  Uint32 flags = NUM2UINT32(flags_);

  if (!bpp) bpp = 32; // TODO: remove bpp option and always be 32?

  SDL_Window *window =
    SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                     w, h,
                     flags);
  if (!window) FAILURE("Screen.open(CreateWindow)");

  SDL_Renderer *renderer =
    SDL_CreateRenderer(window, -1,
                       SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_ACCELERATED);
  if (!renderer) FAILURE("Screen.open(CreateRenderer)");

  // bumps the refcount and returns the same thing
  SDL_PixelFormat *format = SDL_AllocFormat(SDL_PIXELFORMAT_RGBA32);
  if (!format)
    rb_raise(eSDLError, "SDL_AllocFormat freaked out.");

  VALUE vrenderer = TypedData_Wrap_Struct(cRenderer, &_Renderer_type, renderer);
  VALUE vwindow   = TypedData_Wrap_Struct(cWindow,   &_Window_type,   window);
  VALUE vformat   = TypedData_Wrap_Struct(cPixelFormat, &_PixelFormat_type, format);

  rb_ivar_set(vrenderer, id_iv_window,  vwindow);
  rb_ivar_set(vrenderer, id_iv_format,  vformat);

  return vrenderer;
}