opengl3 0.0.1.pre4 → 0.0.1.pre5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # OpenGL (opengl3)
2
+
3
+ OpenGL wrapper library for Ruby
4
+
5
+ * Pure Ruby, no C/C++/Java extension included (thanks to ffi gem)
6
+ * OpenGL 2.1 ~ 4.2
7
+ * automatic error checking each function call
8
+ * Ruby-style wrapper (not complete)
9
+ * Inspired by PyOpenGL
10
+
11
+ Tested on
12
+
13
+ * Mac OS X 10.8 (MRI 1.9.3, Rubinius)
14
+ * Linux (MRI 1.9.3, JRuby 1.7, Rubinius)
15
+ * Windows (JRuby 1.7)
16
+
17
+ ## Notice
18
+
19
+ Since the project is not complete, many functions are still C-style.
20
+ But don't worry, the gem makes use of `ffi` gem to import functions, and
21
+ therefore you can use ffi objects like `FFI::MemoryPointer` to work
22
+ with C-style OpenGL entrypoints.
23
+
24
+ ## Ruby-Style OpenGL APIs
25
+
26
+ Please take a look at `lib/opengl/wrapper/**/*.rb`
27
+ to see if entrypoints are wrapped.
28
+
29
+
30
+
31
+ * `glGetString(pname)` -> `String`
32
+ * `glGen...`-like functions
33
+ - `glGenTextures(count)` -> `Array<Integer>`
34
+ - `glGenBuffers(count)` -> `Array<Integer>`
35
+ - and more ...
36
+ * `glDelete...`-like functions
37
+ - `glDeleteTextures(Array<Integer>)`
38
+ - `glDeleteBuffers(Array<Integer>)`
39
+ - and more ...
40
+ * `glGet...`-like functions
41
+ - `glGetIntegerv(pname, count)` -> `Array<Integer>`
42
+ - `glGetFloatv(pname, count)` -> `Array<Float>`
43
+ - `glGetTexParameteriv(target, pname, count)` -> `Array<Integer>`
44
+ - `glGetTexParameterfv(target, pname, count)` -> `Array<Float>`
45
+ - `glGetShaderiv(shader, pname, count)` -> `Array<Integer>`
46
+ - and more ...
47
+ * `glShaderSource(shader, Array<String>)`
48
+ * `glGetShaderInfoLog(shader)` -> `String`
49
+ * `glGetProgramInfoLog(program)` -> `String`
50
+ * More Ruby-style functions coming soon
51
+
52
+ block-style glMapBuffer / glMapBufferRange:
53
+
54
+ ```ruby
55
+ glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY) do |ptr|
56
+ ptr.put_array_of_GLfloat(offset_in_bytes, [ 1.0, 2.0, 3.0 ])
57
+ end
58
+ ```
59
+
60
+ And helper functions
61
+
62
+ * `glGetVersion()` -> `Array<Integer>`
63
+ * `glGetShadingLanguageVersion()` -> `Array<Integer>`
64
+ * `glGetAvailableExtensions()` -> `Array<String>`
65
+ * `glIsShaderCompiled?(shader)` -> `Boolean`
66
+ * `glIsProgramLinked?(program)` -> `Boolean`
67
+ * `glUniformMatrixf(location, Matrix, transpose = true)` (Experimental)
68
+ * More helper functions coming soon
69
+
70
+ Note for functions has a offset with GLvoid* type
71
+ (ex: `glDrawElements`, `glVertexAttribPointer`)
72
+
73
+ ```ruby
74
+ offset_in_bytes = 0
75
+ glVertexAttribPointer 0, 3, GL_FLOAT, GL_FALSE, 0,
76
+ OpenGL::Type.pointer_offset(offset_in_bytes)
77
+ ```
78
+
79
+ ## Installation
80
+
81
+ Add this line to your application's Gemfile:
82
+
83
+ gem 'opengl3', :require => 'opengl'
84
+
85
+ And then execute:
86
+
87
+ $ bundle
88
+
89
+ Or install it yourself as:
90
+
91
+ $ gem install opengl3
92
+
93
+ ## Usage
94
+
95
+ ```ruby
96
+ require 'opengl'
97
+ class App
98
+ include OpenGL::Constants
99
+
100
+ def initialize
101
+ # ... (window created)
102
+ self.extend OpenGL::GL.entrypoints
103
+ # OK, you can use OpenGL now
104
+ end
105
+
106
+ end
107
+ ```
108
+
109
+ ## Contributing
110
+
111
+ 1. Fork it
112
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
113
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
114
+ 4. Push to the branch (`git push origin my-new-feature`)
115
+ 5. Create new Pull Request
@@ -1,3 +1,3 @@
1
1
  module OpenGL
2
- VERSION = "0.0.1.pre4"
2
+ VERSION = "0.0.1.pre5"
3
3
  end
@@ -77,7 +77,9 @@ module OpenGL
77
77
  # @param [String, Array<String>] codes
78
78
  #
79
79
  def glShaderSource(shader, codes)
80
- pointers = Array(codes).map{|s| FFI::MemoryPointer.from_string(s) }
80
+ pointers = Array(codes).map{|s|
81
+ s.is_a?(FFI::Pointer) ? s : FFI::MemoryPointer.from_string(s)
82
+ }
81
83
  ptr = FFI::MemoryPointer.new(:pointer, pointers.count)
82
84
  ptr.write_array_of_pointer(pointers)
83
85
  super(shader, pointers.count, ptr, nil)
@@ -101,5 +103,25 @@ module OpenGL
101
103
  glGetProgramiv(program, Constants::GL_LINK_STATUS, 1)[0] != 0
102
104
  end
103
105
 
106
+ # a variant of glUniformMatrix*fv
107
+ #
108
+ # @param [GLint] location
109
+ # @param [Matrix] matrix
110
+ # @param [Boolean] transpose
111
+ #
112
+ def glUniformMatrixf(location, mat, transpose = true)
113
+ transpose = (transpose ? Constants::GL_TRUE : Constants::GL_FALSE)
114
+
115
+ # TODO: refactor it
116
+ if defined?(::Matrix) && mat.is_a?(::Matrix)
117
+ m, n = mat.row_size, mat.column_size
118
+ dim = (m == n ? "#{m}" : "#{n}x#{m}")
119
+
120
+ ptr = Type.GLfloat(m*n).write_array_of_GLfloat(mat.to_a.flatten)
121
+ end
122
+
123
+ send(:"glUniformMatrix#{dim}fv", location, 1, transpose, ptr)
124
+ end
125
+
104
126
  end
105
127
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opengl3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre4
4
+ version: 0.0.1.pre5
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-12 00:00:00.000000000 Z
12
+ date: 2013-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -248,6 +248,7 @@ files:
248
248
  - lib/opengl/wrapper/core/4_2/GL_VERSION_4_2.rb
249
249
  - lib/opengl/wrapper.rb
250
250
  - lib/opengl.rb
251
+ - README.md
251
252
  homepage: https://github.com/davll/ruby-opengl
252
253
  licenses: []
253
254
  post_install_message: