ruby-opengl 0.40.1 → 0.50.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.
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
@@ -10,7 +10,7 @@
10
10
  # written prior permission.
11
11
  #
12
12
  # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
13
- #AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
13
+ # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
14
14
  # INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
15
15
  # FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
16
16
  # GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
@@ -33,72 +33,73 @@
33
33
  # Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
34
34
  #
35
35
  # OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
36
- #/
37
-
38
36
  #
39
- # double.c
40
- # This is a simple double buffered program.
41
- # Pressing the left mouse button rotates the rectangle.
42
- # Pressing the middle mouse button stops the rotation.
43
- #/
44
- require "gl_prev"
45
- require "glu_prev"
46
- require "glut_prev"
47
- require "rational"
48
-
49
- $spin = 0.0;
37
+ # double.c
38
+ # This is a simple double buffered program.
39
+ # Pressing the left mouse button rotates the rectangle.
40
+ # Pressing the middle mouse button stops the rotation.
41
+ require 'opengl'
42
+ require 'rational'
43
+ include Gl,Glu,Glut
50
44
 
51
- display = Proc.new {
52
- GL.Clear(GL::COLOR_BUFFER_BIT);
53
- GL.PushMatrix();
54
- GL.Rotate($spin, 0.0, 0.0, 1.0);
55
- GL.Color(1.0, 1.0, 1.0);
56
- GL.Rect(-25.0, -25.0, 25.0, 25.0);
57
- GL.PopMatrix();
45
+ $spin = 0.0
58
46
 
59
- GLUT.SwapBuffers();
60
- }
47
+ display = Proc.new do
48
+ glClear(GL_COLOR_BUFFER_BIT)
49
+ glPushMatrix()
50
+ glRotate($spin, 0.0, 0.0, 1.0)
51
+ glColor(1.0, 1.0, 1.0)
52
+ glRect(-25.0, -25.0, 25.0, 25.0)
53
+ glPopMatrix()
54
+ glutSwapBuffers()
55
+ end
61
56
 
62
- $spinDisplay = Proc.new {
63
- $spin = $spin + 4.0;
64
- $spin = $spin - 360.0 if ($spin > 360.0)
65
- GLUT.PostRedisplay();
66
- }
57
+ $spinDisplay = Proc.new do
58
+ $spin = $spin + 4.0
59
+ $spin = $spin - 360.0 if ($spin > 360.0)
60
+ glutPostRedisplay()
61
+ end
67
62
 
68
63
  def init
69
- GL.ClearColor(0.0, 0.0, 0.0, 0.0);
70
- GL.ShadeModel(GL::FLAT);
64
+ glClearColor(0.0, 0.0, 0.0, 0.0)
65
+ glShadeModel(GL_FLAT)
71
66
  end
72
67
 
73
- reshape = Proc.new {|w, h|
74
- GL.Viewport(0, 0, w, h);
75
- GL.MatrixMode(GL::PROJECTION);
76
- GL.LoadIdentity();
77
- GL.Ortho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
78
- GL.MatrixMode(GL::MODELVIEW);
79
- GL.LoadIdentity();
80
- }
68
+ reshape = Proc.new do |w, h|
69
+ glViewport(0, 0, w, h)
70
+ glMatrixMode(GL_PROJECTION)
71
+ glLoadIdentity()
72
+ glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0)
73
+ glMatrixMode(GL_MODELVIEW)
74
+ glLoadIdentity()
75
+ end
81
76
 
82
- mouse = Proc.new {|button, state, x, y|
83
- case button
84
- when GLUT::LEFT_BUTTON
85
- GLUT.IdleFunc($spinDisplay) if (state == GLUT::DOWN)
86
- when GLUT::MIDDLE_BUTTON
87
- GLUT.IdleFunc(nil) if (state == GLUT::DOWN)
88
- end
89
- }
77
+ mouse = Proc.new do |button, state, x, y|
78
+ case button
79
+ when GLUT_LEFT_BUTTON
80
+ glutIdleFunc($spinDisplay) if (state == GLUT_DOWN)
81
+ when GLUT_MIDDLE_BUTTON
82
+ glutIdleFunc(nil) if (state == GLUT_DOWN)
83
+ end
84
+ end
85
+
86
+ keyboard = Proc.new do |key, x, y|
87
+ case (key)
88
+ when 27
89
+ exit(0)
90
+ end
91
+ end
90
92
 
91
- #
92
93
  # Request double buffer display mode.
93
94
  # Register mouse input callback functions
