rubygl 0.1.0 → 0.2.1

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.
Files changed (38) hide show
  1. checksums.yaml +13 -5
  2. data/.travis/push-rdoc-to-gh-pages.sh +22 -0
  3. data/.travis.yml +18 -0
  4. data/Gemfile +7 -0
  5. data/Gemfile.lock +12 -0
  6. data/LICENSE +21 -21
  7. data/README.md +40 -0
  8. data/Rakefile +98 -83
  9. data/bin/ffi_code_gen.rb +166 -166
  10. data/bin/gl_code_gen.rb +458 -458
  11. data/examples/faceted_example.rb +71 -64
  12. data/examples/instanced_example.rb +135 -127
  13. data/examples/phong_example.rb +80 -71
  14. data/ext/windows/RubyGL.so +0 -0
  15. data/lib/rubygl/event.rb +64 -0
  16. data/lib/{RubyGL → rubygl}/geometry.rb +216 -211
  17. data/lib/{RubyGL → rubygl}/math.rb +300 -300
  18. data/lib/{RubyGL → rubygl}/memory.rb +125 -121
  19. data/lib/rubygl/native/all_enums.rb +641 -0
  20. data/lib/{RubyGL/Native → rubygl/native}/glcontext.rb +23 -47
  21. data/lib/{RubyGL/Native → rubygl/native}/include/GLContext.h +36 -36
  22. data/lib/{RubyGL/Native → rubygl/native}/include/Input.h +15 -15
  23. data/lib/{RubyGL/Native → rubygl/native}/include/Window.h +27 -27
  24. data/lib/rubygl/native/input.rb +247 -0
  25. data/lib/{RubyGL/Native → rubygl/native}/opengl.rb +2808 -2032
  26. data/lib/{RubyGL/Native → rubygl/native}/src/GLContext.c +72 -72
  27. data/lib/{RubyGL/Native → rubygl/native}/src/Input.c +25 -25
  28. data/lib/{RubyGL/Native → rubygl/native}/src/Window.c +57 -57
  29. data/lib/{RubyGL/Native → rubygl/native}/window.rb +24 -24
  30. data/lib/{RubyGL → rubygl}/setup.rb +50 -50
  31. data/lib/{RubyGL → rubygl}/shader.rb +203 -203
  32. data/lib/{RubyGL → rubygl}/util.rb +77 -77
  33. data/lib/rubygl.rb +49 -48
  34. data/{RubyGL.gemspec → rubygl.gemspec} +20 -23
  35. data/test/test_util.rb +19 -0
  36. metadata +36 -33
  37. data/lib/RubyGL/Native/input.rb +0 -13
  38. data/lib/RubyGL/callback.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d0db02206c2e8a176817a841bc3ced8cfe60b4af
4
- data.tar.gz: cc0aee2bc3df4f86b43b151e666b967ad9153b03
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWE2NTJjYThmM2M2MGM0MmUwNmE5NTk1YmQxOTFiMTI5YTZkZjEzYg==
5
+ data.tar.gz: !binary |-
6
+ ZDRmMDFhZmI3MjJkZDEwZTgwMDg2N2I4NGI2YmFmOGRjOTg5MjUxYQ==
5
7
  SHA512:
