From e41a2b65244778f0cb44ef76615111fb7641170a Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Thu, 26 Sep 2019 08:24:32 -0500 Subject: [PATCH] Cleanup i-mic-fps.rb a bit --- i-mic-fps.rb | 65 +++++------------------------------------- lib/ext/load_opengl.rb | 35 +++++++++++++++++++++++ lib/ext/numeric.rb | 18 ++++++++++++ 3 files changed, 60 insertions(+), 58 deletions(-) create mode 100644 lib/ext/load_opengl.rb create mode 100644 lib/ext/numeric.rb diff --git a/i-mic-fps.rb b/i-mic-fps.rb index 833d10f..560b03d 100644 --- a/i-mic-fps.rb +++ b/i-mic-fps.rb @@ -7,68 +7,17 @@ require "time" require "opengl" require "glu" -#begin +begin require_relative "../cyberarm_engine/lib/cyberarm_engine" -#rescue LoadError -# require "cyberarm_engine" -#end +rescue LoadError => e + pp e + require "cyberarm_engine" +end Dir.chdir(File.dirname(__FILE__)) -case OpenGL.get_platform -when :OPENGL_PLATFORM_WINDOWS - OpenGL.load_lib("opengl32.dll", "C:/Windows/System32") - GLU.load_lib("GLU32.dll", "C:/Windows/System32") -when :OPENGL_PLATFORM_MACOSX - OpenGL.load_lib("libGL.dylib", "/System/Library/Frameworks/OpenGL.framework/Libraries") - GLU.load_lib("libGLU.dylib", "/System/Library/Frameworks/OpenGL.framework/Libraries") -when :OPENGL_PLATFORM_LINUX - # Black magic to get GLSL 3.30 support on older Intel hardware - # if `glxinfo | egrep "OpenGL vendor|OpenGL renderer"`.include?("Intel") - # ENV["MESA_GL_VERSION_OVERRIDE"] = "3.3" - # ENV["MESA_GLSL_VERSION_OVERRIDE"] = "330" - # end - - gl_library_path = nil - - if File.exist?("/usr/lib/x86_64-linux-gnu/libGL.so") # Ubuntu (Debian) - gl_library_path = "/usr/lib/x86_64-linux-gnu" - - elsif File.exist?("/usr/lib/libGL.so") # Manjaro (ARCH) - gl_library_path = "/usr/lib" - - elsif File.exist?("/usr/lib/arm-linux-gnueabihf/libGL.so") # Raspbian (ARM/Raspberry Pi) - gl_library_path = "/usr/lib/arm-linux-gnueabihf" - end - - if gl_library_path - OpenGL.load_lib("libGL.so", gl_library_path) - GLU.load_lib("libGLU.so", gl_library_path) - else - raise RuntimeError, "Couldn't find GL libraries" - end -else - raise RuntimeError, "Unsupported platform." -end - -if RUBY_VERSION < "2.5.0" - puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" - puts "|NOTICE| Ruby is #{RUBY_VERSION} not 2.5.0+..............................|Notice|" - puts "|NOTICE| Monkey Patching Float to add required '.clamp' method.|Notice|" - puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" - puts - class Float - def clamp(min, max) - if self < min - min - elsif self > max - max - else - return self - end - end - end -end +require_relative "lib/ext/numeric" +require_relative "lib/ext/load_opengl" include CyberarmEngine include OpenGL diff --git a/lib/ext/load_opengl.rb b/lib/ext/load_opengl.rb new file mode 100644 index 0000000..2696e54 --- /dev/null +++ b/lib/ext/load_opengl.rb @@ -0,0 +1,35 @@ +case OpenGL.get_platform +when :OPENGL_PLATFORM_WINDOWS + OpenGL.load_lib("opengl32.dll", "C:/Windows/System32") + GLU.load_lib("GLU32.dll", "C:/Windows/System32") +when :OPENGL_PLATFORM_MACOSX + OpenGL.load_lib("libGL.dylib", "/System/Library/Frameworks/OpenGL.framework/Libraries") + GLU.load_lib("libGLU.dylib", "/System/Library/Frameworks/OpenGL.framework/Libraries") +when :OPENGL_PLATFORM_LINUX + # Black magic to get GLSL 3.30 support on older Intel hardware + # if `glxinfo | egrep "OpenGL vendor|OpenGL renderer"`.include?("Intel") + # ENV["MESA_GL_VERSION_OVERRIDE"] = "3.3" + # ENV["MESA_GLSL_VERSION_OVERRIDE"] = "330" + # end + + gl_library_path = nil + + if File.exist?("/usr/lib/x86_64-linux-gnu/libGL.so") # Ubuntu (Debian) + gl_library_path = "/usr/lib/x86_64-linux-gnu" + + elsif File.exist?("/usr/lib/libGL.so") # Manjaro (ARCH) + gl_library_path = "/usr/lib" + + elsif File.exist?("/usr/lib/arm-linux-gnueabihf/libGL.so") # Raspbian (ARM/Raspberry Pi) + gl_library_path = "/usr/lib/arm-linux-gnueabihf" + end + + if gl_library_path + OpenGL.load_lib("libGL.so", gl_library_path) + GLU.load_lib("libGLU.so", gl_library_path) + else + raise RuntimeError, "Couldn't find GL libraries" + end +else + raise RuntimeError, "Unsupported platform." +end \ No newline at end of file diff --git a/lib/ext/numeric.rb b/lib/ext/numeric.rb new file mode 100644 index 0000000..6e419e6 --- /dev/null +++ b/lib/ext/numeric.rb @@ -0,0 +1,18 @@ +if RUBY_VERSION < "2.5.0" + puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" + puts "|NOTICE| Ruby is #{RUBY_VERSION} not 2.5.0+..............................|Notice|" + puts "|NOTICE| Monkey Patching Numeric to add required '.clamp' method.|Notice|" + puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" + puts + class Numeric + def clamp(min, max) + if self < min + min + elsif self > max + max + else + return self + end + end + end +end \ No newline at end of file