ruby-opengl 0.50.0 → 0.60.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/Rakefile +15 -11
  2. data/doc/build_install.txt +10 -6
  3. data/doc/extensions.txt.in +348 -0
  4. data/doc/history.txt +4 -0
  5. data/doc/roadmap.txt +4 -6
  6. data/doc/scientific_use.txt +7 -0
  7. data/doc/supplies/page_template.html +2 -1
  8. data/doc/thanks.txt +5 -0
  9. data/doc/tutorial.txt +431 -121
  10. data/examples/NeHe/nehe_lesson02.rb +1 -1
  11. data/examples/NeHe/nehe_lesson03.rb +1 -1
  12. data/examples/NeHe/nehe_lesson04.rb +1 -1
  13. data/examples/NeHe/nehe_lesson05.rb +1 -1
  14. data/examples/NeHe/nehe_lesson36.rb +1 -1
  15. data/examples/OrangeBook/brick.rb +3 -15
  16. data/examples/OrangeBook/particle.rb +2 -20
  17. data/examples/RedBook/aapoly.rb +1 -1
  18. data/examples/RedBook/aargb.rb +2 -2
  19. data/examples/RedBook/accanti.rb +1 -1
  20. data/examples/RedBook/accpersp.rb +1 -1
  21. data/examples/RedBook/alpha.rb +2 -2
  22. data/examples/RedBook/alpha3D.rb +1 -1
  23. data/examples/RedBook/bezcurve.rb +1 -1
  24. data/examples/RedBook/bezmesh.rb +1 -1
  25. data/examples/RedBook/checker.rb +1 -1
  26. data/examples/RedBook/clip.rb +1 -1
  27. data/examples/RedBook/colormat.rb +1 -1
  28. data/examples/RedBook/cube.rb +1 -1
  29. data/examples/RedBook/depthcue.rb +1 -1
  30. data/examples/RedBook/dof.rb +1 -1
  31. data/examples/RedBook/double.rb +1 -1
  32. data/examples/RedBook/drawf.rb +1 -1
  33. data/examples/RedBook/feedback.rb +1 -1
  34. data/examples/RedBook/fog.rb +1 -1
  35. data/examples/RedBook/font.rb +2 -2
  36. data/examples/RedBook/hello.rb +1 -1
  37. data/examples/RedBook/image.rb +4 -4
  38. data/examples/RedBook/lines.rb +1 -1
  39. data/examples/RedBook/list.rb +1 -1
  40. data/examples/RedBook/material.rb +1 -1
  41. data/examples/RedBook/mipmap.rb +1 -1
  42. data/examples/RedBook/model.rb +1 -1
  43. data/examples/RedBook/movelight.rb +1 -1
  44. data/examples/RedBook/pickdepth.rb +1 -1
  45. data/examples/RedBook/planet.rb +5 -5
  46. data/examples/RedBook/quadric.rb +1 -1
  47. data/examples/RedBook/robot.rb +5 -5
  48. data/examples/RedBook/select.rb +1 -1
  49. data/examples/RedBook/smooth.rb +1 -1
  50. data/examples/RedBook/stencil.rb +1 -1
  51. data/examples/RedBook/stroke.rb +2 -2
  52. data/examples/RedBook/surface.rb +1 -1
  53. data/examples/RedBook/teaambient.rb +1 -1
  54. data/examples/RedBook/teapots.rb +1 -1
  55. data/examples/RedBook/tess.rb +1 -1
  56. data/examples/RedBook/texbind.rb +1 -1
  57. data/examples/RedBook/texgen.rb +5 -5
  58. data/examples/RedBook/texturesurf.rb +1 -1
  59. data/examples/RedBook/varray.rb +1 -1
  60. data/examples/RedBook/wrap.rb +5 -5
  61. data/examples/misc/OGLBench.rb +337 -0
  62. data/examples/misc/anisotropic.rb +1 -1
  63. data/examples/misc/fbo_test.rb +356 -0
  64. data/examples/misc/font-glut.rb +1 -1
  65. data/examples/misc/glfwtest.rb +30 -0
  66. data/examples/misc/md2model.rb +15 -0
  67. data/examples/misc/plane.rb +1 -1
  68. data/examples/misc/readpixel.rb +1 -1
  69. data/examples/misc/sdltest.rb +34 -0
  70. data/examples/misc/trislam.rb +828 -0
  71. data/ext/common/common.h +126 -218
  72. data/ext/common/conv.h +244 -0
  73. data/ext/common/funcdef.h +280 -0
  74. data/ext/common/gl-error.h +23 -0
  75. data/ext/common/gl-types.h +14 -0
  76. data/ext/gl/gl-1.0-1.1.c +497 -1255
  77. data/ext/gl/gl-1.2.c +121 -304
  78. data/ext/gl/gl-1.3.c +78 -339
  79. data/ext/gl/gl-1.4.c +102 -164
  80. data/ext/gl/gl-1.5.c +42 -173
  81. data/ext/gl/gl-2.0.c +273 -1039
  82. data/ext/gl/gl-2.1.c +15 -19
  83. data/ext/gl/gl-enums.c +3 -2
  84. data/ext/gl/gl-error.c +104 -0
  85. data/ext/gl/gl-ext-3dfx.c +27 -0
  86. data/ext/gl/gl-ext-arb.c +812 -12
  87. data/ext/gl/gl-ext-ati.c +41 -0
  88. data/ext/gl/gl-ext-ext.c +791 -119
  89. data/ext/gl/gl-ext-gremedy.c +41 -0
  90. data/ext/gl/gl-ext-nv.c +679 -0
  91. data/ext/gl/gl.c +48 -28
  92. data/ext/gl/mkrf_conf.rb +13 -10
  93. data/ext/glu/glu-enums.c +3 -2
  94. data/ext/glu/glu.c +136 -41
  95. data/ext/glu/mkrf_conf.rb +15 -12
  96. data/ext/glut/glut.c +37 -80
  97. data/ext/glut/mkrf_conf.rb +17 -13
  98. data/lib/opengl.rb +29 -53
  99. data/test/tc_common.rb +9 -3
  100. data/test/tc_ext_arb.rb +397 -3
  101. data/test/tc_ext_ati.rb +33 -0
  102. data/test/tc_ext_ext.rb +479 -2
  103. data/test/tc_ext_gremedy.rb +36 -0
  104. data/test/tc_ext_nv.rb +357 -0
  105. data/test/tc_func_10_11.rb +93 -67
  106. data/test/tc_func_12.rb +11 -11
  107. data/test/tc_func_13.rb +38 -18
  108. data/test/tc_func_14.rb +2 -2
  109. data/test/tc_func_15.rb +10 -10
  110. data/test/tc_func_20.rb +20 -20
  111. data/test/tc_func_21.rb +53 -22
  112. data/test/tc_glu.rb +9 -4
  113. data/test/tc_misc.rb +15 -2
  114. metadata +22 -8
  115. data/doc/extensions.txt +0 -361
  116. data/examples/RedBook/aaindex.rb +0 -97
  117. data/examples/misc/smooth.rb +0 -42
  118. data/examples/misc/test.rb +0 -65
