Class: Rugl::Backends::OpenGLBindingsGLFW

Inherits:
PrefixedModuleAdapter show all
Defined in:
lib/rugl/backends/opengl_bindings.rb

Constant Summary collapse

LIBRARY_CANDIDATES =
[
  ["libglfw.3.dylib", "/opt/homebrew/lib"],
  ["libglfw.dylib", "/opt/homebrew/lib"],
  ["libglfw.3.dylib", "/opt/homebrew/opt/glfw/lib"],
  ["libglfw.dylib", "/opt/homebrew/opt/glfw/lib"],
  ["libglfw.3.dylib", "/usr/local/lib"],
  ["libglfw.dylib", "/usr/local/lib"],
  ["libglfw.3.dylib", "/usr/local/opt/glfw/lib"],
  ["libglfw.dylib", "/usr/local/opt/glfw/lib"]
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PrefixedModuleAdapter

#const_defined?, #const_get, #method_missing, #respond_to_missing?

Constructor Details

#initialize(target) ⇒ OpenGLBindingsGLFW

Returns a new instance of OpenGLBindingsGLFW.



274
275
276
# File 'lib/rugl/backends/opengl_bindings.rb', line 274

def initialize(target)
  super(target: target, method_prefix: "glfw", constant_prefix: "GLFW")
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rugl::Backends::PrefixedModuleAdapter

Class Method Details

.loadObject



254
255
256
257
258
259
# File 'lib/rugl/backends/opengl_bindings.rb', line 254

def self.load
  require "opengl" unless Object.const_defined?(:OpenGL)
  require "glfw"
  load_library!
  new(GLFW)
end

.load_library!Object



261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/rugl/backends/opengl_bindings.rb', line 261

def self.load_library!
  LIBRARY_CANDIDATES.each do |lib, path|
    next unless File.exist?(File.join(path, lib))

    GLFW.load_lib(lib, path)
    return
  rescue StandardError
    next
  end

  GLFW.load_lib
end

Instance Method Details

#CreateWindow(width, height, title, monitor, share) ⇒ Object



286
287
288
289
290
291
# File 'lib/rugl/backends/opengl_bindings.rb', line 286

def CreateWindow(width, height, title, monitor, share)
  window = target.glfwCreateWindow(width, height, title.to_s, monitor, share)
  return nil if window.respond_to?(:null?) && window.null?

  window
end

#GetFramebufferSize(window) ⇒ Object



303
304
305
306
307
# File 'lib/rugl/backends/opengl_bindings.rb', line 303

def GetFramebufferSize(window)
  read_size_pair do |width_buffer, height_buffer|
    target.glfwGetFramebufferSize(window, width_buffer, height_buffer)
  end
end

#GetWindowSize(window) ⇒ Object



297
298
299
300
301
# File 'lib/rugl/backends/opengl_bindings.rb', line 297

def GetWindowSize(window)
  read_size_pair do |width_buffer, height_buffer|
    target.glfwGetWindowSize(window, width_buffer, height_buffer)
  end
end

#InitObject



282
283
284
# File 'lib/rugl/backends/opengl_bindings.rb', line 282

def Init
  target.glfwInit != 0
end

#load_lib(*args) ⇒ Object



278
279
280
# File 'lib/rugl/backends/opengl_bindings.rb', line 278

def load_lib(*args)
  target.load_lib(*args)
end

#WindowShouldClose(window) ⇒ Object



293
294
295
# File 'lib/rugl/backends/opengl_bindings.rb', line 293

def WindowShouldClose(window)
  target.glfwWindowShouldClose(window) != 0
end