6
- metadata.gz: c37b401ada50218e49983b17a3e7d8f9486fe1a05f1b5bd99ac1ec67fd83cea4a6254c9febf8fa903a21b1f9364bed9bb8c1f8399a862e7eb7e71c3f220d5911
7
- data.tar.gz: 7148dd01e893ed00fcfccb884b34d05e24a946ee01d668b637b3defc22a77b0f378784b225512394e6728a2f8210a266e2b247e3c36b3b05204623c3d33d7a86
8
+ metadata.gz: !binary |-
9
+ YjA1NWMzYzI1YTZiM2E2ZWEyYWI0NDUxYmM5ZmVlY2UyYThkOGU5M2RlN2Nk
10
+ NDlhZjA3NGUwMWQ1ZTMzOTE4M2Q2MmI3OTg0NDM1ZWYyNTVmMzgyY2I2NjJk
11
+ ODUzNGU0YTE5ZjFhYzY4OTFlYWJlYzgyYzI5YjQ0NWY0N2Q2OGI=
12
+ data.tar.gz: !binary |-
13
+ ODNkNTRmZmUxMTVmODU4OWUxMmMwZGNiM2Q1YzBlNjE5NGJiZjc4MmRjODk1
14
+ NjNlMTMxYTlhNzQ3OWZkZGEzOWNjZWE1ZjE0ZDFmODk0OWYyZTFhYmYyNDcx
15
+ MDhmZGFhNWY1ODA5OTNhN2JkMTgyMmIyY2Y0MjMxZDllNmMzNzY=
@@ -0,0 +1,22 @@
1
+ #!/bin/bash
2
+
3
+ if [ "$TRAVIS_REPO_SLUG" == "GGist/RubyGL" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then
4
+ echo -e "Publishing rdoc to gh-pages...\n"
5
+
6
+ mkdir $HOME/rdoc-latest
7
+ rake doc
8
+ cp -r doc/* $HOME/rdoc-latest/.
9
+
10
+ cd $HOME
11
+ git config --global user.email "travis@travis-ci.org"
12
+ git config --global user.name "travis-ci"
13
+ git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/GGist/RubyGL gh-pages > /dev/null
14
+
15
+ cd gh-pages
16
+ cp -rf $HOME/rdoc-latest/* .
17
+ git add -A
18
+ git commit -m "Latest rdoc on successful travis build $TRAVIS_BUILD_NUMBER auto-pushed to gh-pages"
19
+ git push -fq origin gh-pages > /dev/null
20
+
21
+ echo -e "Published rdoc to gh-pages.\n"
22
+ fi
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+
3
+ script:
4
+ - bundle exec rake test
5
+
6
+ env:
7
+ global:
8
+ - secure: qt435BABTrF0JP6PwK5WyyaMYMdDatHDT4yQcJq9BEfhMrhyY+Xdwzpkhq2UVkJ1r+g+ML5C7oNFQxUkDFS7PY4H7YhaPZHKCBbCpp9YH7yzMH7eWq4FtjGUt357kdGVhLietfqTiBl/pnxgAdUmvXxcjvZGHd2OORUymxRucIw=
9
+
10
+ after_success:
11
+ - chmod +x .travis/push-rdoc-to-gh-pages.sh
12
+ - .travis/push-rdoc-to-gh-pages.sh
13
+
14
+ deploy:
15
+ provider: rubygems
16
+ api_key:
17
+ - secure: ohBwl2E3XI6eP3O35SiJU5hnnh6/fah0yCtAHcs30PJaDuHHoCB/RfwhsiNHWAvs7jJGg261UD/Mz1t1vl3mpxx0KfTc1y/Px+5JbjHSlvd6OeVMu1fIZweYXofjQbhHjugbWmDKII5a1G+/4WEU6FTI0RGpGww1w+dh4nXjQj4=
18
+ gem: rubygl
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :test do
4
+ gem 'ffi'
5
+ gem 'rake'
6
+ end
7
+
data/Gemfile.lock ADDED
@@ -0,0 +1,12 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ ffi (1.9.5-x86-mingw32)
5
+ rake (0.9.6)
6
+
7
+ PLATFORMS
8
+ x86-mingw32
9
+
10
+ DEPENDENCIES
11
+ ffi
12
+ rake
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2014 Andrew
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Andrew
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ RubyGL - [![Build Status](https://travis-ci.org/GGist/RubyGL.svg)](https://travis-ci.org/GGist/RubyGL) [![Documentation](http://img.shields.io/badge/docs-in--progress-blue.svg)](http://ggist.github.io/RubyGL/index.html) [![License](http://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/GGist/RubyGL/master/LICENSE)
2
+ =======
3
+ A Complete Solution For Graphics Programming In Ruby.
4
+
5
+ Installing - [![Gem Version](https://badge.fury.io/rb/rubygl.svg)](http://badge.fury.io/rb/rubygl)
6
+ ----------
7
+ ```
8
+ gem install rubygl
9
+ ```
10
+
11
+ Examples Gallery
12
+ ----------------
13
+ <img src="https://cloud.githubusercontent.com/assets/5248583/5156041/53eeb3ce-725b-11e4-908b-0b5aa7b37e2e.gif">
14
+ <img align="right" src="https://cloud.githubusercontent.com/assets/5248583/5156042/55d1ee0e-725b-11e4-9edf-b240051a41b7.gif">
15
+
16
+ Frequently Asked Questions
17
+ --------------------------
18
+ **Q: Why are my shaders not working?**
19
+ A: You probably have an older version of GLSL (1.2 or earler) so your version of GLSL may not support the ```in``` and ```out```
20
+ variables (the shaders in ShaderGenerator use these). To work around this, you can change the ```in``` qualifiers in the
21
+ vertex shader to ```attribute``` qualifiers and the ```out``` qualifiers to ```varying``` qualifiers. In the fragment
22
+ shader change the ```in``` qualifiers to ```varying``` qualifiers and remove any ```out``` variables; you should use the
23
+ built-in ```gl_FragColor``` variable to assign the output fragment color. Lastly, make sure to update the ```#version XXX```
24
+ tag for the version of GLSL your GPU can support (Ex: ```#version 120``` if running GLSL 1.2). You can check your
25
+ GLSL version by running ```puts RubyGL::Native::glGetString(RubyGL::Native::GL_SHADING_LANGUAGE_VERSION)```.
26
+
27
+ **Q: Why is my program giving a segmentation fault?**
28
+ A: You are most likely trying to call an OpenGL function that does not exist in your GPUs version of OpenGL. The offending
29
+ function should be given to you in the stack trace. I have compiled the rubygl shared library for the latest version of OpenGL
30
+ in compatibility mode to let users call any function that their version of OpenGL may support; the library will assume
31
+ that any OpenGL function you are calling is valid (I should probably change this), hence the segmentation fault. Go to
32
+ https://www.opengl.org/sdk/docs/man/ to see which functions are supported by each OpenGL version. You can run
33
+ ```puts RubyGL::Native::glGetString(RubyGL::Native::GL_VERSION)``` to see what version of OpenGL you have.
34
+
35
+ Known Issues
36
+ ------------
37
+ - Only supports Windows at the moment (OSX support coming soon)
38
+ - Not sure how to support Linux without requiring users to compile a shared library
39
+ - Windows does not guarantee that OpenGL functions loaded during context creation will be valid for other contexts
40
+ - Need to figure out how to efficiently swap these out if the user creates more than one context
data/Rakefile CHANGED
@@ -1,83 +1,98 @@
1
- require 'rake/task'
2
- require 'rake/testtask'
3
- require 'tmpdir'
4
-
5
- SDL_INCLUDE = 'C:\Users\GG\Desktop\SDL2-2.0.3\i686-w64-mingw32\include\SDL2'
6
- SDL_LIB = 'C:\Users\GG\Desktop\SDL2-2.0.3\i686-w64-mingw32\lib'
7
- SDL_BIN = 'C:\Users\GG\Desktop\SDL2-2.0.3\i686-w64-mingw32\bin'
8
-
9
- MINGW_LIB = ''
10
-
11
- PROJ_INCLUDE = 'lib/RubyGL/Native/include'
12
- PROJ_SRC = 'lib/RubyGL/Native/src/'
13
-
14
- # OS Detection
15
- def os
16
- @os ||= (
17
- host_os = RbConfig::CONFIG['host_os']
18
-
19
- case host_os
20
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
21
- :windows
22
- when /darwin|mac os/
23
- :macosx
24
- when /linux/
25
- :linux
26
- when /solaris|bsd/
27
- :unix
28
- else
29
- raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
30
- end
31
- )
32
- end
33
-
34
- /---------------------------------RAKE JOBS-----------------------------------/
35
-
36
- task :default do
37
- files = ['Audio', 'Window', 'GLContext', 'Input', 'OpenGL']
38
-
39
- # Build Object Files
40
- obj = "gcc -I#{SDL_INCLUDE} -I#{PROJ_INCLUDE} -c -fPIC REPLACE.c -o REPLACE.o"
41
- files.each { |file|
42
- sh (obj.gsub(/REPLACE/, PROJ_SRC + file))
43
- file = file.prepend PROJ_SRC
44
- }
45
-
46
- # Build Shared Object File
47
- bin = "gcc -L#{SDL_LIB} -L#{MINGW_LIB} #{files.join('.o ') << '.o'} \
48
- -lmingw32 -lSDL2main -lSDL2 -lopengl32 -shared -o \
49
- ext/#{os.to_s}/RubyGL.so"
50
- sh bin
51
- end
52
-
53
- task :clean do
54
- # Clean Out Object Files
55
- FileUtils.rm Dir.glob(PROJ_SRC + '/*.o')
56
- end
57
-
58
- task :bindings do
59
- shared_lib = "RubyGL.so"
60
-
61
- Dir.mktmpdir { |dir|
62
- # Generates Header And Source C Files
63
- sh "ruby bin/gl_code_gen.rb gl 4.5 OpenGL #{dir}"
64
-
65
- # Run Preprocessor On Source File
66
- sh "gcc -E -I#{SDL_INCLUDE} -o #{dir}/OpenGL.o #{dir}/OpenGL.c"
67
-
68
- # Pipe Preprocessor(ed) File And Header File To Generate Bindings
69
- sh "ruby bin/ffi_code_gen.rb #{dir}/OpenGL.o #{dir}/OpenGL.h \
70
- #{dir}/opengl.rb #{shared_lib}"
71
-
72
- # Move Files To Correct Folders
73
- mv "#{dir}/OpenGL.h", PROJ_INCLUDE
74
- mv "#{dir}/OpenGL.c", PROJ_SRC
75
- mv "#{dir}/opengl.rb", "lib/RubyGL/Native/"
76
- }
77
- end
78
-
79
- Rake::TestTask.new do |t|
80
- t.libs << "tests"
81
- t.test_files = FileList['tests/test*.rb']
82
- t.verbose = true
83
- end
1
+ require 'rake/task'
2
+ require 'rake/testtask'
3
+ require 'tmpdir'
4
+
5
+ # Dependency Locations
6
+ SDL_INCLUDE = 'C:\Users\GG\Desktop\SDL2-2.0.3\i686-w64-mingw32\include\SDL2'
7
+ SDL_LIB = 'C:\Users\GG\Desktop\SDL2-2.0.3\i686-w64-mingw32\lib'
8
+ SDL_BIN = 'C:\Users\GG\Desktop\SDL2-2.0.3\i686-w64-mingw32\bin'
9
+
10
+ # C File Locations
11
+ PROJ_INCLUDE = 'lib/rubygl/native/include/'
12
+ PROJ_SRC = 'lib/rubygl/native/src/'
13
+
14
+ # OS Detection
15
+ def os
16
+ @os ||= (
17
+ host_os = RbConfig::CONFIG['host_os']
18
+
19
+ case host_os
20
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
21
+ :windows
22
+ when /darwin|mac os/
23
+ :macosx
24
+ when /linux/
25
+ :linux
26
+ when /solaris|bsd/
27
+ :unix
28
+ else
29
+ raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
30
+ end
31
+ )
32
+ end
33
+
34
+ /---------------------------------RAKE JOBS-----------------------------------/
35
+
36
+ task :default => [:bindings, :build, :clean]
37
+
38
+ # Builds The RubyGL Shared Library From C Source Files And SDL Library
39
+ task :build do
40
+ files = ['Window', 'GLContext', 'Input', 'OpenGL']
41
+
42
+ # Build Object Files
43
+ obj = "gcc -I#{SDL_INCLUDE} -I#{PROJ_INCLUDE} -c -fPIC REPLACE.c -o REPLACE.o"
44
+ files.each { |file|
45
+ sh (obj.gsub(/REPLACE/, PROJ_SRC + file))
46
+ file = file.prepend PROJ_SRC
47
+ }
48
+
49
+ # Build Shared Object File
50
+ bin = "gcc -L#{SDL_LIB} #{files.join('.o ') << '.o'} -lSDL2main -lSDL2 \
51
+ -lopengl32 -shared -o ext/#{os.to_s}/RubyGL.so"
52
+ sh bin
53
+ end
54
+
55
+ # Created The Documentation For The Library
56
+ task :doc do
57
+ sh "rdoc lib/*"
58
+ end
59
+
60
+ # Clean Out Generated Files Silently
61
+ task :clean do
62
+ FileUtils.rm_r('doc', {:secure => true, :force => true})
63
+
64
+ FileUtils.rm_f(PROJ_INCLUDE + '/OpenGL.h')
65
+
66
+ FileUtils.rm_f(PROJ_SRC + '/OpenGL.c')
67
+
68
+ FileUtils.rm_f Dir.glob(PROJ_SRC + '/*.o')
69
+ end
70
+
71
+ # Generate Updated OpenGL Bindings
72
+ task :bindings do
73
+ gl_api, gl_version, shared_lib = 'gl', '4.5C', 'RubyGL.so'
74
+
75
+ Dir.mktmpdir { |dir|
76
+ # Generates C Header And Source Files
77
+ sh "ruby bin/gl_code_gen.rb #{gl_api} #{gl_version} OpenGL #{dir}"
78
+
79
+ # Run Preprocessor On C Source File
80
+ sh "gcc -E -I#{SDL_INCLUDE} -o #{dir}/OpenGL.o #{dir}/OpenGL.c"
81
+
82
+ # Pipe Preprocessor(ed) File And Header File To Generate Bindings
83
+ sh "ruby bin/ffi_code_gen.rb #{dir}/OpenGL.o #{dir}/OpenGL.h \
84
+ #{dir}/opengl.rb #{shared_lib}"
85
+
86
+ # Move Files To Correct Folders
87
+ mv "#{dir}/OpenGL.h", PROJ_INCLUDE
88
+ mv "#{dir}/OpenGL.c", PROJ_SRC
89
+ mv "#{dir}/opengl.rb", "lib/rubygl/native/"
90
+ }
91
+ end
92
+
93
+ # Run All Tests In The tests Directory
94
+ Rake::TestTask.new do |t|
95
+ t.libs << 'test' << 'lib/rubygl'
96
+ t.test_files = FileList['test/test*.rb']
97
+ t.verbose = true
98
+ end