ruby-opengl 0.33.0 → 0.40.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/Rakefile +42 -15
  2. data/doc/build_install.txt +70 -25
  3. data/doc/history.txt +4 -0
  4. data/doc/requirements_and_design.txt +2 -3
  5. data/doc/roadmap.txt +15 -2
  6. data/doc/screenshots.txt +23 -0
  7. data/doc/supplies/page_template.html +2 -1
  8. data/doc/thanks.txt +3 -0
  9. data/doc/tutorial.txt +5 -3
  10. data/examples/README +57 -7
  11. data/examples/legacy/COPYRIGHT +8 -0
  12. data/examples/{aaindex.rb → legacy/aaindex.rb} +6 -5
  13. data/examples/legacy/aapoly.rb +153 -0
  14. data/examples/legacy/aargb.rb +139 -0
  15. data/examples/legacy/accanti.rb +159 -0
  16. data/examples/legacy/accpersp.rb +216 -0
  17. data/examples/legacy/alpha.rb +133 -0
  18. data/examples/legacy/alpha3D.rb +165 -0
  19. data/examples/legacy/bezcurve.rb +107 -0
  20. data/examples/legacy/bezmesh.rb +131 -0
  21. data/examples/legacy/checker.rb +121 -0
  22. data/examples/legacy/clip.rb +104 -0
  23. data/examples/legacy/colormat.rb +145 -0
  24. data/examples/legacy/cube.rb +73 -0
  25. data/examples/legacy/depthcue.rb +101 -0
  26. data/examples/legacy/dof.rb +212 -0
  27. data/examples/legacy/double.rb +104 -0
  28. data/examples/legacy/drawf.rb +98 -0
  29. data/examples/legacy/feedback.rb +152 -0
  30. data/examples/legacy/fog.rb +172 -0
  31. data/examples/legacy/font-glut.rb +41 -0
  32. data/examples/legacy/font.rb +158 -0
  33. data/examples/legacy/hello.rb +75 -0
  34. data/examples/legacy/image.rb +145 -0
  35. data/examples/legacy/jitter.rb +209 -0
  36. data/examples/legacy/lines.rb +135 -0
  37. data/examples/legacy/list.rb +120 -0
  38. data/examples/legacy/material.rb +290 -0
  39. data/examples/legacy/mipmap.rb +159 -0
  40. data/examples/legacy/model.rb +119 -0
  41. data/examples/legacy/movelight.rb +140 -0
  42. data/examples/legacy/pickdepth.rb +180 -0
  43. data/examples/legacy/planet.rb +112 -0
  44. data/examples/legacy/quadric.rb +180 -0
  45. data/examples/legacy/readpixel.rb +59 -0
  46. data/examples/legacy/robot.rb +120 -0
  47. data/examples/legacy/select.rb +207 -0
  48. data/examples/{smooth_prev.rb → legacy/smooth.rb} +3 -2
  49. data/examples/legacy/stencil.rb +154 -0
  50. data/examples/legacy/stroke.rb +170 -0
  51. data/examples/legacy/surface.rb +170 -0
  52. data/examples/legacy/teaambient.rb +132 -0
  53. data/examples/legacy/teapots.rb +188 -0
  54. data/examples/legacy/tess.rb +222 -0
  55. data/examples/legacy/texbind.rb +157 -0
  56. data/examples/legacy/texgen.rb +171 -0
  57. data/examples/legacy/texturesurf.rb +128 -0
  58. data/examples/legacy/varray.rb +167 -0
  59. data/examples/legacy/wrap.rb +158 -0
  60. data/examples/nehe_lesson02.rb +117 -0
  61. data/examples/nehe_lesson03.rb +122 -0
  62. data/examples/nehe_lesson04.rb +133 -0
  63. data/examples/nehe_lesson05.rb +186 -0
  64. data/examples/plane.rb +1 -1
  65. data/examples/smooth.rb +4 -2
  66. data/examples/test.rb +3 -2
  67. data/ext/common/{rbogl.c → common.h} +99 -32
  68. data/ext/common/gl-enums.h +39 -1
  69. data/ext/gl/gl-1.0-1.1.c +350 -305
  70. data/ext/gl/gl-1.2.c +933 -38
  71. data/ext/gl/gl-1.3.c +725 -0
  72. data/ext/gl/gl-1.4.c +647 -0
  73. data/ext/gl/gl-1.5.c +362 -0
  74. data/ext/gl/gl-2.0.c +1632 -0
  75. data/ext/gl/gl-2.1.c +154 -0
  76. data/ext/gl/gl-enums.c +1 -2
  77. data/ext/gl/gl.c +58 -2
  78. data/ext/gl/mkrf_conf.rb +4 -1
  79. data/ext/glu/glu.c +5 -4
  80. data/ext/glu/mkrf_conf.rb +4 -1
  81. data/ext/glut/glut.c +7 -1
  82. data/ext/glut/mkrf_conf.rb +5 -0
  83. data/lib/gl_prev.rb +4 -3
  84. data/lib/glu_prev.rb +4 -3
  85. data/lib/glut_prev.rb +3 -3
  86. data/{examples/all_tests.rb → lib/opengl.rb} +9 -12
  87. data/test/README +5 -18
  88. data/test/tc_common.rb +79 -0
  89. data/test/tc_func_10_11.rb +1255 -0
  90. data/test/tc_func_12.rb +186 -0
  91. data/test/tc_func_13.rb +203 -0
  92. data/test/tc_func_14.rb +197 -0
  93. data/test/tc_func_15.rb +82 -0
  94. data/test/tc_func_20.rb +320 -0
  95. data/test/tc_func_21.rb +67 -0
  96. data/test/tc_include_gl.rb +1 -1
  97. data/test/{tc_opengl_namespace.rb → tc_misc.rb} +20 -20
  98. data/test/tc_require_gl.rb +1 -1
  99. metadata +99 -27
  100. data/ext/common/Rakefile +0 -39
  101. data/ext/common/rbogl.h +0 -52
  102. data/test/runtests.sh +0 -7
  103. data/test/tc_gl_vertex.rb +0 -180
