opengl-bindings 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ require 'rbconfig'
2
+
3
+ module OpenGL
4
+ @@opengl_platform = case RbConfig::CONFIG['host_os']
5
+ when /mswin|msys|mingw|cygwin/
6
+ :OPENGL_PLATFORM_WINDOWS
7
+ when /darwin/
8
+ :OPENGL_PLATFORM_MACOSX
9
+ when /linux/
10
+ :OPENGL_PLATFORM_LINUX
11
+ else
12
+ raise RuntimeError, "OpenGL : Unknown OS: #{host_os.inspect}"
13
+ end
14
+
15
+ def self.get_platform()
16
+ return @@opengl_platform
17
+ end
18
+
19
+ end
@@ -0,0 +1,31 @@
1
+ require 'fiddle'
2
+
3
+ module OpenGL
4
+
5
+ WGL_FUNCTIONS_MAP = {}
6
+ WGL_FUNCTIONS_ARGS_MAP = {}
7
+ WGL_FUNCTIONS_RETVAL_MAP = {}
8
+
9
+ def self.get_wgl_command( sym )
10
+ if WGL_FUNCTIONS_MAP[sym] == nil
11
+ bind_wgl_command( sym )
12
+ end
13
+ return WGL_FUNCTIONS_MAP[sym]
14
+ end
15
+
16
+ def self.bind_wgl_command( sym )
17
+ WGL_FUNCTIONS_MAP[sym] = Fiddle::Function.new( @@gl_dll[sym.to_s],
18
+ WGL_FUNCTIONS_ARGS_MAP[sym],
19
+ WGL_FUNCTIONS_RETVAL_MAP[sym] )
20
+ raise RuntimeError if WGL_FUNCTIONS_RETVAL_MAP[sym] == nil
21
+ end
22
+
23
+ WGL_FUNCTIONS_ARGS_MAP[:wglGetProcAddress] = [Fiddle::TYPE_VOIDP]
24
+ WGL_FUNCTIONS_RETVAL_MAP[:wglGetProcAddress] = Fiddle::TYPE_VOIDP
25
+
26
+ def wglGetProcAddress(_lpszProc_)
27
+ f = OpenGL::get_wgl_command(:wglGetProcAddress)
28
+ f.call(_lpszProc_)
29
+ end
30
+
31
+ end
data/sample/README.md ADDED
@@ -0,0 +1,7 @@
1
+ ### Getting GLFW (http://www.glfw.org) ###
2
+
3
+ * Windows
4
+ * Put glfw3.dll here.
5
+
6
+ * Mac OS X
7
+ * run ./glfw_build_dylib.sh to get ./libglfw.dylib.
@@ -0,0 +1,22 @@
1
+ #
2
+ # For Mac OS X + Xcode + CMake users.
3
+ #
4
+ # Ref.: https://github.com/malkia/ufo/blob/master/build/OSX/glfw.sh
5
+ #
6
+ wget http://downloads.sourceforge.net/project/glfw/glfw/3.0.2/glfw-3.0.2.tar.bz2
7
+ tar xvjf glfw-3.0.2.tar.bz2
8
+ cd glfw-3.0.2/
9
+ mkdir build
10
+ cd build
11
+ export MACOSX_DEPLOYMENT_TARGET=10.8
12
+ cmake -D GLFW_NATIVE_API=1 -D CMAKE_OSX_ARCHITECTURES="i386;x86_64" -D BUILD_SHARED_LIBS=ON -D CMAKE_C_COMPILER=clang ../
13
+ make
14
+
15
+ # 'ls -l src/libglfw*' should be:
16
+ #
17
+ # $ ls -l src/libglfw*
18
+ # -rwxr-xr-x 1 foo staff 222008 8 11 22:29 src/libglfw.3.0.dylib
19
+ # lrwxr-xr-x 1 foo staff 17 8 11 22:29 src/libglfw.3.dylib -> libglfw.3.0.dylib
20
+ # lrwxr-xr-x 1 foo staff 15 8 11 22:29 src/libglfw.dylib -> libglfw.3.dylib
21
+
22
+ cp -R src/libglfw* ../..
@@ -0,0 +1,23 @@
1
+ require 'glfw'
2
+ require 'opengl'
3
+
4
+ include OpenGL
5
+ include GLFW
6
+
7
+ OpenGL.load_dll()
8
+ case OpenGL.get_platform
9
+ when :OPENGL_PLATFORM_WINDOWS
10
+ GLFW.load_dll('glfw3.dll', '.')
11
+ when :OPENGL_PLATFORM_MACOSX
12
+ GLFW.load_dll('libglfw.dylib', '.')
13
+ end
14
+
15
+ if __FILE__ == $0
16
+ glfwInit()
17
+ window = glfwCreateWindow( 100, 100, "Report OpenGL Environment", nil, nil )
18
+ glfwMakeContextCurrent( window )
19
+ puts "Version: #{glGetString(GL_VERSION).to_s}"
20
+ puts "Extensions:"
21
+ puts glGetString(GL_EXTENSIONS).to_s.split(/ /)
22
+ glfwTerminate()
23
+ end
data/sample/simple.rb ADDED
@@ -0,0 +1,64 @@
1
+ # Ref.: /glfw-3.0.1/examples/simple.c
2
+ require 'glfw'
3
+ require 'opengl'
4
+
5
+ include GLFW
6
+ include OpenGL
7
+
8
+ OpenGL.load_dll()
9
+
10
+ case OpenGL.get_platform
11
+ when :OPENGL_PLATFORM_WINDOWS
12
+ GLFW.load_dll('glfw3.dll', '.')
13
+ when :OPENGL_PLATFORM_MACOSX
14
+ GLFW.load_dll('libglfw.dylib', '.')
15
+ end
16
+
17
+ # Press ESC to exit.
18
+ key_callback = GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods|
19
+ if key == GLFW_KEY_ESCAPE && action == GLFW_PRESS
20
+ glfwSetWindowShouldClose(window_handle, 1)
21
+ end
22
+ end
23
+
24
+ if __FILE__ == $0
25
+ glfwInit()
26
+
27
+ window = glfwCreateWindow( 640, 480, "Simple example", nil, nil )
28
+ glfwMakeContextCurrent( window )
29
+ glfwSetKeyCallback( window, key_callback )
30
+
31
+ while glfwWindowShouldClose( window ) == 0
32
+ width_ptr = ' '
33
+ height_ptr = ' '
34
+ glfwGetFramebufferSize(window, width_ptr, height_ptr)
35
+ width = width_ptr.unpack('L')[0]
36
+ height = height_ptr.unpack('L')[0]
37
+ ratio = width.to_f / height.to_f
38
+
39
+ glViewport(0, 0, width, height)
40
+ glClear(GL_COLOR_BUFFER_BIT)
41
+ glMatrixMode(GL_PROJECTION)
42
+ glLoadIdentity()
43
+ glOrtho(-ratio, ratio, -1.0, 1.0, 1.0, -1.0)
44
+ glMatrixMode(GL_MODELVIEW)
45
+
46
+ glLoadIdentity()
47
+ glRotatef(glfwGetTime() * 50.0, 0.0, 0.0, 1.0)
48
+
49
+ glBegin(GL_TRIANGLES)
50
+ glColor3f(1.0, 0.0, 0.0)
51
+ glVertex3f(-0.6, -0.4, 0.0)
52
+ glColor3f(0.0, 1.0, 0.0)
53
+ glVertex3f(0.6, -0.4, 0.0)
54
+ glColor3f(0.0, 0.0, 1.0)
55
+ glVertex3f(0.0, 0.6, 0.0)
56
+ glEnd()
57
+
58
+ glfwSwapBuffers( window )
59
+ glfwPollEvents()
60
+ end
61
+
62
+ glfwDestroyWindow( window )
63
+ glfwTerminate()
64
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opengl-bindings
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ platform: ruby
6
+ authors:
7
+ - vaiorabbit
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ Ruby bindings for OpenGL 1.0-4.4 and all extensions using Fiddle.
15
+ email:
16
+ - vaiorabbit@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/glfw.rb
22
+ - lib/glu.rb
23
+ - lib/opengl.rb
24
+ - lib/opengl_command.rb
25
+ - lib/opengl_common.rb
26
+ - lib/opengl_enum.rb
27
+ - lib/opengl_ext.rb
28
+ - lib/opengl_ext_command.rb
29
+ - lib/opengl_ext_enum.rb
30
+ - lib/opengl_platform.rb
31
+ - lib/opengl_windows.rb
32
+ - README.md
33
+ - LICENSE.txt
34
+ - ChangeLog
35
+ - sample/simple.rb
36
+ - sample/report_env.rb
37
+ - sample/glfw_build_dylib.sh
38
+ - sample/README.md
39
+ homepage: https://github.com/vaiorabbit/ruby-opengl
40
+ licenses:
41
+ - zlib/libpng
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - '>='
50
+ - !ruby/object:Gem::Version
51
+ version: 2.0.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.0.5
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Bindings for OpenGL 1.0-4.4 and extensions (For Ruby >= 2.0)
63
+ test_files: []