@@ -60,3 +60,7 @@ of unit tests, creating near-complete support for OpenGL 2.1.
60
60
  Support for MS Windows was also added during this time.
61
61
 
62
62
  Version 0.40 was released in July 2007.
63
+
64
+ Version 0.50 was released in October 2007.
65
+
66
+ Version 0.60 was released in December 2007.
@@ -1,21 +1,19 @@
1
1
  Roadmap
2
2
  =======
3
3
 
4
- * Add ARB and other core OpenGL extensions
5
- * Write better getting started tutorial
6
4
  * Write comprehensive API documentation
7
5
  * Create more example code
6
+ * Add RMagick(ImageMagick) integration for easy image handling (textures,screenshots)
8
7
  * Support all pixelstore modes (currently forced to default values by
9
8
  any function getting/setting data affected by it)
10
- * Add direct mapping on ruby types for vertex arrays, buffers and image data to allow
11
- high performance data operations from within ruby (currently data has to be converted to/from string when being passed to OpenGL and so does not allow fast in-place modifications)
12
- - this should be modeled after Perl's OpenGL::Array
13
9
 
14
10
  Possible Features
15
11
  ========
16
12
  * Add **all** OpenGL extensions (some are obsolete or not really used or useful at all)
13
+ * Add direct mapping on ruby types for vertex arrays, buffers and image data to allow high performance data operations from within ruby
14
+ - this should be modeled after Perl's OpenGL::Array
15
+ - Update: preliminary tests shows that performance-wise there is no need for it, as the Ruby interpreter overhead is currently larger than immediate-mode calls overhead, so any potential speed gains are in domain of 1-5%. It still may be good idea from usability perspective, although that would require more comprehensive design, not just simple wrapper.
17
16
  * Support for r/w VBO buffer mapping - gl(Un)MapBuffer (is it needed?)
18
- * Add image handling wrapper for easy image handling (textures,screenshots) using RMagick (ImageMagick) - this may not be needed as API as using RMagick to do this stuff is trivial, maybe writing usage guide as part of tutorial is better alternative
19
17
 
