ruby-opengl 0.40.1 → 0.50.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. data/Rakefile +2 -2
  2. data/doc/build_install.txt +48 -28
  3. data/doc/extensions.txt +361 -0
  4. data/doc/history.txt +8 -2
  5. data/doc/requirements_and_design.txt +0 -13
  6. data/doc/roadmap.txt +11 -13
  7. data/doc/supplies/page_template.html +11 -5
  8. data/doc/thanks.txt +2 -4
  9. data/doc/tutorial.txt +1 -4
  10. data/examples/{nehe_lesson02.rb → NeHe/nehe_lesson02.rb} +0 -0
  11. data/examples/{nehe_lesson03.rb → NeHe/nehe_lesson03.rb} +0 -0
  12. data/examples/{nehe_lesson04.rb → NeHe/nehe_lesson04.rb} +0 -0
  13. data/examples/{nehe_lesson05.rb → NeHe/nehe_lesson05.rb} +0 -0
  14. data/examples/NeHe/nehe_lesson36.rb +303 -0
  15. data/examples/OrangeBook/3Dlabs-License.txt +33 -0
  16. data/examples/OrangeBook/brick.frag +36 -0
  17. data/examples/OrangeBook/brick.rb +388 -0
  18. data/examples/OrangeBook/brick.vert +41 -0
  19. data/examples/OrangeBook/particle.frag +17 -0
  20. data/examples/OrangeBook/particle.rb +424 -0
  21. data/examples/OrangeBook/particle.vert +38 -0
  22. data/examples/README +13 -83
  23. data/examples/RedBook/aaindex.rb +97 -0
  24. data/examples/RedBook/aapoly.rb +142 -0
  25. data/examples/RedBook/aargb.rb +119 -0
  26. data/examples/RedBook/accanti.rb +162 -0
  27. data/examples/RedBook/accpersp.rb +215 -0
  28. data/examples/RedBook/alpha.rb +123 -0
  29. data/examples/RedBook/alpha3D.rb +158 -0
  30. data/examples/RedBook/bezcurve.rb +105 -0
  31. data/examples/RedBook/bezmesh.rb +137 -0
  32. data/examples/RedBook/checker.rb +124 -0
  33. data/examples/RedBook/clip.rb +95 -0
  34. data/examples/RedBook/colormat.rb +135 -0
  35. data/examples/RedBook/cube.rb +69 -0
  36. data/examples/RedBook/depthcue.rb +99 -0
  37. data/examples/RedBook/dof.rb +205 -0
  38. data/examples/{legacy → RedBook}/double.rb +59 -58
  39. data/examples/{legacy → RedBook}/drawf.rb +47 -54
  40. data/examples/RedBook/feedback.rb +145 -0
  41. data/examples/RedBook/fog.rb +167 -0
  42. data/examples/RedBook/font.rb +151 -0
  43. data/examples/RedBook/hello.rb +79 -0
  44. data/examples/RedBook/image.rb +137 -0
  45. data/examples/{legacy → RedBook}/jitter.rb +60 -62
  46. data/examples/RedBook/lines.rb +128 -0
  47. data/examples/RedBook/list.rb +111 -0
  48. data/examples/RedBook/material.rb +275 -0
  49. data/examples/RedBook/mipmap.rb +156 -0
  50. data/examples/{legacy → RedBook}/model.rb +66 -72
  51. data/examples/{legacy → RedBook}/movelight.rb +67 -75
  52. data/examples/RedBook/pickdepth.rb +179 -0
  53. data/examples/{legacy → RedBook}/planet.rb +62 -66
  54. data/examples/RedBook/quadric.rb +158 -0
  55. data/examples/RedBook/robot.rb +115 -0
  56. data/examples/RedBook/select.rb +196 -0
  57. data/examples/RedBook/smooth.rb +95 -0
  58. data/examples/RedBook/stencil.rb +163 -0
  59. data/examples/RedBook/stroke.rb +167 -0
  60. data/examples/RedBook/surface.rb +166 -0
  61. data/examples/RedBook/teaambient.rb +132 -0
  62. data/examples/RedBook/teapots.rb +182 -0
  63. data/examples/RedBook/tess.rb +183 -0
  64. data/examples/RedBook/texbind.rb +147 -0
  65. data/examples/RedBook/texgen.rb +169 -0
  66. data/examples/RedBook/texturesurf.rb +128 -0
  67. data/examples/RedBook/varray.rb +159 -0
  68. data/examples/RedBook/wrap.rb +148 -0
  69. data/examples/misc/anisotropic.rb +194 -0
  70. data/examples/misc/font-glut.rb +46 -0
  71. data/examples/{plane.rb → misc/plane.rb} +0 -0
  72. data/examples/misc/readpixel.rb +65 -0
  73. data/examples/{smooth.rb → misc/smooth.rb} +0 -0
  74. data/examples/{test.rb → misc/test.rb} +0 -0
  75. data/ext/common/common.h +252 -70
  76. data/ext/common/gl-enums.h +6102 -7334
  77. data/ext/common/gl-types.h +47 -0
  78. data/ext/common/glu-enums.h +469 -0
  79. data/ext/gl/gl-1.0-1.1.c +842 -2464
  80. data/ext/gl/gl-1.2.c +217 -281
  81. data/ext/gl/gl-1.3.c +113 -133
  82. data/ext/gl/gl-1.4.c +98 -334
  83. data/ext/gl/gl-1.5.c +28 -34
  84. data/ext/gl/gl-2.0.c +26 -235
  85. data/ext/gl/gl-2.1.c +31 -124
  86. data/ext/gl/gl-enums.c +786 -631
  87. data/ext/gl/gl-ext-arb.c +66 -0
  88. data/ext/gl/gl-ext-ext.c +218 -0
  89. data/ext/gl/gl.c +138 -31
  90. data/ext/gl/mkrf_conf.rb +1 -0
  91. data/ext/glu/glu-enums.c +163 -0
  92. data/ext/glu/glu.c +1003 -1205
  93. data/ext/glu/mkrf_conf.rb +1 -0
  94. data/ext/glut/glut.c +1056 -1175
  95. data/lib/opengl.rb +90 -3
  96. data/test/tc_common.rb +26 -13
  97. data/test/tc_ext_arb.rb +73 -0
  98. data/test/tc_ext_ext.rb +74 -0
  99. data/test/tc_func_12.rb +8 -8
  100. data/test/tc_func_13.rb +17 -11
  101. data/test/tc_func_14.rb +8 -8
  102. data/test/tc_func_15.rb +190 -2
  103. data/test/tc_func_20.rb +36 -10
  104. data/test/tc_func_21.rb +445 -2
  105. data/test/tc_glu.rb +305 -0
  106. data/test/tc_misc.rb +1 -0
  107. metadata +84 -68
  108. data/doc/screenshots.txt +0 -23
  109. data/examples/legacy/COPYRIGHT +0 -8
  110. data/examples/legacy/aaindex.rb +0 -98
  111. data/examples/legacy/aapoly.rb +0 -153
  112. data/examples/legacy/aargb.rb +0 -139
  113. data/examples/legacy/accanti.rb +0 -159
  114. data/examples/legacy/accpersp.rb +0 -216
  115. data/examples/legacy/alpha.rb +0 -133
  116. data/examples/legacy/alpha3D.rb +0 -165
  117. data/examples/legacy/bezcurve.rb +0 -107
  118. data/examples/legacy/bezmesh.rb +0 -131
  119. data/examples/legacy/checker.rb +0 -121
  120. data/examples/legacy/clip.rb +0 -104
  121. data/examples/legacy/colormat.rb +0 -145
  122. data/examples/legacy/cube.rb +0 -73
  123. data/examples/legacy/depthcue.rb +0 -101
  124. data/examples/legacy/dof.rb +0 -212
  125. data/examples/legacy/feedback.rb +0 -152
  126. data/examples/legacy/fog.rb +0 -172
  127. data/examples/legacy/font-glut.rb +0 -41
  128. data/examples/legacy/font.rb +0 -158
  129. data/examples/legacy/hello.rb +0 -75
  130. data/examples/legacy/image.rb +0 -145
  131. data/examples/legacy/lines.rb +0 -135
  132. data/examples/legacy/list.rb +0 -120
  133. data/examples/legacy/material.rb +0 -290
  134. data/examples/legacy/mipmap.rb +0 -159
  135. data/examples/legacy/pickdepth.rb +0 -180
  136. data/examples/legacy/quadric.rb +0 -180
  137. data/examples/legacy/readpixel.rb +0 -59
  138. data/examples/legacy/robot.rb +0 -120
  139. data/examples/legacy/select.rb +0 -207
  140. data/examples/legacy/smooth.rb +0 -41
  141. data/examples/legacy/stencil.rb +0 -154
  142. data/examples/legacy/stroke.rb +0 -170
  143. data/examples/legacy/surface.rb +0 -170
  144. data/examples/legacy/teaambient.rb +0 -132
  145. data/examples/legacy/teapots.rb +0 -188
  146. data/examples/legacy/tess.rb +0 -222
  147. data/examples/legacy/texbind.rb +0 -157
  148. data/examples/legacy/texgen.rb +0 -171
  149. data/examples/legacy/texturesurf.rb +0 -128
  150. data/examples/legacy/varray.rb +0 -167
  151. data/examples/legacy/wrap.rb +0 -158
  152. data/lib/gl_prev.rb +0 -46
  153. data/lib/glu_prev.rb +0 -46
  154. data/lib/glut_prev.rb +0 -45