@@ -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
+ #
38
+ #/*
39
+ # * colormat.c
40
+ # * After initialization, the program will be in
41
+ # * ColorMaterial mode. Interaction: pressing the
42
+ # * mouse buttons will change the diffuse reflection values.
43
+ # */
44
+
45
+ require "gl_prev"
46
+ require "glu_prev"
47
+ require "glut_prev"
48
+ require "mathn"
49
+
50
+ $diffuseMaterial = [0.5,0.5,0.5,1.0];
51
+
52
+ #/* Initialize material property, light source, lighting model,
53
+ # * and depth buffer.
54
+ # */
55
+ def init
56
+ mat_specular = [ 1.0, 1.0, 1.0, 1.0 ];
57
+ light_position = [ 1.0, 1.0, 1.0, 0.0 ];
58
+
59
+ GL.ClearColor(0.0, 0.0, 0.0, 0.0);
60
+ GL.ShadeModel(GL::SMOOTH);
61
+ GL.Enable(GL::DEPTH_TEST);
62
+ GL.Material(GL::FRONT, GL::DIFFUSE, $diffuseMaterial);
63
+ GL.Material(GL::FRONT, GL::SPECULAR, mat_specular);
64
+ GL.Material(GL::FRONT, GL::SHININESS, 25.0);
65
+ GL.Light(GL::LIGHT0, GL::POSITION, light_position);
66
+ GL.Enable(GL::LIGHTING);
67
+ GL.Enable(GL::LIGHT0);
68
+
69
+ GL.ColorMaterial(GL::FRONT, GL::DIFFUSE);
70
+ GL.Enable(GL::COLOR_MATERIAL);
71
+ end
72
+
73
+ display = Proc.new {
74
+ GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
75
+ GLUT.SolidSphere(1.0, 20, 16);
76
+ GL.Flush();
77
+ }
78
+
79
+ reshape = Proc.new {|w, h|
80
+ GL.Viewport(0, 0, w, h);
81
+ GL.MatrixMode (GL::PROJECTION);
82
+ GL.LoadIdentity();
83
+ if (w <= h)
84
+ GL.Ortho(-1.5, 1.5, -1.5*h/w, 1.5*h/w, -10.0, 10.0);
85
+ else
86
+ GL.Ortho(-1.5*w/h, 1.5*w/h, -1.5, 1.5, -10.0, 10.0);
87
+ end
88
+ GL.MatrixMode(GL::MODELVIEW);
89
+ GL.LoadIdentity();
90
+ }
91
+
92
+ # /* ARGSUSED2 */
93
+ mouse = Proc.new {|button, state, x, y|
94
+ case (button)
95
+ when GLUT::LEFT_BUTTON
96
+ if (state == GLUT::DOWN)
97
+ $diffuseMaterial[0] = $diffuseMaterial[0] + 0.1;
98
+ if ($diffuseMaterial[0] > 1.0)
99
+ $diffuseMaterial[0] = 0.0;
100
+ end
101
+ GL.Color($diffuseMaterial);
102
+ GLUT.PostRedisplay();
103
+ end
104
+ when GLUT::MIDDLE_BUTTON
105
+ if (state == GLUT::DOWN)
106
+ $diffuseMaterial[1] = $diffuseMaterial[1] + 0.1;
107
+ if ($diffuseMaterial[1] > 1.0)
108
+ $diffuseMaterial[1] = 0.0;
109
+ end
110
+ GL.Color($diffuseMaterial);
111
+ GLUT.PostRedisplay();
112
+ end
113
+ when GLUT::RIGHT_BUTTON
114
+ if (state == GLUT::DOWN)
115
+ $diffuseMaterial[2] = $diffuseMaterial[2] + 0.1;
116
+ if ($diffuseMaterial[2] > 1.0)
117
+ $diffuseMaterial[2] = 0.0;
118
+ end
119
+ GL.Color($diffuseMaterial);
120
+ GLUT.PostRedisplay();
121
+ end
122
+ end
123
+ }
124
+
125
+ # /* ARGSUSED1 */
126
+ keyboard = Proc.new {|key, x, y|
127
+ case (key)
128
+ when 27
129
+ exit(0);
130
+ end
131
+ }
132
+
133
+ #int main(int argc, char** argv)
134
+ #{
135
+ GLUT.Init
136
+ GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB | GLUT::DEPTH);
137
+ GLUT.InitWindowSize(500, 500);
138
+ GLUT.InitWindowPosition(100, 100);
139
+ GLUT.CreateWindow($0);
140
+ init();
141
+ GLUT.DisplayFunc(display);
142
+ GLUT.ReshapeFunc(reshape);
143
+ GLUT.MouseFunc(mouse);
144
+ GLUT.KeyboardFunc(keyboard);
145
+ GLUT.MainLoop();
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby -rubygems
2
+ require "gl_prev"
3
+ require "glu_prev"
4
+ require "glut_prev"
5
+
6
+
7
+ $light_diffuse = [1.0, 0.0, 0.0, 1.0]
8
+ $light_position = [1.0, 1.0, 1.0, 0.0]
9
+ $n = [
10
+ [-1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0],
11
+ [0.0, -1.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, -1.0] ]
12
+ $faces = [
13
+ [0, 1, 2, 3], [3, 2, 6, 7], [7, 6, 5, 4],
14
+ [4, 5, 1, 0], [5, 6, 2, 1], [7, 4, 0, 3] ]
15
+ $v = 0
16
+
17
+ def drawBox
18
+ for i in (0..5)
19
+ GL.Begin(GL::QUADS);
20
+ GL.Normal(*($n[i]));
21
+ # tmp = $v.to_array
22
+ # GL.Vertex3f(*$v[$faces[i][0]]);
23
+ # GL.Vertex3f(*$v[$faces[i][1]]);
24
+ # GL.Vertex3f(*$v[$faces[i][2]]);
25
+ # GL.Vertex3f(*$v[$faces[i][3]]);
26
+ GL.Vertex($v[$faces[i][0]]);
27
+ GL.Vertex($v[$faces[i][1]]);
28
+ GL.Vertex($v[$faces[i][2]]);
29
+ GL.Vertex($v[$faces[i][3]]);
30
+ GL.End()
31
+ end
32
+ end
33
+
34
+ display = Proc.new {
35
+ GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
36
+ drawBox
37
+ GLUT.SwapBuffers
38
+ }
39
+
40
+ def myinit
41
+ # $v[0,0] = $v[1,0] = $v[2,0] = $v[3,0] = -1;
42
+ # $v[4,0] = $v[5,0] = $v[6,0] = $v[7,0] = 1;
43
+ # $v[0,1] = $v[1,1] = $v[4,1] = $v[5,1] = -1;
44
+ # $v[2,1] = $v[3,1] = $v[6,1] = $v[7,1] = 1;
45
+ # $v[0,2] = $v[3,2] = $v[4,2] = $v[7,2] = 1;
46
+ # $v[1,2] = $v[2,2] = $v[5,2] = $v[6,2] = -1;
47
+
48
+ $v = [[-1, -1,1],[-1, -1,-1], [-1,1,-1], [-1,1,1], [1, -1,1],
49
+ [1, -1,-1], [1, 1,-1], [1,1,1]]
50
+
51
+ GL.Light(GL::LIGHT0, GL::DIFFUSE, $light_diffuse);
52
+ GL.Light(GL::LIGHT0, GL::POSITION, $light_position);
53
+ GL.Enable(GL::LIGHT0);
54
+ GL.Enable(GL::LIGHTING);
55
+
56
+ GL.Enable(GL::DEPTH_TEST);
57
+
58
+ GL.MatrixMode(GL::PROJECTION);
59
+ GLU.Perspective(40.0, 1.0, 1.0, 10.0);
60
+ GL.MatrixMode(GL::MODELVIEW);
61
+ GLU.LookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
62
+
63
+ GL.Translate(0.0, 0.0, -1.0);
64
+ GL.Rotate(60, 1.0, 0.0, 0.0);
65
+ GL.Rotate(-20, 0.0, 0.0, 1.0);
66
+ end
67
+
68
+ GLUT.Init
69
+ GLUT.InitDisplayMode(GLUT::DOUBLE | GLUT::RGB | GLUT::DEPTH);
70
+ GLUT.CreateWindow("red 3D lighted cube");
71
+ GLUT.DisplayFunc(display);
72
+ myinit
73
+ GLUT.MainLoop();
@@ -0,0 +1,101 @@
1
+ #
2
+ #/* Copyright (c) Mark J. Kilgard, 1994. */
3
+ #
4
+ #/*
5
+ # * (c) Copyright 1993, Silicon Graphics, Inc.
6
+ # * ALL RIGHTS RESERVED
7
+ # * Permission to use, copy, modify, and distribute this software for
8
+ # * any purpose and without fee is hereby granted, provided that the above
9
+ # * copyright notice appear in all copies and that both the copyright notice
10
+ # * and this permission notice appear in supporting documentation, and that
11
+ # * the name of Silicon Graphics, Inc. not be used in advertising
12
+ # * or publicity pertaining to distribution of the software without specific,
13
+ # * written prior permission.
14
+ # *
15
+ # * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
16
+ # * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
17
+ # * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
18
+ # * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19
+ # * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
20
+ # * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
21
+ # * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
22
+ # * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
23
+ # * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
24
+ # * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
25
+ # * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
26
+ # * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
27
+ # *
28
+ # * US Government Users Restricted Rights
29
+ # * Use, duplication, or disclosure by the Government is subject to
30
+ # * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
31
+ # * (c)(1)(ii) of the Rights in Technical Data and Computer Software
32
+ # * clause at DFARS 252.227-7013 and/or in similar or successor
33
+ # * clauses in the FAR or the DOD or NASA FAR Supplement.
34
+ # * Unpublished-- rights reserved under the copyright laws of the
35
+ # * United States. Contractor/manufacturer is Silicon Graphics,
36
+ # * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
37
+ # *
38
+ # * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
39
+ # */
40
+ #/*
41
+ # * depthcue.c
42
+ # * This program draws a wireframe model, which uses
43
+ # * intensity (brightness) to give clues to distance.
44
+ # * Fog is used to achieve this effect.
45
+ # */
46
+ require "gl_prev"
47
+ require "glu_prev"
48
+ require "glut_prev"
49
+ require "mathn"
50
+
51
+ #/* Initialize linear fog for depth cueing.
52
+ # */
53
+ def myinit
54
+ fogColor = [0.0, 0.0, 0.0, 1.0];
55
+
56
+ GL.Enable(GL::FOG);
57
+ GL.Fog(GL::FOG_MODE, GL::LINEAR);
58
+ GL.Hint(GL::FOG_HINT, GL::NICEST); #/* per pixel */
59
+ GL.Fog(GL::FOG_START, 3.0);
60
+ GL.Fog(GL::FOG_END, 5.0);
61
+ GL.Fog(GL::FOG_COLOR, fogColor);
62
+ GL.ClearColor(0.0, 0.0, 0.0, 1.0);
63
+
64
+ GL.DepthFunc(GL::LESS);
65
+ GL.Enable(GL::DEPTH_TEST);
66
+ GL.ShadeModel(GL::FLAT);
67
+ end
68
+
69
+ #/* display() draws an icosahedron.
70
+ # */
71
+ display = Proc.new {
72
+ GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
73
+ GL.Color(1.0, 1.0, 1.0);
74
+ GLUT.WireIcosahedron();
75
+ GL.Flush();
76
+ }
77
+
78
+ myReshape = Proc.new {|w, h|
79
+ GL.Viewport(0, 0, w, h);
80
+ GL.MatrixMode(GL::PROJECTION);
81
+ GL.LoadIdentity();
82
+ GLU.Perspective(45.0, w/h, 3.0, 5.0);
83
+ GL.MatrixMode(GL::MODELVIEW);
84
+ GL.LoadIdentity();
85
+ GL.Translate(0.0, 0.0, -4.0); #/* move object into view */
86
+ }
87
+
88
+ #/* Main Loop
89
+ # */
90
+ #int main(int argc, char** argv)
91
+ #{
92
+ GLUT.Init
93
+ GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB | GLUT::DEPTH);
94
+ GLUT.CreateWindow($0);
95
+ myinit();
96
+ GLUT.ReshapeFunc(myReshape);
97
+ GLUT.DisplayFunc(display);
98
+ GLUT.MainLoop();
99
+ # return 0; /* ANSI C requires main to return int. */
100
+ #}
101
+
@@ -0,0 +1,212 @@
1
+ #
2
+ #/* Copyright (c) Mark J. Kilgard, 1994. */
3
+ #
4
+ #/*
5
+ # * (c) Copyright 1993, Silicon Graphics, Inc.
6
+ # * ALL RIGHTS RESERVED
7
+ # * Permission to use, copy, modify, and distribute this software for
8
+ # * any purpose and without fee is hereby granted, provided that the above
9
+ # * copyright notice appear in all copies and that both the copyright notice
10
+ # * and this permission notice appear in supporting documentation, and that
11
+ # * the name of Silicon Graphics, Inc. not be used in advertising
12
+ # * or publicity pertaining to distribution of the software without specific,
13
+ # * written prior permission.
14
+ # *
15
+ # * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
16
+ # * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
17
+ # * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
18
+ # * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19
+ # * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
20
+ # * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
21
+ # * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
22
+ # * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
23
+ # * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
24
+ # * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
25
+ # * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
26
+ # * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
27
+ # *
28
+ # * US Government Users Restricted Rights
29
+ # * Use, duplication, or disclosure by the Government is subject to
30
+ # * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
31
+ # * (c)(1)(ii) of the Rights in Technical Data and Computer Software
32
+ # * clause at DFARS 252.227-7013 and/or in similar or successor
33
+ # * clauses in the FAR or the DOD or NASA FAR Supplement.
34
+ # * Unpublished-- rights reserved under the copyright laws of the
35
+ # * United States. Contractor/manufacturer is Silicon Graphics,
36
+ # * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
37
+ # *
38
+ # * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
39
+ # */
40
+ #/*
41
+ # * dof.c
42
+ # * This program demonstrates use of the accumulation buffer to
43
+ # * create an out-of-focus depth-of-field effect. The teapots
44
+ # * are drawn several times into the accumulation buffer. The
45
+ # * viewing volume is jittered, except at the focal point, where
46
+ # * the viewing volume is at the same position, each time. In
47
+ # * this case, the gold teapot remains in focus.
48
+ # */
49
+ require "gl_prev"
50
+ require "glu_prev"
51
+ require "glut_prev"
52
+ require "jitter"
53
+
54
+ PI_=3.14159265358979323846
55
+
56
+ #/* accFrustum()
57
+ # * The first 6 arguments are identical to the glFrustum() call.
58
+ # *
59
+ # * pixdx and pixdy are anti-alias jitter in pixels.
60
+ # * Set both equal to 0.0 for no anti-alias jitter.
61
+ # * eyedx and eyedy are depth-of field jitter in pixels.
62
+ # * Set both equal to 0.0 for no depth of field effects.
63
+ # *
64
+ # * focus is distance from eye to plane in focus.
65
+ # * focus must be greater than, but not equal to 0.0.
66
+ # *
67
+ # * Note that accFrustum() calls glTranslatef(). You will
68
+ # * probably want to insure that your ModelView matrix has been
69
+ # * initialized to identity before calling accFrustum().
70
+ # */
71
+ def accFrustum(left, right, bottom, top, nnear, ffar, pixdx, pixdy, eyedx, eyedy, focus)
72
+
73
+ viewport = GL::GetDoublev(GL::VIEWPORT);
74
+
75
+ xwsize = right - left;
76
+ ywsize = top - bottom;
77
+
78
+ dx = -(pixdx*xwsize/viewport[2] + eyedx*nnear/focus);
79
+ dy = -(pixdy*ywsize/viewport[3] + eyedy*nnear/focus);
80
+
81
+ GL::MatrixMode(GL::PROJECTION);
82
+ GL::LoadIdentity();
83
+ GL::Frustum(left + dx, right + dx, bottom + dy, top + dy, nnear, ffar);
84
+ GL::MatrixMode(GL::MODELVIEW);
85
+ GL::LoadIdentity();
86
+ GL::Translate(-eyedx, -eyedy, 0.0);
87
+ end
88
+
89
+ #/* accPerspective()
90
+ # *
91
+ # * The first 4 arguments are identical to the gluPerspective() call.
92
+ # * pixdx and pixdy are anti-alias jitter in pixels.
93
+ # * Set both equal to 0.0 for no anti-alias jitter.
94
+ # * eyedx and eyedy are depth-of field jitter in pixels.
95
+ # * Set both equal to 0.0 for no depth of field effects.
96
+ # *
97
+ # * focus is distance from eye to plane in focus.
98
+ # * focus must be greater than, but not equal to 0.0.
99
+ # *
100
+ # * Note that accPerspective() calls accFrustum().
101
+ # */
102
+ def accPerspective(fovy, aspect, nnear, ffar, pixdx, pixdy, eyedx, eyedy, focus)
103
+ fov2 = ((fovy*PI_) / 180.0) / 2.0;
104
+
105
+ top = nnear / (Math::cos(fov2) / Math::sin(fov2));
106
+ bottom = -top;
107
+
108
+ right = top * aspect;
109
+ left = -right;
110
+
111
+ accFrustum(left, right, bottom, top, nnear, ffar,
112
+ pixdx, pixdy, eyedx, eyedy, focus);
113
+ end
114
+
115
+
116
+ def myinit
117
+ ambient = [ 0.0, 0.0, 0.0, 1.0 ];
118
+ diffuse = [ 1.0, 1.0, 1.0, 1.0 ];
119
+ position = [ 0.0, 3.0, 3.0, 0.0 ];
120
+
121
+ lmodel_ambient = [ 0.2, 0.2, 0.2, 1.0 ];
122
+ local_view = [ 0.0 ];
123
+
124
+ GL::Enable(GL::DEPTH_TEST);
125
+ GL::DepthFunc(GL::LESS);
126
+
127
+ GL::Light(GL::LIGHT0, GL::AMBIENT, ambient);
128
+ GL::Light(GL::LIGHT0, GL::DIFFUSE, diffuse);
129
+ GL::Light(GL::LIGHT0, GL::POSITION, position);
130
+
131
+ GL::LightModel(GL::LIGHT_MODEL_AMBIENT, lmodel_ambient);
132
+ GL::LightModel(GL::LIGHT_MODEL_LOCAL_VIEWER, local_view);
133
+
134
+ GL::FrontFace(GL::CW);
135
+ GL::Enable(GL::LIGHTING);
136
+ GL::Enable(GL::LIGHT0);
137
+ GL::Enable(GL::AUTO_NORMAL);
138
+ GL::Enable(GL::NORMALIZE);
139
+
140
+ GL::MatrixMode(GL::MODELVIEW);
141
+ GL::LoadIdentity();
142
+
143
+ GL::ClearColor(0.0, 0.0, 0.0, 0.0);
144
+ GL::ClearAccum(0.0, 0.0, 0.0, 0.0);
145
+ end
146
+
147
+ def renderTeapot (x, y, z, ambr, ambg, ambb, difr, difg, difb, specr, specg, specb, shine)
148
+ GL::PushMatrix();
149
+ GL::Translate(x, y, z);
150
+ mat = []
151
+ mat[0] = ambr; mat[1] = ambg; mat[2] = ambb; mat[3] = 1.0;
152
+ GL::Material(GL::FRONT, GL::AMBIENT, mat);
153
+ mat[0] = difr; mat[1] = difg; mat[2] = difb;
154
+ GL::Material(GL::FRONT, GL::DIFFUSE, mat);
155
+ mat[0] = specr; mat[1] = specg; mat[2] = specb;
156
+ GL::Material(GL::FRONT, GL::SPECULAR, mat);
157
+ GL::Material(GL::FRONT, GL::SHININESS, shine*128.0);
158
+ GLUT::SolidTeapot(0.5);
159
+ GL::PopMatrix();
160
+ end
161
+
162
+ #/* display() draws 5 teapots into the accumulation buffer
163
+ # * several times; each time with a jittered perspective.
164
+ # * The focal point is at z = 5.0, so the gold teapot will
165
+ # * stay in focus. The amount of jitter is adjusted by the
166
+ # * magnitude of the accPerspective() jitter; in this example, 0.33.
167
+ # * In this example, the teapots are drawn 8 times. See jitter.h
168
+ # */
169
+ display = proc {
170
+ viewport = GL::GetDoublev(GL::VIEWPORT);
171
+ GL::Clear(GL::ACCUM_BUFFER_BIT);
172
+
173
+ for jitter in 0...8
174
+ GL::Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
175
+ accPerspective(45.0,
176
+ viewport[2]/ viewport[3],
177
+ 1.0, 15.0, 0.0, 0.0,
178
+ 0.33*$j8[jitter][0], 0.33*$j8[jitter][1], 5.0);
179
+ #/* ruby, gold, silver, emerald, and cyan teapots */
180
+ renderTeapot(-1.1, -0.5, -4.5, 0.1745, 0.01175, 0.01175,
181
+ 0.61424, 0.04136, 0.04136, 0.727811, 0.626959, 0.626959, 0.6);
182
+ renderTeapot(-0.5, -0.5, -5.0, 0.24725, 0.1995, 0.0745,
183
+ 0.75164, 0.60648, 0.22648, 0.628281, 0.555802, 0.366065, 0.4);
184
+ renderTeapot(0.2, -0.5, -5.5, 0.19225, 0.19225, 0.19225,
185
+ 0.50754, 0.50754, 0.50754, 0.508273, 0.508273, 0.508273, 0.4);
186
+ renderTeapot(1.0, -0.5, -6.0, 0.0215, 0.1745, 0.0215,
187
+ 0.07568, 0.61424, 0.07568, 0.633, 0.727811, 0.633, 0.6);
188
+ renderTeapot(1.8, -0.5, -6.5, 0.0, 0.1, 0.06, 0.0, 0.50980392,
189
+ 0.50980392, 0.50196078, 0.50196078, 0.50196078, 0.25);
190
+ GL::Accum(GL::ACCUM, 0.125);
191
+ end
192
+
193
+ GL::Accum(GL::RETURN, 1.0);
194
+ GL::Flush();
195
+ }
196
+
197
+ myReshape = proc {|w, h|
198
+ GL::Viewport(0, 0, w, h);
199
+ }
200
+
201
+ #/* Main Loop
202
+ # * Open window with initial window size, title bar,
203
+ # * RGBA display mode, depth buffer, and handle input events.
204
+ # */
205
+ GLUT::Init();
206
+ GLUT::InitDisplayMode(GLUT::SINGLE | GLUT::RGB | GLUT::ACCUM | GLUT::DEPTH);
207
+ GLUT::CreateWindow()
208
+ myinit();
209
+ GLUT::ReshapeFunc(myReshape);
210
+ GLUT::DisplayFunc(display);
211
+ GLUT::MainLoop();
212
+