Class: Quake::Window
- Inherits:
-
Object
- Object
- Quake::Window
- Defined in:
- lib/quake/window.rb
Constant Summary collapse
- DEFAULT_WIDTH =
1280- DEFAULT_HEIGHT =
720- TITLE =
"RubyQuake"
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #aspect_ratio ⇒ Object
- #close ⇒ Object
-
#initialize(width: DEFAULT_WIDTH, height: DEFAULT_HEIGHT, visible: true) ⇒ Window
constructor
A new instance of Window.
- #poll_events ⇒ Object
- #swap ⇒ Object
Constructor Details
#initialize(width: DEFAULT_WIDTH, height: DEFAULT_HEIGHT, visible: true) ⇒ Window
Returns a new instance of Window.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/quake/window.rb', line 15 def initialize(width: DEFAULT_WIDTH, height: DEFAULT_HEIGHT, visible: true) @width = width @height = height @visible = visible SDL.load_lib("/opt/homebrew/lib/libSDL2.dylib") SDL.Init(SDL::INIT_VIDEO) SDL.GL_SetAttribute(SDL::GL_CONTEXT_MAJOR_VERSION, 2) SDL.GL_SetAttribute(SDL::GL_CONTEXT_MINOR_VERSION, 1) SDL.GL_SetAttribute(SDL::GL_DOUBLEBUFFER, 1) SDL.GL_SetAttribute(SDL::GL_DEPTH_SIZE, 24) window_flags = SDL::WINDOW_OPENGL window_flags |= visible ? SDL::WINDOW_SHOWN : SDL::WINDOW_HIDDEN @window = SDL.CreateWindow( TITLE, SDL::WINDOWPOS_CENTERED_MASK, SDL::WINDOWPOS_CENTERED_MASK, width, height, window_flags ) @context = SDL.GL_CreateContext(@window) SDL.GL_MakeCurrent(@window, @context) SDL.GL_SetSwapInterval(visible ? 1 : 0) # vsync only for visible GL.load_lib GLU.load_lib GL.Viewport(0, 0, width, height) GL.Enable(GL::DEPTH_TEST) GL.ClearColor(0.0, 0.0, 0.0, 1.0) SDL.SetRelativeMouseMode(SDL::TRUE) if visible end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
13 14 15 |
# File 'lib/quake/window.rb', line 13 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
13 14 15 |
# File 'lib/quake/window.rb', line 13 def width @width end |
Instance Method Details
#aspect_ratio ⇒ Object
64 65 66 |
# File 'lib/quake/window.rb', line 64 def aspect_ratio @width.to_f / @height end |
#close ⇒ Object
68 69 70 71 72 |
# File 'lib/quake/window.rb', line 68 def close SDL.GL_DeleteContext(@context) SDL.DestroyWindow(@window) SDL.Quit end |
#poll_events ⇒ Object
57 58 59 60 61 62 |
# File 'lib/quake/window.rb', line 57 def poll_events @event ||= SDL::Event.new while SDL.PollEvent(@event.to_ptr) != 0 yield @event end end |
#swap ⇒ Object
53 54 55 |
# File 'lib/quake/window.rb', line 53 def swap SDL.GL_SwapWindow(@window) end |