94
- #/
95
- GLUT.Init
96
- GLUT.InitDisplayMode(GLUT::DOUBLE | GLUT::RGB);
97
- GLUT.InitWindowSize(250, 250);
98
- GLUT.InitWindowPosition(100, 100);
99
- GLUT.CreateWindow($0);
100
- init();
101
- GLUT.DisplayFunc(display);
102
- GLUT.ReshapeFunc(reshape);
103
- GLUT.MouseFunc(mouse);
104
- GLUT.MainLoop();
95
+ glutInit
96
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
97
+ glutInitWindowSize(500, 500)
98
+ glutInitWindowPosition(100, 100)
99
+ glutCreateWindow($0)
100
+ init()
101
+ glutDisplayFunc(display)
102
+ glutReshapeFunc(reshape)
103
+ glutKeyboardFunc(keyboard)
104
+ glutMouseFunc(mouse)
105
+ glutMainLoop()
@@ -33,66 +33,59 @@
33
33
  # Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
34
34
  #
35
35
  # OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
36
- #/
37
-
38
- #*
39
- #* drawf.c
40
- #* Draws the bitmapped letter F on the screen (several times).
41
- #* This demonstrates use of the glBitmap() call.
42
- #*/
43
-
44
- require "gl_prev"
45
- require "glu_prev"
46
- require "glut_prev"
47
-
36
+ #
37
+ # drawf.c
38
+ # Draws the bitmapped letter F on the screen (several times).
39
+ # This demonstrates use of the glBitmap() call.
40
+ require 'opengl'
41
+ include Gl,Glu,Glut
48
42
 
49
43
  $rasters = [
50
- 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
51
- 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
52
- 0xff, 0xc0, 0xff, 0xc0].pack("C*");
44
+ 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
45
+ 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
46
+ 0xff, 0xc0, 0xff, 0xc0
47
+ ].pack("C*")
53
48
 
54
49
  def init
55
- GL.PixelStorei(GL::UNPACK_ALIGNMENT, 1);
56
- GL.ClearColor(0.0, 0.0, 0.0, 0.0);
50
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
51
+ glClearColor(0.0, 0.0, 0.0, 0.0)
57
52
  end
58
53
 
59
- display = Proc.new {
60
- GL.Clear(GL::COLOR_BUFFER_BIT);
61
- GL.Color(1.0, 1.0, 1.0);
62
- GL.RasterPos2i(20, 20);
63
- GL.Bitmap(10, 12, 0.0, 0.0, 11.0, 0.0, $rasters);
64
- GL.Bitmap(10, 12, 0.0, 0.0, 11.0, 0.0, $rasters);
65
- GL.Bitmap(10, 12, 0.0, 0.0, 11.0, 0.0, $rasters);
66
- GL.Flush();
67
- }
54
+ display = Proc.new do
55
+ glClear(GL_COLOR_BUFFER_BIT)
56
+ glColor(1.0, 1.0, 1.0)
57
+ glRasterPos2i(20, 20)
58
+ glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, $rasters)
59
+ glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, $rasters)
60
+ glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, $rasters)
61
+ glutSwapBuffers()
62
+ end
68
63
 
69
- reshape = Proc.new {|w, h|
70
- GL.Viewport(0, 0, w, h);
71
- GL.MatrixMode(GL::PROJECTION);
72
- GL.LoadIdentity();
73
- GL.Ortho(0, w, 0, h, -1.0, 1.0);
74
- GL.MatrixMode(GL::MODELVIEW);
75
- }
64
+ reshape = Proc.new do |w, h|
65
+ glViewport(0, 0, w, h)
66
+ glMatrixMode(GL_PROJECTION)
67
+ glLoadIdentity()
68
+ glOrtho(0, w, 0, h, -1.0, 1.0)
69
+ glMatrixMode(GL_MODELVIEW)
70
+ end
76
71
 
77
- #* ARGSUSED1 */
78
- keyboard = Proc.new {|key, x, y|
79
- case (key)
80
- when 27
81
- exit(0);
82
- end
83
- }
72
+ keyboard = Proc.new do |key, x, y|
73
+ case (key)
74
+ when 27
75
+ exit(0)
76
+ end
77
+ end
84
78
 