20
18
  <br/>
21
19
  <br/>
@@ -26,3 +26,10 @@ Links
26
26
  * <http://narray.rubyforge.org/> -- Numerical n-dimensional Array class.
27
27
  * <http://www.kitp.ucsb.edu/~paxton/tioga.html> -- Tioga. Create plots using
28
28
  Ruby and TeX.
29
+
30
+ <br/>
31
+ <br/>
32
+ <br/>
33
+ <br/>
34
+ <br/>
35
+ <br/>
@@ -24,10 +24,11 @@
24
24
  </ul>
25
25
 
26
26
  <div id="sidebar">
27
+ <img src="./images/ogl.jpg">
27
28
  <h3>Contact</h3>
28
29
  <ul>
29
30
  <li><a href="http://rubyforge.org/mail/?group_id=2103">Mailing list</a></li>
30
- <li><a href="http://rubyforge.org/tracker/?atid=8185&group_id=2103&func=browse">Bug tracker</a></li>
31
+ <li><a href="http://rubyforge.org/tracker/?atid=8185&amp;group_id=2103&amp;func=browse">Bug tracker</a></li>
31
32
  <li><a href="http://rubyforge.org/projects/ruby-opengl">Project page</a></li>
32
33
  </ul>
33
34
  <h3>Download</h3>
@@ -22,3 +22,8 @@ Aside from big thank-you's to the core devs, special thanks also goes to:
22
22
  <br/>
23
23
  <br/>
24
24
  <br/>
25
+ <br/>
26
+ <br/>
27
+ <br/>
28
+ <br/>
29
+ <br/>
@@ -1,105 +1,456 @@
1
- Usage tutorial
1
+ Usage Tutorial
2
2
  ==============
3
+ This page should serve as tutorial and also as reference to Ruby bindings for OpenGL
4
+ language. It is assumed that you have basic understanding of both OpenGL and Ruby.
3
5
 