data/doc/history.txt CHANGED
@@ -52,5 +52,11 @@ Thu's original `utils/mkwrap.rb` script.
52
52
  Development stalled in October 2006.
53
53
 
54
54
  Development picked up again towards the end of 2006. After a long hiatus
55
- and getting a new release of mkrf out the door. ruby-opengl is proud
56
- to put out version 0.33.0 as a gem for everyone to try out.
55
+ and getting a new release of mkrf out the door, version 0.33 (following the
56
+ numbering of original Yoshi's bindings which stalled at 0.32) was released.
57
+
58
+ During first half of 2007, we added large portion of code, as well as number
59
+ of unit tests, creating near-complete support for OpenGL 2.1.
60
+ Support for MS Windows was also added during this time.
61
+
62
+ Version 0.40 was released in July 2007.
@@ -73,11 +73,6 @@ Requirements
73
73
  on the following platforms: Mac OS X, GNU/Linux. MS Windows operating
74
74
  systems may also be supported in the future.
75
75
 
76
- * Provide backwards compatiblity for the older ruby-opengl function and
77
- constant naming style (possibly in a layer built on top of the Base layers).
78
- The support should be as minimally invasive as possible, perhaps via:
79
- `require 'gl_prev'`, `require 'glu_prev'`, and `require 'glut_prev'`.
80
-
81
76
  * The project will make a number of pre-compiled extensions available as gems.
82
77
 
83
78
  * The project will supply source code and build scripts (via svn checkout)
@@ -86,14 +81,6 @@ Requirements
86
81
  * There shall be a test suite that exercises each call in each of the Base
87
82
  modules.
88
83
 
89
- * There shall be tools supplied which can:
90
-
91
- * generate source code from existing OpenGL/GLUT header files which,
92
- probably with some fine-tuning, can be used to update the module.
93
-
94
- * show differences in coverage between ruby-opengl and a given set
95
- of OpenGL/GLUT header files.
96
-
97
84
  * All project documentation will be in Markdown format in files that end in
98
85
  `.txt`.
99
86
 
data/doc/roadmap.txt CHANGED
@@ -1,23 +1,21 @@
1
1
  Roadmap
2
2
  =======
3
3
 
4
- * Ensure support for 2.0 and 2.1 is solid
5
- * Make sure OpenGL 1.0 and 1.1 are solidly supported
6
- * Continue testing 1.2+ support
7
- * Create a set of test images for functional test comparison
8
- * Get BaseGLUT updated.
9
- * Add RDoc documentation comments to C API
10
- * Make sure this can build cleanly under Windows under the current
11
- build system.
12
- * Add the ESC keyboard handler to smooth.rb
13
- * Add all of Yoshi's examples into examples
4
+ * Add ARB and other core OpenGL extensions
5
+ * Write better getting started tutorial
6
+ * Write comprehensive API documentation
14
7
  * Create more example code
15
- * Write a getting started tutorial
16
-
8
+ * Support all pixelstore modes (currently forced to default values by
9
+ 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
17
13
 
18
14
  Possible Features
19
15
  ========
20
- * Possibly port GLU to use Ruby/DL
16
+ * Add **all** OpenGL extensions (some are obsolete or not really used or useful at all)
17
+ * 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
21
19
 
22
20
  <br/>
23
21
  <br/>
@@ -17,21 +17,27 @@
17
17
  <ul id="tabnav">
18
18
  <li><a href="./index.html">Home</a></li>
19
19
  <li><a href="./tutorial.html">Tutorial</a></li>
20
- <li><a href="./screenshots.html">Screenshots</a></li>
21
- <li><a href="./requirements_and_design.html">Req's doc</a></li>
22
20
  <li><a href="./build_install.html">Build/Install</a></li>
23
- <li><a href="./history.html">History</a></li>
24
21
  <li><a href="./roadmap.html">Roadmap</a></li>
22
+ <li><a href="./requirements_and_design.html">Req's doc</a></li>
23
+ <li><a href="./history.html">History</a></li>
25
24
  </ul>
26
25
 
27
26
  <div id="sidebar">
28
27
  <h3>Contact</h3>
29
28
  <ul>
30
29
  <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/projects/ruby-opengl">Project page</a></li>
32
+ </ul>
33
+ <h3>Download</h3>
34
+ <ul>
35
+ <li><a href="http://rubyforge.org/frs/?group_id=2103">Releases</a></li>
36
+ <li><a href="http://rubyforge.org/scm/?group_id=2103">SVN</a></li>
31
37
  </ul>
32
-
33
38
  <h3>Other docs</h3>
34
39
  <ul>
40
+ <li><a href="./extensions.html">Extension support</a></li>
35
41
  <li><a href="./thanks.html">Thanks</a></li>
36
42
  <li><a href="./scientific_use.html">Scientific use</a></li>
37
43
  </ul>
@@ -43,7 +49,7 @@
43
49
  <li><a href="http://freeglut.sourceforge.net/">freeglut</a></li>
44
50
  <li><a href="http://rubyforge.org/projects/ruby-ftgl/">ruby-ftgl</a></li>
45
51
  <li><a href="http://www.rubygarden.org/ruby?OpenGL">Ruby wiki GL page</a></li>
46
- <li><a href="http://rubygame.seul.org/">RubyGame</a></li>
52
+ <li><a href="http://rubygame.sourceforge.net">RubyGame</a></li>
47
53
  </ul>
48
54
  </div>
49
55
 
data/doc/thanks.txt CHANGED
@@ -1,8 +1,7 @@
1
1
  Thank you
2
2
  ---------
3
3
 
4
- Aside from big thank-you's to the core devs, special thanks (alphabetical
5
- by first name) also goes to:
4
+ Aside from big thank-you's to the core devs, special thanks also goes to:
6
5
 
7
6
  * Bill Kelly -- provided some pilot code changing how users can call method and constant names.
8
7
  * Ilmari Heikkinen -- provided code for changing how users can call method and constant names.
@@ -10,10 +9,9 @@ by first name) also goes to:
10
9
  * Tony Hursh -- Mac OS X glut build tweak