85
- #* Main Loop
86
- #* Open window with initial window size, title bar,
87
- #* RGBA display mode, and handle input events.
88
- #*/
89
- GLUT.Init
90
- GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB);
91
- GLUT.InitWindowSize(100, 100);
92
- GLUT.InitWindowPosition(100, 100);
93
- GLUT.CreateWindow($0);
94
- init();
95
- GLUT.ReshapeFunc(reshape);
96
- GLUT.KeyboardFunc(keyboard);
97
- GLUT.DisplayFunc(display);
98
- GLUT.MainLoop();
79
+ # Main Loop
80
+ # Open window with initial window size, title bar,
81
+ # RGBA display mode, and handle input events.
82
+ glutInit
83
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
84
+ glutInitWindowSize(100, 100)
85
+ glutInitWindowPosition(100, 100)
86
+ glutCreateWindow($0)
87
+ init()
88
+ glutReshapeFunc(reshape)
89
+ glutKeyboardFunc(keyboard)
90
+ glutDisplayFunc(display)
91
+ glutMainLoop()
@@ -0,0 +1,145 @@
1
+ #
2
+ # Copyright (c) 1993-1997, Silicon Graphics, Inc.
3
+ # ALL RIGHTS RESERVED
4
+ # Permission to use, copy, modify, and distribute this software for
5
+ # any purpose and without fee is hereby granted, provided that the above
6
+ # copyright notice appear in all copies and that both the copyright notice
7
+ # and this permission notice appear in supporting documentation, and that
8
+ # the name of Silicon Graphics, Inc. not be used in advertising
9
+ # or publicity pertaining to distribution of the software without specific,
10
+ # written prior permission.
11
+ #
12
+ # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
13
+ # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
14
+ # INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
15
+ # FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
16
+ # GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
17
+ # SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
18
+ # KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
19
+ # LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
20
+ # THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
21
+ # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
22
+ # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
23
+ # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
24
+ #
25
+ # US Government Users Restricted Rights
26
+ # Use, duplication, or disclosure by the Government is subject to
27
+ # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
28
+ # (c)(1)(ii) of the Rights in Technical Data and Computer Software
29
+ # clause at DFARS 252.227-7013 and/or in similar or successor
30
+ # clauses in the FAR or the DOD or NASA FAR Supplement.
31
+ # Unpublished-- rights reserved under the copyright laws of the
32
+ # United States. Contractor/manufacturer is Silicon Graphics,
33
+ # Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
34
+ #
35
+ # OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
36
+ #
37
+ # feedback.c
38
+ # This program demonstrates use of OpenGL feedback. First,
39
+ # a lighting environment is set up and a few lines are drawn.
40
+ # Then feedback mode is entered, and the same lines are
41
+ # drawn. The results in the feedback buffer are printed.
42
+ require 'opengl'
43
+ include Gl,Glu,Glut
44
+
45
+ # Initialize lighting.
46
+ def init
47
+ glEnable(GL_LIGHTING)
48
+ glEnable(GL_LIGHT0)
49
+ end
50
+
51
+ # Draw a few lines and two points, one of which will
52
+ # be clipped. If in feedback mode, a passthrough token
53
+ # is issued between the each primitive.
54
+ def drawGeometry(mode)
55
+ glBegin(GL_LINE_STRIP)
56
+ glNormal(0.0, 0.0, 1.0)
57
+ glVertex(30.0, 30.0, 0.0)
58
+ glVertex(50.0, 60.0, 0.0)
59
+ glVertex(70.0, 40.0, 0.0)
60
+ glEnd()
61
+ if (mode == GL_FEEDBACK)
62
+ glPassThrough(1.0)
63
+ end
64
+ glBegin(GL_POINTS)
65
+ glVertex(-100.0, -100.0, -100.0) # will be clipped
66
+ glEnd()
67
+ if (mode == GL_FEEDBACK)
68
+ glPassThrough(2.0)
69
+ end
70
+ glBegin(GL_POINTS)
71
+ glNormal(0.0, 0.0, 1.0)
72
+ glVertex(50.0, 50.0, 0.0)
73
+ glEnd()
74
+ end
75
+
76
+ # Write contents of one vertex to stdout.
77
+ def print3DcolorVertex(size, count, buffer)
78
+ printf(" ")
79
+ for i in 0...7
80
+ printf("%4.2f ", buffer[size-count])
81
+ count -= 1
82
+ end
83
+ printf("\n")
84
+ return count
85
+ end
86
+
87
+ # Write contents of entire buffer. (Parse tokens!)
88
+ def printBuffer(size, buffer)
89
+ count = size
90
+ while (count!=0)
91
+ token = buffer[size-count]
92
+ count-=1
93
+ if (token == GL_PASS_THROUGH_TOKEN)
94
+ printf("GL_PASS_THROUGH_TOKEN\n")
95
+ printf(" %4.2f\n", buffer[size-count])
96
+ count-=1
97
+ elsif (token == GL_POINT_TOKEN)
98
+ printf("GL_POINT_TOKEN\n")
99
+ count = print3DcolorVertex(size, count, buffer)
100
+ elsif (token == GL_LINE_TOKEN)
101
+ printf("GL_LINE_TOKEN\n")
102
+ count = print3DcolorVertex(size, count, buffer)
103
+ count = print3DcolorVertex(size, count, buffer)
104
+ elsif (token == GL_LINE_RESET_TOKEN)
105
+ printf("GL_LINE_RESET_TOKEN\n")
106
+ count = print3DcolorVertex(size, count, buffer)
107
+ count = print3DcolorVertex(size, count, buffer)
108
+ end
109
+ end
110
+ end
111
+
112
+ display = proc do
113
+ glMatrixMode(GL_PROJECTION)
114
+ glLoadIdentity()
115
+ glOrtho(0.0, 100.0, 0.0, 100.0, 0.0, 1.0)
116
+
117
+ glClearColor(0.0, 0.0, 0.0, 0.0)
118
+ glClear(GL_COLOR_BUFFER_BIT)
119
+ drawGeometry(GL_RENDER)
120
+
121
+ feedBuffer = glFeedbackBuffer(1024, GL_3D_COLOR)
122
+ glRenderMode(GL_FEEDBACK)
123
+ drawGeometry(GL_FEEDBACK)
124
+
125
+ size = glRenderMode(GL_RENDER)
126
+ printBuffer(size, feedBuffer.unpack("f#{size}"))
127
+ glutSwapBuffers()
128
+ end
129
+
130
+ keyboard = proc do |key, x, y|
131
+ case (key)
132
+ when 27
133
+ exit(0)
134
+ end
135
+ end
136
+
137
+ glutInit()
138
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
139
+ glutInitWindowSize(100, 100)
140
+ glutInitWindowPosition(100, 100)
141
+ glutCreateWindow()
142
+ init()
143
+ glutDisplayFunc(display)
144
+ glutKeyboardFunc(keyboard)
145
+ glutMainLoop()
@@ -0,0 +1,167 @@
1
+ #
2
+ # Copyright (c) Mark J. Kilgard, 1994.
3
+ #
4
+ # (c) Copyright 1993, Silicon Graphics, Inc.
5
+ # ALL RIGHTS RESERVED
6
+ # Permission to use, copy, modify, and distribute this software for
7
+ # any purpose and without fee is hereby granted, provided that the above
8
+ # copyright notice appear in all copies and that both the copyright notice
9
+ # and this permission notice appear in supporting documentation, and that
10
+ # the name of Silicon Graphics, Inc. not be used in advertising
11
+ # or publicity pertaining to distribution of the software without specific,
12
+ # written prior permission.
13
+ #
14
+ # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
15
+ # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
16
+ # INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
17
+ # FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
18
+ # GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
19
+ # SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
20
+ # KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
21
+ # LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
22
+ # THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
23
+ # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
24
+ # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
25
+ # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
26
+ #
27
+ # US Government Users Restricted Rights
28
+ # Use, duplication, or disclosure by the Government is subject to
29
+ # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
30
+ # (c)(1)(ii) of the Rights in Technical Data and Computer Software
31
+ # clause at DFARS 252.227-7013 and/or in similar or successor
32
+ # clauses in the FAR or the DOD or NASA FAR Supplement.
33
+ # Unpublished-- rights reserved under the copyright laws of the
34
+ # United States. Contractor/manufacturer is Silicon Graphics,
35
+ # Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
36
+ #
37
+ # OpenGL(TM) is a trademark of Silicon Graphics, Inc.
38
+ #
39
+ # fog.c
40
+ # This program draws 5 red teapots, each at a different
41
+ # z distance from the eye, in different types of fog.
42
+ # Pressing the left mouse button chooses between 3 types of
43
+ # fog: exponential, exponential squared, and linear.
44
+ # In this program, there is a fixed density value, as well
45
+ # as fixed start and end values for the linear fog.
46
+ require 'opengl'
47
+ require 'mathn'
48
+ include Gl,Glu,Glut
49
+
50
+ $fogMode = 0
51
+
52
+ selectFog = Proc.new do |mode|
53
+ if (mode == GL_LINEAR)
54
+ glFog(GL_FOG_START, 1.0)
55
+ glFog(GL_FOG_END, 5.0)
56
+ # falls through
57
+ glFog(GL_FOG_MODE, mode)
58
+ glutPostRedisplay()
59
+ end
60
+ if (mode == GL_EXP2 || mode == GL_EXP)
61
+ glFog(GL_FOG_MODE, mode)
62
+ glutPostRedisplay()
63
+ end
64
+ exit(0) if (mode == 0)
65
+ end
66
+
67
+ # Initialize z-buffer, projection matrix, light source,
68
+ # and lighting model. Do not specify a material property here.
69
+ def myinit
70
+ position = [0.0, 3.0, 3.0, 0.0]
71
+ local_view = [0.0]
72
+
73
+ glEnable(GL_DEPTH_TEST)
74
+ glDepthFunc(GL_LESS)
75
+
76
+ glLight(GL_LIGHT0, GL_POSITION, position)
77
+ glLightModel(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view)
78
+
79
+ glFrontFace(GL_CW)
80
+ glEnable(GL_LIGHTING)
81
+ glEnable(GL_LIGHT0)
82
+ glEnable(GL_AUTO_NORMAL)
83
+ glEnable(GL_NORMALIZE)
84
+ glEnable(GL_FOG)
85
+ fogColor = [0.5, 0.5, 0.5, 1.0]
86
+
87
+ fogMode = GL_EXP
88
+ glFog(GL_FOG_MODE, fogMode)
89
+ glFog(GL_FOG_COLOR, fogColor)
90
+ glFog(GL_FOG_DENSITY, 0.35)
91
+ glHint(GL_FOG_HINT, GL_DONT_CARE)
92
+ glClearColor(0.5, 0.5, 0.5, 1.0)
93
+ end
94
+
95
+ def renderRedTeapot(x, y, z)
96
+ mat = []
97
+ glPushMatrix()
98
+ glTranslate(x, y, z)
99
+ mat[0] = 0.1745
100
+ mat[1] = 0.01175
101
+ mat[2] = 0.01175
102
+ mat[3] = 1.0
103
+ glMaterial(GL_FRONT, GL_AMBIENT, mat)
104
+ mat[0] = 0.61424
105
+ mat[1] = 0.04136
106
+ mat[2] = 0.04136
107
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat)
108
+ mat[0] = 0.727811
109
+ mat[1] = 0.626959
110
+ mat[2] = 0.626959
111
+ glMaterial(GL_FRONT, GL_SPECULAR, mat)
112
+ glMaterial(GL_FRONT, GL_SHININESS, 0.6 * 128.0)
113
+ glutSolidTeapot(1.0)
114
+ glPopMatrix()
115
+ end
116
+
117
+ # display() draws 5 teapots at different z positions.
118
+ display = Proc.new do
119
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
120
+ renderRedTeapot(-4.0, -0.5, -1.0)
121
+ renderRedTeapot(-2.0, -0.5, -2.0)
122
+ renderRedTeapot(0.0, -0.5, -3.0)
123
+ renderRedTeapot(2.0, -0.5, -4.0)
124
+ renderRedTeapot(4.0, -0.5, -5.0)
125
+ glFlush()
126
+ end
127
+
128
+ myReshape = Proc.new do |w, h|
129
+ glViewport(0, 0, w, h)
130
+ glMatrixMode(GL_PROJECTION)
131
+ glLoadIdentity()
132
+ if (w <= (h * 3))
133
+ glOrtho(-6.0, 6.0, -2.0 * h * 3 / w, 2.0 * h * 3 / w, 0.0, 10.0)
134
+ elsif
135
+ glOrtho(-6.0 * w / h * 3, 6.0 * w / h * 3, -2.0, 2.0, 0.0, 10.0)
136
+ end
137
+ glMatrixMode(GL_MODELVIEW)
138
+ glLoadIdentity()
139
+ end
140
+
141
+ keyboard = Proc.new do |key, x, y|
142
+ case (key)
143
+ when 27
144
+ exit(0)
145
+ end
146
+ end
147
+
148
+ # Main Loop
149
+ # Open window with initial window size, title bar,
150
+ # RGBA display mode, depth buffer, and handle input events.
151
+ glutInit
152
+ glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)
153
+ glutInitWindowSize(800, 300)
154
+ glutInitWindowPosition(100, 100)
155
+ glutCreateWindow($0)
156
+ myinit()
157
+ glutReshapeFunc(myReshape)
158
+ glutDisplayFunc(display)
159
+ glutKeyboardFunc(keyboard)
160
+ glutCreateMenu(selectFog)
161
+ glutAddMenuEntry("Fog EXP", GL_EXP)
162
+ glutAddMenuEntry("Fog EXP2", GL_EXP2)
163
+ glutAddMenuEntry("Fog LINEAR", GL_LINEAR)
164
+ glutAddMenuEntry("Quit", 0)
165
+ glutAttachMenu(GLUT_RIGHT_BUTTON)
166
+ glutMainLoop()
167
+