4
- Naming conventions
5
- ------------------
6
-
7
- There are two ways to use ruby-opengl. Firstly, you can use customary
8
- C-style method names and constant names like so:
9
-
10
- {{ruby}}
11
- require 'gl'
12
- require 'glu'
13
- require 'glut'
14
-
15
- include Gl
16
- include Glu
17
- include Glut
6
+ If you are new to OpenGL, you can start by visiting [OpenGL homepage](http://www.opengl.org)
7
+ , reading the [OpenGL Programming Guide](http://opengl.org/documentation/books/#the_opengl_programming_guide_the_official_guide_to_learning_opengl_version) (also known as Red Book) or going to [NeHe's tutorials page](http://nehe.gamedev.net/).
18
8
 
19
- glFooBar( GL_FOO_BAR )
20
- gluFooBar( GLU_FOO_BAR )
21
- glutFooBar( GLUT_FOO_BAR )
9
+ If you are new to Ruby, [the ruby-lang website](http://www.ruby-lang.org/en/documentation/) contains lots of
10
+ documentation and manuals for Ruby.
22
11
 
23
- You don't have to `include` Gl, Glu, and Glut, but if you don't, then
24
- you'll have to prefix each of those method and constant names like so:
25
-
26
- {{ruby}}
27
- require 'gl'
28
- require 'glu'
29
- require 'glut'
12
+ Table of Contents
13
+ ==============
14
+ Basics:
15
+ * [Naming Conventions](#naming_conventions)<br/>
16
+ * [Function parameters](#function_parameters)<br/>
17
+ * [Return values](#return_values)<br/>
18
+ * [Matrices](#matrices)<br/>
19
+ * [Textures and other raw data](#textures)<br/>
20
+ * [Error Checking](#error_checking)<br/>
21
+ * [Examples](#examples)<br/>
22
+
23
+ Advanced stuff:
24
+ * [OpenGL version and Extensions](#extensions)<br/>
25
+ * [Selection and Feedback queries](#selection_feedback)<br/>
26
+ * [Vertex Arrays](#vertex_arrays)<br/>
27
+ * [Buffer Objects](#buffer_objects)<br/>
28
+ * [GLUT, SDL, GLFW..](#glut_sdl)<br/>
29
+ * [GLUT callbacks](#glut_callbacks)<br/>
30
+ * [Internals](#internals)<br/>
31
+
32
+ API reference:
33
+ * TODO
34
+
35
+ <a name="naming_conventions"></a>
36
+ Naming conventions
37
+ ------------------
30
38
 
31
- Gl.glFooBar( Gl::GL_FOO_BAR )
32
- Glu.gluFooBar( Glu::GLU_FOO_BAR )
33
- Glut.glutFooBar( Glut::GLUT_FOO_BAR )
39
+ The bindings contains three modules:
40
+ * 'Gl' - OpenGL functions itself
41
+ * 'Glu' - OpenGL Utility Library API - higher-level drawing routines, NURBS etc.
42
+ * 'Glut' - OpenGL Utility Toolkit - low level functions such as creating OpenGL
43
+ context, opening window or handling user input
44
+
45
+ You can import all three modules by calling
46
+
47
+ {{ruby}}
48
+ require 'opengl'
49
+
50
+ You can also load the modules separately by using:
51
+
52
+ {{ruby}}
53
+ require 'gl'
54
+ require 'glu'
55
+ require 'glut'
56
+
57
+ The functions and constants are named the same as their C counterparts:
58
+
59
+ {{ruby}}
60
+ require 'opengl'
61
+ ...
62
+ Gl.glFooBar( Gl::GL_FOO_BAR )
63
+ Glu.gluFooBar( Glu::GLU_FOO_BAR )
64
+ Glut.glutFooBar( Glut::GLUT_FOO_BAR )
65
+
66
+ This is the 'full' syntax, usefull when you are expecting name clashes
67
+ with other modules, or just want to be formal ;) More often, you will
68
+ want to use the 'C-style' syntax, which you can accomplish by using 'include'
69
+ to export the module functions and constants to global namespace:
70
+
71
+ {{ruby}}
72
+ require 'opengl'
73
+ include Gl,Glu,Glut
74
+ ...
75
+ glFooBar( GL_FOO_BAR )
76
+ gluFooBar( GLU_FOO_BAR )
77
+ glutFooBar( GLUT_FOO_BAR )
78
+
79
+ Finally, you can use the 'old' syntax:
80
+
81
+ {{ruby}}
82
+ require 'opengl'
83
+ ...
84
+ # Note the missing prefixes in functions and constants
85
+ # and also capitalization of module names
86
+ GL.FooBar( GL::FOO_BAR )
87
+ GLU.FooBar( GLU::FOO_BAR )
88
+ GLUT.FooBar( GLUT::FOO_BAR )
89
+
90
+ This syntax was used by previous ruby-opengl versions; some people also
91
+ consider it as being more in the spirit of OO programming. It has one
92
+ downside though - due to Ruby's naming scheme, you cannot use constants
93
+ which begins with number, e.g. GL_2D would under this syntax be (GL::)2D
94
+ which is illegal.
95
+
96
+ All three variants of syntax will continue to be supported in future,
97
+ so it's up to you which one you choose to use.
98
+
99
+ The rest of this tutorial will use the C syntax.
100
+
101
+ Calling syntax
102
+ --------------
103
+ <a name="function_parameters"></a>
104
+ Function parameters
105
+ --------------
106
+ For most types the ruby syntax follows the C API. If needed, ruby will do
107
+ automatic parameter conversion to required type if possible. Example:
108
+
109
+ {{ruby}}
110
+ glVertex3f( 1.0, 1.0, 1.0 ) # matches C syntax
111
+ glVertex3f( 1, 1, 1 ) # equivalent to the above
112
+ glVertex3f( "string", 1, 1 ) # raises TypeError exception
113
+
114
+ Arrays are passed/received as Ruby arrays:
115
+
116
+ {{ruby}}
117
+ vertex = [ 1, 1, 1 ]
118
+ glVertex3fv( vertex )
119
+
120
+ For functions with multiple parameter-number variations (glVertex,glColor,...)
121
+ we define 'overloaded' functions, as in:
122
+
123
+ {{ruby}}
124
+ glVertexf( 1, 1 ) # will call glVertex2f()
125
+ glVertexf( 1, 1, 1 ) # will call glVertex3f()
126
+ glVertexf( 1, 1, 1, 1 ) # will call glVertex4f()
127
+ glVertexi( 1, 1 ) # will call glVertex2i()
128
+ ...
129
+ # and so on
130
+
131
+ <a name="return_values"></a>
132
+ Return values
133
+ -------------
134
+ In C, OpenGL functions rarely return values directly, instead you pass in pointer to
135
+ preallocated buffer and they will fill it with values; sometimes you have to even query
136
+ how big buffer you'll need to allocate. Ruby does this all for you, returning either single
137
+ value or array:
138
+
139
+ {{ruby}}
140
+ glColor4f( 1.0, 1.0, 1.0, 1.0 )
141
+ ...
142
+ color = glGetDoublev(GL_CURRENT_COLOR)
143
+ p color # will be [1.0,1.0,1.0,1.0]
144
+
145
+ <a name="matrices"></a>
146
+ Matrices
147
+ -------------
148
+ Matrices are passed and received as ruby array, or as ruby Matrix objects:
149
+
150
+ {{ruby}}
151
+ matrix_a = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
152
+ matrix_b = [ [ 0, 1, 2, 3 ],
153
+ [ 4, 5, 6, 7 ],
154
+ [ 8, 9,10,11 ],
155
+ [ 12,13,14,15 ] ]
156
+ matrix_c = Matrix.rows( [ [ 0, 1, 2, 3 ],
157
+ [ 4, 5, 6, 7 ],
158
+ [ 8, 9,10,11 ],
159
+ [ 12,13,14,15 ] ] )
160
+ ...
161
+ glLoadMatrixf(matrix_a)
162
+ glLoadMatrixf(matrix_b)
163
+ glLoadMatrixf(matrix_c) # same result
164
+
165
+ You may also create your own matrix class and pass it this way, provided that it
166
+ is convertible to array (has 'to_a' method).
167
+
168
+ Note that as OpenGL uses column-major
169
+ notation for matrices, you may need to call transpose() when working with
170
+ row-major matrices or arrays in ruby.
171
+
172
+ <a name="textures"></a>
173
+ Textures and other raw data
174
+ -------------
175
+ Data for textures, arrays, buffers etc. can be specified either as ruby arrays or directly as raw packed strings -
176
+ strings that contains their direct memory representation (just like C arrays). If you need to convert between
177
+ ruby arrays and these strings, use ruby Array#pack() and String#unpack() functions.
178
+ Example:
179
+
180
+ {{ruby}}
181
+ # create texture, 2x2 pixels,
182
+ # 3 components (R,G,B) for each pixel as floats
183
+ texture = [
184
+ 1.0, 0.0, 0.0, # 1st pixel, red
185
+ 0.0, 1.0, 0.0, # 2nd pixel, green
186
+ 0.0, 0.0, 1.0, # 3rd pixel, blue
187
+ 1.0, 1.0, 1.0 # 4th pixel, white
188
+ ]
189
+ # convert it to string
190
+ # f = native float representation
191
+ # * = convert all values in the array the same way
192
+ data = texture.pack("f*")
193
+ ...
194
+ glTexImage2D(
195
+ GL_TEXTURE_2D, # target
196
+ 0, # mipmap level,
197
+ GL_RGB8, # internal format
198
+ 2, 2, # width, height
199
+ 0, # border = no
200
+ GL_RGB, # components per each pixel
201
+ GL_FLOAT, # component type - floats
202
+ data # the packed data
203
+ )
204
+
205
+ Reverse works just the same:
206
+
207
+ {{ruby}}
208
+ ...
209
+ data = glGetTexImage( # returns the packed data as string
210
+ GL_TEXTURE_2D, # target
211
+ 0, # mipmap level
212
+ GL_RGB, # components per pixel
213
+ GL_FLOAT # component type
214
+ )
215
+ # now convert it to ruby array
216
+ texture = data.unpack("f*")
217
+ ...
218
+
219
+ For storage, packed strings are more memory efficient than ruby arrays, but
220
+ cannot be easily changed or manipulated.
221
+
222
+ <a name="error_checking"></a>
223
+ Error Checking
224
+ --------------
225
+ Starting with version 0.60.0, ruby-opengl performs automatic checking of OpenGL and GLU errors.
226
+ Functions:
227
+
228
+ {{ruby}}
229
+ Gl.enable_error_checking
230
+ Gl.disable_error_checking
231
+ Gl.is_error_checking_enabled? # true/false
232
+
233
+ When the checking is enabled (default), glGetError() is executed after each OpenGL call, and should error
234
+ occur, Gl::Error exception is raised:
235
+
236
+ {{ruby}}
237
+ Gl.enable_error_checking
238
+ ...
239
+ begin
240
+ ...
241
+ glEnable(GL_TRUE) # will raise exception
242
+ ...
243
+ rescue Gl::Error => err
244
+ # err.id contains the OpenGL error ID
245
+ if (err.id == GL_INVALID_ENUM)
246
+ puts "Oh noes! You used invalid enum!"
247
+ ...
248
+ end
249
+ ...
250
+ end
251
+
252
+ Some GLU functions may also throw Glu::Error - the handling is the same as above.
253
+
254
+ It is usually good idea to leave error checking on for all your code, as OpenGL errors have habit to pop-up in
255
+ unexpected places. For now there is no measurable performance hit for error checking, although this may depend
256
+ on your graphic drivers implementation.
257
+
258
+ <a name="examples"></a>
259
+ The Examples
260
+ -----------
34
261
 
35
- The other way you might use ruby-opengl is to employ the notation that
36
- users of previous versions of ruby-opengl have used:
262
+ Various examples are in 'examples' directory of the bindings. To run them, manually pass them to `ruby` like:
37
263
 
38
- {{ruby}}
39
- require 'opengl'
40
-
41
- GL.FooBar( GL::FOO_BAR )
42
- GLU.FooBar( GLU::FOO_BAR )
43
- GLUT.FooBar( GLUT::FOO_BAR )
264
+ ruby some_sample.rb
44
265
 
45
- There are many fine OpenGL and GLUT tutorials all over the 'Net, so we
46
- don't plan on trying to duplicate them here at the moment. Most of
47
- these tutorials presume you are writing your code in C or C++, but
48
- they should still be almost directly usable with ruby-opengl as long
49
- as you use the C-style names (and, of course, as long as you change
50
- the rest of the C code you find from C (or C++) to Ruby). If you opt
51
- for using the legacy ruby-opengl style names, you'll have to take the
52
- additional step of converting the calls from `glFooBar( GL_FOO_BAR )`
53
- to `GL.FooBar( GL::FOO_BAR )`.
266
+ On windows, you may want to use 'rubyw' instead, which displays the standard output window
267
+ as some examples use the console for usage info etc.
54
268
 
55
- Personally, I prefer the current C-style names because:
269
+ If you get 'opengl not found' error, and you installed ruby-opengl from gems, your
270
+ shell or ruby installation is probably not configured to use the gems; in that case type:
56
271
 
57
- 1. It's somewhat easier to follow along with the many online tutorials
58
- and written OpenGL/GLUT books (i.e. the RedBook, BlueBook, SuperBible,
59
- etc.).
272
+ ruby -rubygems some_sample.rb
60
273
 
61
- 2. Copying/pasting code between Ruby and C is easier (otherwise you'll
62
- be doing a lot of search/replace).
274
+ The `README` file in the `examples` directory contains some notes on the examples.
63
275
 
64
- 3. My fingers are already used to typing the traditional C-style names
65
- of all these identifiers.
276
+ <a name="extensions"></a>
277
+ OpenGL Version and Extensions
278
+ -----------
279
+ To query for available OpenGL version or OpenGL extension, use Gl.is_available? function:
280
+
281
+ {{ruby}}
282
+ # true if OpenGL version is 2.0 or later is available
283
+ Gl.is_available?(2.0)
284
+ ...
285
+ # returns true if GL_ARB_shadow is available on this system
286
+ Gl.is_available?("GL_ARB_shadow")
287
+
288
+ For list of what extensions are supported in ruby-opengl see this [page](extensions.html)
289
+
290
+ The extensions' function names once again follows the C API. Some extensions were over time
291
+ promoted to ARB or even to OpenGL core, retaining their function names just with suffix changed
292
+ or removed. However sometimes the functions semantics was changed in the process, so to avoid
293
+ confusion, ruby-opengl bindings will strictly adhere to the C naming, e.g. :
294
+
295
+ {{ruby}}
296
+ # will call the function from GL_ARB_transpose_matrix extension
297
+ glLoadTransposeMatrixfARB(matrix)
298
+ ...
299
+ # will call the function from OpenGL 1.3
300
+ glLoadTransposeMatrixf(matrix)
301
+
302
+ <b>Note:</b> ruby-opengl is compiled against OpenGL 1.1, and all functions and enums from later
303
+ versions of OpenGL and from extensions are loaded dynamically at runtime. That means that all
304
+ of OpenGL 2.1 and supported extensions are available even if the ruby-opengl bindings are
305
+ compiled on platform which lacks proper libraries or headers (like for example Windows without
306
+ installed graphic drivers). This should ease binary-only distribution and application packaging.
307
+
308
+
309
+ <a name="selection_feedback"></a>
310
+ Selection/Feedback queries
311
+ -----------
312
+ Querying selection and feedback is different from C. Example:
313
+
314
+ {{ruby}}
315
+ # this will create selection buffer 512*sizeof(GLuint) long
316
+ buf = glselectbuffer(512)
317
+ # enter feedback mode
318
+ glRenderMode(GL_SELECT)
319
+ ... # draw something here
320
+ # return to render mode
321
+ count = glRenderMode(GL_RENDER)
322
+ # at this point the buf string is freezed and contains
323
+ # the selection data, which you can recover with unpack
324
+ # function
325
+ data = buf.unpack("I*") # I for unsigned integer
326
+ # also, next call to glRenderMode(GL_SELECT) will overwrite
327
+ # the 'buf' buffer with new data
328
+
329
+ The feedback query follows the same pattern, only the data are stored
330
+ as floats.
331
+
332
+ <a name="vertex_arrays"></a>
333
+ Vertex Arrays
334
+ -----------
335
+ In current state, vertex arrays are not very efficient in ruby-opengl, as it is not possible to change
336
+ the array content once it is specified, and there is overhead for converting between ruby and C representation
337
+ of numbers. Using display lists for static and immediate mode for dynamic objects is recommended instead.
66
338
 
67
- Also, I don't like the fact that, if you use the previous ruby-opengl
68
- style, you've got method names starting with a capital letter (which is
69
- not customary Ruby style).
339
+ You can specify the data the same way as [texture data](#textures). Example:
70
340
 
71
- For the rest of this document, I'll use the current C-style names.
341
+ {{ruby}}
342
+ normals = [0,1,0, 1,0,0, 1,1,1]
343
+ glNormalPointer(GL_FLOAT,0,normals)
344
+ ...
345
+ glEnable(GL_NORMAL_ARRAY)
346
+ glDrawArrays(...)
347
+ ...
72
348
 
349
+ This applies to all *pointer functions. glGetPointerv will return reference to the frozen string
350
+ previously specified.
73
351
 
352
+ <a name="buffer_objects"></a>
353
+ Buffer Objects
354
+ -----------
355
+ Once again, in current state buffer objects (VBOs in particular) are not very efficient in ruby-opengl.
356
+ Unlike textures and vertex arrays, the data for buffers *must* be prepacked by using .pack() function,
357
+ as buffers does not retain information about the storage type. Mapping of the buffer afterwards is read-only.
358
+
359
+ Like in C, buffer binding affects some functions in way that if particular buffer is bound, the related
360
+ functions (for example glTexImage) take integer offset in place of data string argument. This is also true
361
+ for getter functions (e.g. glGetTexImage) - instead of returning the data string, they take offset as they're
362
+ last argument (so in ruby they take one extra argument), and will write the data in the bound buffer as expected.
363
+
364
+ VBO example:
365
+
366
+ {{ruby}}
367
+ # specify 3 vertices, 2*float each
368
+ data = [0,0, 0,1, 1,1].pack("f*")
369
+ ...
370
+ # generate buffer name
371
+ buffers = glGenBuffers(1)
372
+ # bind to the name to ARRAY buffer for vertex array
373
+ glBindBuffer(GL_ARRAY_BUFFER,buffers[0])
374
+ # here the data is specified, size is n*sizeof(float)
375
+ # note that you don't get to specify type, as buffers
376
+ # operate on byte level
377
+ glBufferData(GL_ARRAY_BUFFER,6*4,data,GL_DYNAMIC_DRAW)
378
+ ...
379
+ # here instead of specyfing the data, you pass '0' (or
380
+ # positive integer) as offset to the bound buffer
381
+ glVertexPointer(2,GL_FLOAT,0,0)
382
+ ...
383
+ glEnableClientState(GL_VERTEX_ARRAY)
384
+ ...
385
+
386
+ <a name="glut_sdl"></a>
387
+ GLUT, SDL, GLFW..
388
+ ---------
389
+ When it comes to low-level task like GL window creation, input and event handling, the first choice is GLUT,
390
+ as it is readilly available alongside OpenGL. However both GLUT itself and its implementations
391
+ have their drawbacks, and for that and other reasons there are number of replacement libraries.
392
+ You can use any of them with ruby-opengl (as long as there are ruby bindings for them).
393
+
394
+ Here is example for [SDL](http://www.kmc.gr.jp/~ohai/index.en.html):
395
+
396
+ {{ruby}}
397
+ require 'opengl'
398
+ require 'sdl'
399
+ # init
400
+ SDL.init(SDL::INIT_VIDEO)
401
+ SDL.setGLAttr(SDL::GL_DOUBLEBUFFER,1)
402
+ SDL.setVideoMode(512,512,32,SDL::OPENGL)
403
+ ...
404
+ Gl.glVertex3f(1.0,0.0,0.0)
405
+ ...
406
+ SDL.GLSwapBuffers()
407
+ ...
408
+
409
+ and another example for [GLFW](http://ruby-glfw.rubyforge.org/):
410
+
411
+ {{ruby}}
412
+ require 'opengl'
413
+ require 'glfw'
414
+ # init
415
+ Glfw.glfwOpenWindow( 500,500, 0,0,0,0, 32,0, Glfw::GLFW_WINDOW )
416
+ ...
417
+ Gl.glVertex3f(1.0,0.0,0.0)
418
+ ...
419
+ Glfw.glfwSwapBuffers()
420
+ ...
421
+
422
+ <a name="glut_callbacks"></a>
74
423
  GLUT callbacks
75
424
  --------------
76
425
 
77
- The major difference from your GL code in C is in how glut callbacks are
78
- handled. Rather than define your callbacks as top-level functions,
79
- with ruby-opengl, it's done (for example) like so:
426
+ The GLUT callback functions are specified as Proc objects, which you can
427
+ either create with lambda as:
80
428
 
81
- {{ruby}}
82
- reshape = lambda do |w, h|
83
- glViewport( ... )
84
- glMatrixMode( GL_PROJECTION )
85
- # etc.
86
- glMatrixMode( GL_MODELVIEW )
87
- glLoadIdentity
88
- end
429
+ {{ruby}}
430
+ reshape = lambda do |w, h|
431
+ ...
432
+ end
433
+ ...
434
+ glutReshapeFunc( reshape )
89
435
 
90
- # ...
91
-
92
- glutReshapeFunc( reshape )
436
+ or by conversion from normal functions:
93
437
 
94
- An older notation you'll see instead of `lambda` is `proc`. The PickAxe
95
- v2 notes that `proc` is "mildly deprecated" in favor of `lambda`. You'll
96
- also sometimes see `Proc.new` used in place of either. Pages 359-360 of
438
+ {{ruby}}
439
+ def reshape(w,h)
440
+ ...
441
+ end
442
+ ...
443
+ glutReshapeFunc( method("reshape").to_proc )
444
+
445
+ Note: An older notation you'll see instead of `lambda` is `proc`. The
446
+ PickAxe v2 notes that `proc` is "mildly deprecated" in favor of `lambda`.
447
+ You'll also sometimes see `Proc.new` used in place of either. Pages 359-360 of
97
448
  PickAxe v2 describe the differences between using `lambda` and `Proc.new`,
98
449
  but for our purposes either will be fine.
99
450
 
100
-
101
- Source code layout
102
- ------------------
451
+ <a name="internals"></a>
452
+ Internals
453
+ ---------
103
454
 
104
455
  The directory structure follows current Ruby standards, with a few
105
456
  extra directories added.
@@ -111,49 +462,8 @@ extra directories added.
111
462
  modules (gl, glu, glut). Herein are the files needed to compile the extension
112
463
  modules.
113
464
  * `lib/` -- Files that the user is meant to `require` in their own code.
114
- * `test/` -- Contains sample ruby files that make OpenGL and GLUT calls.
115
- * `utils` -- Some under-construction utility scripts used to help generate
116
- extension module source from GL header files. Also contains some scripts
117
- used to generate the ruby-opengl website.
465
+ * `test/` -- Contains automatic testsuite for the bindings
466
+ * `utils` -- Some utility scripts used to help generate code, documentation
467
+ and website.
118
468
  * `website` -- After running `rake gen_website` this directory will contain
119
469
  the ruby-opengl website.
120
-
121
-
122
- The Samples
123
- -----------
124
-
125
- To run the samples, manually pass them to `ruby` like so:
126
-
127
- ruby some_sample.rb
128
- ruby some_sample_prev.rb
129
-
130
- The names ending in `_prev.rb` have been "ported" to use the legacy method
131
- and constant names (and possibly have been neatened up a bit as well). The
132
- `README` file in the `samples` directory contains some notes on the samples.
133
-
134
-
135
- Mac OS X notes
136
- --------------
137
-
138
- James Adam passed along some fixes to ruby-opengl in 2005 on ruby-talk.
139
- Some methods have been incorporated into ruby-opengl-0.33. Paraphrasing
140
- James a bit, he writes:
141
-
142
- > 1. `CheckLoop` was added to bring the GLUT module in line with the
143
- > same function in Apple's GLUT. GLUT's MainLoop is blocking and forces
144
- > you to perform additoinal processing using GLUT's IdleFunc system,
145
- > which can sometimes be very undesirable (particularly if you are using
146
- > Ruby as the glue between two libraries which both feature this type of
147
- > loop). CheckLoop allows you to cycle through a *single* GLUT processing
148
- > loop, and then returns control to the calling thread/process. Thus, by
149
- > periodically calling CheckLoop, you can get the scene to update without
150
- > having GLUT seize control of the whole application.
151
- >
152
- > 2. `GameModeString(mode_string)` and `Glut.EnterGameMode()`. May allow you
153
- > to switch your application to fullscreen.
154
- >
155
- > 3. `BitmapCharacterX(char)` for displaying characters, since there seems to
156
- > be a problem with the default `GLUT.BitmapCharacter` method.
157
-
158
- Any feedback on testing of these methods is welcome, and will likely
159
- be incorporated into the ruby-opengl docs.