11
10
  * Sean Long -- More Mac OS X fixes
12
11
  * John Gabriele -- Numerous fixes, documentation, and project support
13
- * Jan Dvorak -- Patches to start OpenGL 2.1 support
12
+ * Ronald Pijnacker -- Windows support and bugfixes
14
13
  * **Yoshi** -- providing ruby-opengl-0.32g from which to work off of.
15
14
 
16
-
17
15
  <br/>
18
16
  <br/>
19
17
  <br/>
data/doc/tutorial.txt CHANGED
@@ -106,10 +106,7 @@ extra directories added.
106
106
 
107
107
  * `doc/` -- Contains documentation for the project (from which this
108
108
  website is generated).
109
- * `examples` -- Some small sample programs. Mostly, these are being
110
- copied from Yoshi's examples while being updated and neatened up.
111
- * `experimental` -- Pure Ruby modules that are intended to make ruby-opengl
112
- usage more "Rubyish". These may eventually become part of ruby-opengl proper.
109
+ * `examples/` -- Example programs.
113
110
  * `ext/` -- Contains subdirectories, one for each of the three extension
114
111
  modules (gl, glu, glut). Herein are the files needed to compile the extension
115
112
  modules.
@@ -0,0 +1,303 @@
1
+ # Nehe Lesson 36 Code
2
+ # modified from immediate mode to use vertex arrays for helix drawing
3
+ require 'opengl'
4
+ include Gl,Glu,Glut
5
+ include Math
6
+
7
+ def emptyTexture
8
+ # Create Storage Space For Texture Data (128x128x4)
9
+ data = ([0]*4*128*128).pack("f*")
10
+ txtnumber = glGenTextures(1) # Create 1 Texture
11
+ glBindTexture(GL_TEXTURE_2D, txtnumber[0]) # Bind The Texture
12
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, 128, 128, 0,
13
+ GL_RGBA, GL_FLOAT, data) # Build Texture Using Information In data
14
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
15
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
16
+ return txtnumber[0] # Return The Texture ID
17
+ end
18
+
19
+ def init
20
+ global_ambient = [0.2, 0.2, 0.2, 1.0] # Set Ambient Lighting To Fairly Dark Light (No Color)
21
+ light0pos = [0.0, 5.0, 10.0, 1.0] # Set The Light Position
22
+ light0ambient = [0.2, 0.2, 0.2, 1.0] # More Ambient Light
23
+ light0diffuse = [0.3, 0.3, 0.3, 1.0] # Set The Diffuse Light A Bit Brighter
24
+ light0specular = [0.8, 0.8, 0.8, 1.0] # Fairly Bright Specular Lighting
25
+
26
+ lmodel_ambient = [0.2,0.2,0.2,1.0] # And More Ambient Light
27
+
28
+ $angle = 0.0 # Set Starting Angle To Zero
29
+
30
+ $lasttime = 0
31
+
32
+ $blurTexture = emptyTexture() # Create Our Empty Texture
33
+
34
+ $helix_v,$helix_n = createHelix()
35
+ glVertexPointer(3,GL_FLOAT,0,$helix_v.flatten.pack("f*"))
36
+ glNormalPointer(GL_FLOAT,0,$helix_n.flatten.pack("f*"))
37
+
38
+ glLoadIdentity() # Reset The Modelview Matrix
39
+
40
+ glEnable(GL_DEPTH_TEST) # Enable Depth Testing
41
+
42
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient) # Set The Ambient Light Model
43
+
44
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT,global_ambient) # Set The Global Ambient Light Model
45
+ glLightfv(GL_LIGHT0, GL_POSITION, light0pos) # Set The Lights Position
46
+ glLightfv(GL_LIGHT0, GL_AMBIENT, light0ambient) # Set The Ambient Light
47
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, light0diffuse) # Set The Diffuse Light
48
+ glLightfv(GL_LIGHT0, GL_SPECULAR, light0specular) # Set Up Specular Lighting
49
+ glEnable(GL_LIGHTING) # Enable Lighting
50
+ glEnable(GL_LIGHT0) # Enable Light0
51
+
52
+ glShadeModel(GL_SMOOTH) # Select Smooth Shading
53
+
54
+ glMateriali(GL_FRONT, GL_SHININESS, 128)
55
+ glClearColor(0.0, 0.0, 0.0, 0.5) # Set The Clear Color To Black
56
+ end
57
+
58
+ # Keyboard handler to exit when ESC is typed
59
+ keyboard = lambda do |key, x, y|
60
+ case(key)
61
+ when 27
62
+ exit(0)
63
+ end
64
+ glutPostRedisplay
65
+ end
66
+
67
+ reshape = lambda do |w,h|
68
+ glMatrixMode(GL_PROJECTION)
69
+ glViewport(0,0,w,h)
70
+ glLoadIdentity()
71
+ width = 0.5
72
+ height = 0.5 * h/w;
73
+ glFrustum(-width,width,-height,height,1.0,2000.0)
74
+ glMatrixMode(GL_MODELVIEW)
75
+ glViewport(0,0,w,h)
76
+ end
77
+
78
+ def viewOrtho
79
+ glMatrixMode(GL_PROJECTION) # Select Projection
80
+ glPushMatrix() # Push The Matrix
81
+ glLoadIdentity() # Reset The Matrix
82
+ width = glutGet(GLUT_WINDOW_WIDTH)
83
+ height = glutGet(GLUT_WINDOW_HEIGHT)
84
+ glOrtho( 0, width , height , 0, -1, 1 ) # Select Ortho Mode (widthxheight)
85
+ glMatrixMode(GL_MODELVIEW) # Select Modelview Matrix
86
+ glPushMatrix() # Push The Matrix
87
+ glLoadIdentity() # Reset The Matrix
88
+ end
89
+
90
+ def viewPerspective # Set Up A Perspective View
91
+ glMatrixMode( GL_PROJECTION ) # Select Projection
92
+ glPopMatrix() # Pop The Matrix
93
+ glMatrixMode( GL_MODELVIEW ) # Select Modelview
94
+ glPopMatrix() # Pop The Matrix
95
+ end
96
+
97
+ def normalize(v)
98
+ len = sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2])
99
+ return v if len==0
100
+ [ v[0] / len, v[1] / len, v[2] / len ]
101
+ end
102
+
103
+ def calcNormal(v) # Calculates Normal For A Quad Using 3 Points
104
+ # Finds The Vector Between 2 Points By Subtracting
105
+ # The x,y,z Coordinates From One Point To Another.
106
+ # Calculate The Vector From Point 1 To Point 0
107
+ v1, v2, out = [], [], []
108
+ x,y,z = 0,1,2
109
+
110
+ v1[x] = v[0][x] - v[1][x] # Vector 1.x=Vertex[0].x-Vertex[1].x
111
+ v1[y] = v[0][y] - v[1][y] # Vector 1.y=Vertex[0].y-Vertex[1].y
112
+ v1[z] = v[0][z] - v[1][z] # Vector 1.z=Vertex[0].y-Vertex[1].z
113
+ # Calculate The Vector From Point 2 To Point 1
114
+ v2[x] = v[1][x] - v[2][x] # Vector 2.x=Vertex[0].x-Vertex[1].x
115
+ v2[y] = v[1][y] - v[2][y] # Vector 2.y=Vertex[0].y-Vertex[1].y
116
+ v2[z] = v[1][z] - v[2][z] # Vector 2.z=Vertex[0].z-Vertex[1].z
117
+ # Compute The Cross Product To Give Us A Surface Normal
118
+ out[x] = v1[y]*v2[z] - v1[z]*v2[y] # Cross Product For Y - Z
119
+ out[y] = v1[z]*v2[x] - v1[x]*v2[z] # Cross Product For X - Z
120
+ out[z] = v1[x]*v2[y] - v1[y]*v2[x] # Cross Product For X - Y
121
+
122
+ normalize(out)
123
+ end
124
+
125
+ def createHelix() # creates helix VA
126
+ twists = 5
127
+ r = 1.5
128
+
129
+ helix_v = []
130
+ helix_n = []
131
+
132
+ 0.step(360,20) do |phi| # 360 Degrees In Steps Of 20
133
+ 0.step(360*twists,20) do |theta| # 360 Degrees * Number Of Twists In Steps Of 20
134
+ v= phi/180.0*PI # Calculate Angle Of First Point ( 0 )
135
+ u= theta/180.0*PI # Calculate Angle Of First Point ( 0 )
136
+
137
+ x= cos(u)*(2.0+cos(v))*r # Calculate x Position (1st Point)
138
+ y= sin(u)*(2.0+cos(v))*r # Calculate y Position (1st Point)
139
+ z=((u-(2.0*PI)) + sin(v))*r # Calculate z Position (1st Point)
140
+
141
+ v0 = [x,y,z]
142
+
143
+ v= phi/180.0*PI # Calculate Angle Of Second Point ( 0 )
144
+ u= (theta+20)/180.0*PI # Calculate Angle Of Second Point ( 20 )
145
+
146
+ x= cos(u)*(2.0+cos(v))*r # Calculate x Position (2nd Point)
147
+ y= sin(u)*(2.0+cos(v))*r # Calculate y Position (2nd Point)
148
+ z= ((u-(2.0*PI)) + sin(v))*r # Calculate z Position (2nd Point)
149
+
150
+ v1 = [x,y,z]
151
+
152
+ v= (phi+20)/180.0*PI # Calculate Angle Of Third Point ( 20 )
153
+ u= (theta+20)/180.0*PI # Calculate Angle Of Third Point ( 20 )
154
+
155
+ x= cos(u)*(2.0+cos(v))*r # Calculate x Position (3rd Point)
156
+ y= sin(u)*(2.0+cos(v))*r # Calculate y Position (3rd Point)
157
+ z= ((u-(2.0*PI)) + sin(v))*r # Calculate z Position (3rd Point)
158
+
159
+ v2 = [x,y,z]
160
+
161
+ v= (phi+20)/180.0*PI # Calculate Angle Of Fourth Point ( 20 )
162
+ u= (theta)/180.0*PI # Calculate Angle Of Fourth Point ( 0 )
163
+
164
+ x= cos(u)*(2.0+cos(v))*r # Calculate x Position (4th Point)
165
+ y= sin(u)*(2.0+cos(v))*r # Calculate y Position (4th Point)
166
+ z= ((u-(2.0*PI)) + sin(v))*r # Calculate z Position (4th Point)
167
+
168
+ v3 = [x,y,z]
169
+
170
+ normal = calcNormal([v0,v1,v2,v3]) # Calculate The Quad Normal
171
+ helix_v << v0 << v1 << v2 << v3
172
+ helix_n << normal << normal << normal << normal
173
+ end
174
+ end
175
+ [helix_v,helix_n]
176
+ end
177
+
178
+ def processHelix() # Draws A Helix
179
+ glfMaterialColor = [0.4,0.2,0.8,1.0] # Set The Material Color
180
+ specular = [1.0,1.0,1.0,1.0] # Sets Up Specular Lighting
181
+
182
+ glLoadIdentity() # Reset The Modelview Matrix
183
+ gluLookAt(0, 5, 50, 0, 0, 0, 0, 1, 0) # Eye Position (0,5,50) Center Of Scene (0,0,0), Up On Y Axis
184
+
185
+ glPushMatrix() # Push The Modelview Matrix
186
+
187
+ glTranslatef(0,0,-50) # Translate 50 Units Into The Screen
188
+ glRotatef($angle/2.0,1,0,0) # Rotate By angle/2 On The X-Axis
189
+ glRotatef($angle/3.0,0,1,0) # Rotate By angle/3 On The Y-Axis
190
+
191
+ glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,glfMaterialColor)
192
+ glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,specular)
193
+
194
+ glEnableClientState(GL_VERTEX_ARRAY)
195
+ glEnableClientState(GL_NORMAL_ARRAY)
196
+ glDrawArrays(GL_QUADS,0,$helix_v.size)
197
+ glDisableClientState(GL_VERTEX_ARRAY)
198
+ glDisableClientState(GL_NORMAL_ARRAY)
199
+
200
+ glPopMatrix() # Pop The Matrix
201
+ end
202
+
203
+ def drawBlur(times,inc)
204
+ spost = 0.0 # Starting Texture Coordinate Offset
205
+ alphainc = 0.9 / times # Fade Speed For Alpha Blending
206
+ alpha = 0.2 # Starting Alpha Value
207
+
208
+ width = glutGet(GLUT_WINDOW_WIDTH)
209
+ height = glutGet(GLUT_WINDOW_HEIGHT)
210
+ # Disable AutoTexture Coordinates
211
+ glDisable(GL_TEXTURE_GEN_S)
212
+ glDisable(GL_TEXTURE_GEN_T)
213
+
214
+ glEnable(GL_TEXTURE_2D) # Enable 2D Texture Mapping
215
+ glDisable(GL_DEPTH_TEST) # Disable Depth Testing
216
+ glBlendFunc(GL_SRC_ALPHA,GL_ONE) # Set Blending Mode
217
+ glEnable(GL_BLEND) # Enable Blending
218
+ glBindTexture(GL_TEXTURE_2D,$blurTexture) # Bind To The Blur Texture
219
+ viewOrtho() # Switch To An Ortho View
220
+
221
+ alphainc = alpha / times # alphainc=0.2 / Times To Render Blur
222
+
223
+ glBegin(GL_QUADS) # Begin Drawing Quads
224
+ 0.upto(times-1) do |num| # Number Of Times To Render Blur
225
+ glColor4f(1.0, 1.0, 1.0, alpha) # Set The Alpha Value (Starts At 0.2)
226
+ glTexCoord2f(0+spost,1-spost) # Texture Coordinate ( 0, 1 )
227
+ glVertex2f(0,0) # First Vertex ( 0, 0 )
228
+
229
+ glTexCoord2f(0+spost,0+spost) # Texture Coordinate ( 0, 0 )
230
+ glVertex2f(0,height) # Second Vertex ( 0, height )
231
+
232
+ glTexCoord2f(1-spost,0+spost) # Texture Coordinate ( 1, 0 )
233
+ glVertex2f(width,height) # Third Vertex ( width, height )
234
+
235
+ glTexCoord2f(1-spost,1-spost) # Texture Coordinate ( 1, 1 )
236
+ glVertex2f(width,0) # Fourth Vertex ( width, 0 )
237
+
238
+ spost += inc # Gradually Increase spost (Zooming Closer To Texture Center)
239
+ alpha = alpha - alphainc # Gradually Decrease alpha (Gradually Fading Image Out)
240
+ end
241
+ glEnd() # Done Drawing Quads
242
+
243
+ viewPerspective() # Switch To A Perspective View
244
+
245
+ glEnable(GL_DEPTH_TEST) # Enable Depth Testing
246
+ glDisable(GL_TEXTURE_2D) # Disable 2D Texture Mapping
247
+ glDisable(GL_BLEND) # Disable Blending
248
+ glBindTexture(GL_TEXTURE_2D,0) # Unbind The Blur Texture
249
+ end
250
+
251
+
252
+ def renderToTexture
253
+ glViewport(0,0,128,128); # Set Our Viewport (Match Texture Size)
254
+
255
+ processHelix() # Render The Helix
256
+
257
+ glBindTexture(GL_TEXTURE_2D,$blurTexture) # Bind To The Blur Texture
258
+
259
+ # Copy Our ViewPort To The Blur Texture (From 0,0 To 128,128... No Border)
260
+ glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 0, 0, 128, 128, 0)
261
+
262
+ glClearColor(0.0, 0.0, 0.5, 0.5) # Set The Clear Color To Medium Blue
263
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Clear The Screen And Depth Buffer
264
+ width = glutGet(GLUT_WINDOW_WIDTH)
265
+ height = glutGet(GLUT_WINDOW_HEIGHT)
266
+ glViewport(0 , 0,width,height) # Set Viewport (0,0 to widthxheight)
267
+ end
268
+
269
+ drawGLScene = lambda do # Draw The Scene
270
+ glClearColor(0.0, 0.0, 0.0, 0.5) # Set The Clear Color To Black
271
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Clear Screen And Depth Buffer
272
+ glLoadIdentity() # Reset The View
273
+ renderToTexture() # Render To A Texture
274
+ processHelix() # Draw Our Helix
275
+ drawBlur(25,0.02) # Draw The Blur Effect
276
+ glFlush() # Flush The GL Rendering Pipeline
277
+ glutSwapBuffers()
278
+ sleep(0.001) # don't hog all cpu time
279
+ end
280
+
281
+ idle = lambda do
282
+ now = glutGet(GLUT_ELAPSED_TIME)
283
+ elapsed = now - $lasttime
284
+ $angle += (elapsed * 0.03) # Update angle Based On The Clock
285
+ $lasttime = now
286
+
287
+ glutPostRedisplay()
288
+ end
289
+
290
+ # Main
291
+ glutInit()
292
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH)
293
+ glutInitWindowPosition(100,100)
294
+ glutInitWindowSize(640,480)
295
+ glutCreateWindow("NeHe's Lesson 36")
296
+ glutDisplayFunc(drawGLScene)
297
+ glutIdleFunc(idle)
298
+ glutReshapeFunc(reshape)
299
+ glutKeyboardFunc(keyboard)
300
+
301
+ init()
302
+
303
+ glutMainLoop()