Class: Rubyboy::Lcd
- Inherits:
-
Object
- Object
- Rubyboy::Lcd
- Defined in:
- lib/rubyboy/lcd.rb
Constant Summary collapse
- SCREEN_WIDTH =
160
- SCREEN_HEIGHT =
144
- SCALE =
3
Instance Method Summary collapse
- #close_window ⇒ Object
- #draw(framebuffer) ⇒ Object
-
#initialize ⇒ Lcd
constructor
A new instance of Lcd.
- #window_should_close? ⇒ Boolean
Constructor Details
#initialize ⇒ Lcd
Returns a new instance of Lcd.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rubyboy/lcd.rb', line 11 def initialize raise SDL.GetError() if SDL.InitSubSystem(SDL::INIT_VIDEO) != 0 @buffer = FFI::MemoryPointer.new(:uint8, SCREEN_WIDTH * SCREEN_HEIGHT * 3) @window = SDL.CreateWindow('RUBY BOY', 0, 0, SCREEN_WIDTH * SCALE, SCREEN_HEIGHT * SCALE, SDL::SDL_WINDOW_RESIZABLE) raise SDL.GetError() if @window.null? @renderer = SDL.CreateRenderer(@window, -1, 0) SDL.SetHint('SDL_HINT_RENDER_SCALE_QUALITY', '2') SDL.RenderSetLogicalSize(@renderer, SCREEN_WIDTH * SCALE, SCREEN_HEIGHT * SCALE) @texture = SDL.CreateTexture(@renderer, SDL::PIXELFORMAT_RGB24, 1, SCREEN_WIDTH, SCREEN_HEIGHT) @event = FFI::MemoryPointer.new(:pointer) end |
Instance Method Details
#close_window ⇒ Object
43 44 45 46 |
# File 'lib/rubyboy/lcd.rb', line 43 def close_window SDL.DestroyWindow(@window) SDL.Quit end |
#draw(framebuffer) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/rubyboy/lcd.rb', line 26 def draw(framebuffer) @buffer.write_array_of_uint8(framebuffer) SDL.UpdateTexture(@texture, nil, @buffer, SCREEN_WIDTH * 3) SDL.RenderClear(@renderer) SDL.RenderCopy(@renderer, @texture, nil, nil) SDL.RenderPresent(@renderer) end |