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,104 @@
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
+ # 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;
50
+
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();
58
+
59
+ GLUT.SwapBuffers();
60
+ }
61
+
62
+ $spinDisplay = Proc.new {
63
+ $spin = $spin + 4.0;
64
+ $spin = $spin - 360.0 if ($spin > 360.0)
65
+ GLUT.PostRedisplay();
66
+ }
67
+
68
+ def init
69
+ GL.ClearColor(0.0, 0.0, 0.0, 0.0);
70
+ GL.ShadeModel(GL::FLAT);
71
+ end
72
+
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
+ }
81
+
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
+ }
90
+
91
+ #
92
+ # Request double buffer display mode.
93
+ # 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();
@@ -0,0 +1,98 @@
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
+ #* 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
+
48
+
49
+ $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*");
53
+
54
+ def init
55
+ GL.PixelStorei(GL::UNPACK_ALIGNMENT, 1);
56
+ GL.ClearColor(0.0, 0.0, 0.0, 0.0);
57
+ end
58
+
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
+ }
68
+
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
+ }
76
+
77
+ #* ARGSUSED1 */
78
+ keyboard = Proc.new {|key, x, y|
79
+ case (key)
80
+ when 27
81
+ exit(0);
82
+ end
83
+ }
84
+
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();
@@ -0,0 +1,152 @@
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
+ # * feedback.c
40
+ # * This program demonstrates use of OpenGL feedback. First,
41
+ # * a lighting environment is set up and a few lines are drawn.
42
+ # * Then feedback mode is entered, and the same lines are
43
+ # * drawn. The results in the feedback buffer are printed.
44
+ # */
45
+ require "gl_prev"
46
+ require "glu_prev"
47
+ require "glut_prev"
48
+
49
+
50
+ #/* Initialize lighting.
51
+ # */
52
+ def init
53
+ GL::Enable(GL::LIGHTING);
54
+ GL::Enable(GL::LIGHT0);
55
+ end
56
+
57
+ #/* Draw a few lines and two points, one of which will
58
+ # * be clipped. If in feedback mode, a passthrough token
59
+ # * is issued between the each primitive.
60
+ # */
61
+ def drawGeometry(mode)
62
+ GL::Begin(GL::LINE_STRIP);
63
+ GL::Normal(0.0, 0.0, 1.0);
64
+ GL::Vertex(30.0, 30.0, 0.0);
65
+ GL::Vertex(50.0, 60.0, 0.0);
66
+ GL::Vertex(70.0, 40.0, 0.0);
67
+ GL::End();
68
+ if (mode == GL::FEEDBACK)
69
+ GL::PassThrough(1.0);
70
+ end
71
+ GL::Begin(GL::POINTS);
72
+ GL::Vertex(-100.0, -100.0, -100.0); # /* will be clipped */
73
+ GL::End();
74
+ if (mode == GL::FEEDBACK)
75
+ GL::PassThrough(2.0);
76
+ end
77
+ GL::Begin(GL::POINTS);
78
+ GL::Normal(0.0, 0.0, 1.0);
79
+ GL::Vertex(50.0, 50.0, 0.0);
80
+ GL::End();
81
+ end
82
+
83
+ # /* Write contents of one vertex to stdout. */
84
+ def print3DcolorVertex(size, count, buffer)
85
+ printf(" ");
86
+ for i in 0...7
87
+ printf("%4.2f ", buffer[size-count]);
88
+ count = count - 1;
89
+ end
90
+ printf("\n");
91
+ return count
92
+ end
93
+
94
+ #/* Write contents of entire buffer. (Parse tokens!) */
95
+ def printBuffer(size, buffer)
96
+
97
+ count = size;
98
+ while (count!=0)
99
+ token = buffer[size-count]; count-=1;
100
+ if (token == GL::PASS_THROUGH_TOKEN)
101
+ printf("GL::PASS_THROUGH_TOKEN\n");
102
+ printf(" %4.2f\n", buffer[size-count]);
103
+ count-=1;
104
+ elsif (token == GL::POINT_TOKEN)
105
+ printf("GL::POINT_TOKEN\n");
106
+ count = print3DcolorVertex(size, count, buffer);
107
+ elsif (token == GL::LINE_TOKEN)
108
+ printf("GL::LINE_TOKEN\n");
109
+ count = print3DcolorVertex(size, count, buffer);
110
+ count = print3DcolorVertex(size, count, buffer);
111
+ elsif (token == GL::LINE_RESET_TOKEN)
112
+ printf("GL::LINE_RESET_TOKEN\n");
113
+ count = print3DcolorVertex(size, count, buffer);
114
+ count = print3DcolorVertex(size, count, buffer);
115
+ end
116
+ end
117
+ end
118
+
119
+ display = proc {
120
+ GL::MatrixMode(GL::PROJECTION);
121
+ GL::LoadIdentity();
122
+ GL::Ortho(0.0, 100.0, 0.0, 100.0, 0.0, 1.0);
123
+
124
+ GL::ClearColor(0.0, 0.0, 0.0, 0.0);
125
+ GL::Clear(GL::COLOR_BUFFER_BIT);
126
+ drawGeometry(GL::RENDER);
127
+
128
+ feedBuffer = GL::FeedbackBuffer(1024, GL::GL_3D_COLOR);
129
+ GL::RenderMode(GL::FEEDBACK);
130
+ drawGeometry(GL::FEEDBACK);
131
+
132
+ size = GL::RenderMode(GL::RENDER);
133
+ printBuffer(size, feedBuffer.unpack("f#{size}"));
134
+ }
135
+
136
+ #/* ARGSUSED1 */
137
+ keyboard = proc {|key, x, y|
138
+ case (key)
139
+ when 27
140
+ exit(0);
141
+ end
142
+ }
143
+
144
+ GLUT::Init()
145
+ GLUT::InitDisplayMode(GLUT::SINGLE | GLUT::RGB);
146
+ GLUT::InitWindowSize(100, 100);
147
+ GLUT::InitWindowPosition(100, 100);
148
+ GLUT::CreateWindow()
149
+ init();
150
+ GLUT::DisplayFunc(display);
151
+ GLUT::KeyboardFunc(keyboard);
152
+ GLUT::MainLoop();
@@ -0,0 +1,172 @@
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
+ # * fog.c
42
+ # * This program draws 5 red teapots, each at a different
43
+ # * z distance from the eye, in different types of fog.
44
+ # * Pressing the left mouse button chooses between 3 types of
45
+ # * fog: exponential, exponential squared, and linear.
46
+ # * In this program, there is a fixed density value, as well
47
+ # * as fixed start and end values for the linear fog.
48
+ # */
49
+
50
+ require "gl_prev"
51
+ require "glu_prev"
52
+ require "glut_prev"
53
+ require "mathn"
54
+
55
+ $fogMode = 0;
56
+
57
+ selectFog = Proc.new {|mode|
58
+ if (mode == GL::LINEAR)
59
+ GL.Fog(GL::FOG_START, 1.0);
60
+ GL.Fog(GL::FOG_END, 5.0);
61
+ #/* falls through */
62
+ GL.Fog(GL::FOG_MODE, mode);
63
+ GLUT.PostRedisplay();
64
+ end
65
+ if (mode == GL::EXP2 || mode == GL::EXP)
66
+ GL.Fog(GL::FOG_MODE, mode);
67
+ GLUT.PostRedisplay();
68
+ end
69
+ exit(0) if (mode == 0)
70
+ }
71
+
72
+ #/* Initialize z-buffer, projection matrix, light source,
73
+ # * and lighting model. Do not specify a material property here.
74
+ # */
75
+ def myinit
76
+ position = [0.0, 3.0, 3.0, 0.0];
77
+ local_view = [0.0];
78
+
79
+ GL.Enable(GL::DEPTH_TEST);
80
+ GL.DepthFunc(GL::LESS);
81
+
82
+ GL.Light(GL::LIGHT0, GL::POSITION, position);
83
+ GL.LightModel(GL::LIGHT_MODEL_LOCAL_VIEWER, local_view);
84
+
85
+ GL.FrontFace(GL::CW);
86
+ GL.Enable(GL::LIGHTING);
87
+ GL.Enable(GL::LIGHT0);
88
+ GL.Enable(GL::AUTO_NORMAL);
89
+ GL.Enable(GL::NORMALIZE);
90
+ GL.Enable(GL::FOG);
91
+ fogColor = [0.5, 0.5, 0.5, 1.0];
92
+
93
+ fogMode = GL::EXP;
94
+ GL.Fog(GL::FOG_MODE, fogMode);
95
+ GL.Fog(GL::FOG_COLOR, fogColor);
96
+ GL.Fog(GL::FOG_DENSITY, 0.35);
97
+ GL.Hint(GL::FOG_HINT, GL::DONT_CARE);
98
+ GL.ClearColor(0.5, 0.5, 0.5, 1.0);
99
+ end
100
+
101
+ def renderRedTeapot(x, y, z)
102
+ mat = []
103
+ GL.PushMatrix();
104
+ GL.Translate(x, y, z);
105
+ mat[0] = 0.1745;
106
+ mat[1] = 0.01175;
107
+ mat[2] = 0.01175;
108
+ mat[3] = 1.0;
109
+ GL.Material(GL::FRONT, GL::AMBIENT, mat);
110
+ mat[0] = 0.61424;
111
+ mat[1] = 0.04136;
112
+ mat[2] = 0.04136;
113
+ GL.Material(GL::FRONT, GL::DIFFUSE, mat);
114
+ mat[0] = 0.727811;
115
+ mat[1] = 0.626959;
116
+ mat[2] = 0.626959;
117
+ GL.Material(GL::FRONT, GL::SPECULAR, mat);
118
+ GL.Material(GL::FRONT, GL::SHININESS, 0.6 * 128.0);
119
+ GLUT.SolidTeapot(1.0);
120
+ GL.PopMatrix();
121
+ end
122
+
123
+ #/* display() draws 5 teapots at different z positions.
124
+ # */
125
+ display = Proc.new {
126
+ GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
127
+ renderRedTeapot(-4.0, -0.5, -1.0);
128
+ renderRedTeapot(-2.0, -0.5, -2.0);
129
+ renderRedTeapot(0.0, -0.5, -3.0);
130
+ renderRedTeapot(2.0, -0.5, -4.0);
131
+ renderRedTeapot(4.0, -0.5, -5.0);
132
+ GL.Flush();
133
+ }
134
+
135
+ myReshape = Proc.new {|w, h|
136
+ GL.Viewport(0, 0, w, h);
137
+ GL.MatrixMode(GL::PROJECTION);
138
+ GL.LoadIdentity();
139
+ if (w <= (h * 3))
140
+ GL.Ortho(-6.0, 6.0, -2.0 * h * 3 / w,
141
+ 2.0 * h * 3 / w, 0.0, 10.0);
142
+ elsif
143
+ GL.Ortho(-6.0 * w / h * 3,
144
+ 6.0 * w / h * 3, -2.0, 2.0, 0.0, 10.0);
145
+ end
146
+ GL.MatrixMode(GL::MODELVIEW);
147
+ GL.LoadIdentity();
148
+ }
149
+
150
+ #/* Main Loop
151
+ # * Open window with initial window size, title bar,
152
+ # * RGBA display mode, depth buffer, and handle input events.
153
+ # */
154
+ #int
155
+ #main(int argc, char **argv)
156
+ #{
157
+ GLUT.Init
158
+ GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB | GLUT::DEPTH);
159
+ GLUT.InitWindowSize(450, 150);
160
+ GLUT.CreateWindow($0);
161
+ myinit();
162
+ GLUT.ReshapeFunc(myReshape);
163
+ GLUT.DisplayFunc(display);
164
+ GLUT.CreateMenu(selectFog);
165
+ GLUT.AddMenuEntry("Fog EXP", GL::EXP);
166
+ GLUT.AddMenuEntry("Fog EXP2", GL::EXP2);
167
+ GLUT.AddMenuEntry("Fog LINEAR", GL::LINEAR);
168
+ GLUT.AddMenuEntry("Quit", 0);
169
+ GLUT.AttachMenu(GLUT::RIGHT_BUTTON);
170
+ GLUT.MainLoop();
171
+ # return 0; /* ANSI C requires main to return int. */
172
+ #}