ruby-opengl 0.33.0 → 0.40.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 (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,159 @@
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
+ #/* mipmap.c
41
+ # * This program demonstrates using mipmaps for texture maps.
42
+ # * To overtly show the effect of mipmaps, each mipmap reduction
43
+ # * level has a solidly colored, contrasting texture image.
44
+ # * Thus, the quadrilateral which is drawn is drawn with several
45
+ # * different colors.
46
+ # */
47
+
48
+ require "gl_prev"
49
+ require "glu_prev"
50
+ require "glut_prev"
51
+ require "mathn"
52
+
53
+ $mipmapImage32 = []
54
+ $mipmapImage16 = []
55
+ $mipmapImage8 = []
56
+ $mipmapImage4 = []
57
+ $mipmapImage2 = []
58
+ $mipmapImage1 = []
59
+
60
+ def makeImages
61
+ for i in 0..31
62
+ for j in 0..31
63
+ $mipmapImage32[(j*32+i)*3+0] = 255;
64
+ $mipmapImage32[(j*32+i)*3+1] = 255;
65
+ $mipmapImage32[(j*32+i)*3+2] = 0;
66
+ end
67
+ end
68
+ for i in 0..15
69
+ for j in 0..15
70
+ $mipmapImage16[(j*16+i)*3+0] = 255;
71
+ $mipmapImage16[(j*16+i)*3+1] = 0;
72
+ $mipmapImage16[(j*16+i)*3+2] = 255;
73
+ end
74
+ end
75
+ for i in 0..7
76
+ for j in 0..7
77
+ $mipmapImage8[(j*8+i)*3+0] = 255;
78
+ $mipmapImage8[(j*8+i)*3+1] = 0;
79
+ $mipmapImage8[(j*8+i)*3+2] = 0;
80
+ end
81
+ end
82
+ for i in 0..3
83
+ for j in 0..3
84
+ $mipmapImage4[(j*4+i)*3+0] = 0;
85
+ $mipmapImage4[(j*4+i)*3+1] = 255;
86
+ $mipmapImage4[(j*4+i)*3+2] = 0;
87
+ end
88
+ end
89
+ for i in 0..1
90
+ for j in 0..1
91
+ $mipmapImage2[(j*2+i)*3+0] = 0;
92
+ $mipmapImage2[(j*2+i)*3+1] = 0;
93
+ $mipmapImage2[(j*2+i)*3+2] = 255;
94
+ end
95
+ end
96
+ $mipmapImage1[0] = 255;
97
+ $mipmapImage1[1] = 255;
98
+ $mipmapImage1[2] = 255;
99
+ end
100
+
101
+ def myinit
102
+ GL.Enable(GL::DEPTH_TEST);
103
+ GL.DepthFunc(GL::LESS);
104
+ GL.ShadeModel(GL::FLAT);
105
+
106
+ GL.Translate(0.0, 0.0, -3.6);
107
+ makeImages();
108
+ GL.PixelStore(GL::UNPACK_ALIGNMENT, 1);
109
+ GL.TexImage2D(GL::TEXTURE_2D, 0, 3, 32, 32, 0,
110
+ GL::RGB, GL::UNSIGNED_BYTE, $mipmapImage32.pack("C*"));
111
+ GL.TexImage2D(GL::TEXTURE_2D, 1, 3, 16, 16, 0,
112
+ GL::RGB, GL::UNSIGNED_BYTE, $mipmapImage16.pack("C*"));
113
+ GL.TexImage2D(GL::TEXTURE_2D, 2, 3, 8, 8, 0,
114
+ GL::RGB, GL::UNSIGNED_BYTE, $mipmapImage8.pack("C*"));
115
+ GL.TexImage2D(GL::TEXTURE_2D, 3, 3, 4, 4, 0,
116
+ GL::RGB, GL::UNSIGNED_BYTE, $mipmapImage4.pack("C*"));
117
+ GL.TexImage2D(GL::TEXTURE_2D, 4, 3, 2, 2, 0,
118
+ GL::RGB, GL::UNSIGNED_BYTE, $mipmapImage2.pack("C*"));
119
+ GL.TexImage2D(GL::TEXTURE_2D, 5, 3, 1, 1, 0,
120
+ GL::RGB, GL::UNSIGNED_BYTE, $mipmapImage1.pack("C*"));
121
+ GL.TexParameter(GL::TEXTURE_2D, GL::TEXTURE_WRAP_S, GL::REPEAT);
122
+ GL.TexParameter(GL::TEXTURE_2D, GL::TEXTURE_WRAP_T, GL::REPEAT);
123
+ GL.TexParameter(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER, GL::NEAREST);
124
+ GL.TexParameter(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER,
125
+ GL::NEAREST_MIPMAP_NEAREST);
126
+ GL.TexEnv(GL::TEXTURE_ENV, GL::TEXTURE_ENV_MODE, GL::DECAL);
127
+ GL.Enable(GL::TEXTURE_2D);
128
+ end
129
+
130
+ display = Proc.new {
131
+ GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
132
+ GL.Begin(GL::QUADS);
133
+ GL.TexCoord(0.0, 0.0); GL.Vertex(-2.0, -1.0, 0.0);
134
+ GL.TexCoord(0.0, 8.0); GL.Vertex(-2.0, 1.0, 0.0);
135
+ GL.TexCoord(8.0, 8.0); GL.Vertex(2000.0, 1.0, -6000.0);
136
+ GL.TexCoord(8.0, 0.0); GL.Vertex(2000.0, -1.0, -6000.0);
137
+ GL.End();
138
+ GL.Flush();
139
+ }
140
+
141
+ myReshape = Proc.new {|w, h|
142
+ GL.Viewport(0, 0, w, h);
143
+ GL.MatrixMode(GL::PROJECTION);
144
+ GL.LoadIdentity();
145
+ GLU.Perspective(60.0, 1.0*w/h, 1.0, 30000.0);
146
+ GL.MatrixMode(GL::MODELVIEW);
147
+ GL.LoadIdentity();
148
+ }
149
+
150
+ #int main(int argc, char** argv)
151
+ #{
152
+ GLUT.Init
153
+ GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB | GLUT::DEPTH);
154
+ GLUT.InitWindowSize(500, 500);
155
+ GLUT.CreateWindow($0);
156
+ myinit();
157
+ GLUT.ReshapeFunc(myReshape);
158
+ GLUT.DisplayFunc(display);
159
+ GLUT.MainLoop();
@@ -0,0 +1,119 @@
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
+ # model.c
40
+ # This program demonstrates modeling transformations
41
+ #/
42
+ require "gl_prev"
43
+ require "glu_prev"
44
+ require "glut_prev"
45
+ require "mathn"
46
+
47
+ def init
48
+ GL.ClearColor(0.0, 0.0, 0.0, 0.0);
49
+ GL.ShadeModel(GL::FLAT);
50
+ end
51
+
52
+ def draw_triangle
53
+ GL.Begin (GL::LINE_LOOP);
54
+ GL.Vertex(0.0, 25.0);
55
+ GL.Vertex(25.0, -25.0);
56
+ GL.Vertex(-25.0, -25.0);
57
+ GL.End();
58
+ end
59
+
60
+ display = Proc.new {
61
+ GL.Clear(GL::COLOR_BUFFER_BIT);
62
+ GL.Color(1.0, 1.0, 1.0);
63
+
64
+ GL.LoadIdentity();
65
+ GL.Color(1.0, 1.0, 1.0);
66
+ draw_triangle();
67
+
68
+ GL.Enable(GL::LINE_STIPPLE);
69
+ GL.LineStipple(1, 0xF0F0);
70
+ GL.LoadIdentity();
71
+ GL.Translate(-20.0, 0.0, 0.0);
72
+ draw_triangle();
73
+
74
+ GL.LineStipple(1, 0xF00F);
75
+ GL.LoadIdentity();
76
+ GL.Scale(1.5, 0.5, 1.0);
77
+ draw_triangle();
78
+
79
+ GL.LineStipple(1, 0x8888);
80
+ GL.LoadIdentity();
81
+ GL.Rotate(90.0, 0.0, 0.0, 1.0);
82
+ draw_triangle();
83
+ GL.Disable(GL::LINE_STIPPLE);
84
+
85
+ GL.Flush();
86
+ }
87
+
88
+ reshape = Proc.new { |w, h|
89
+ GL.Viewport(0, 0, w, h);
90
+ GL.MatrixMode(GL::PROJECTION);
91
+ GL.LoadIdentity();
92
+ if (w <= h)
93
+ GL.Ortho(-50.0, 50.0, -50.0*h/w,
94
+ 50.0*h/w, -1.0, 1.0);
95
+ else
96
+ GL.Ortho(-50.0*w/h,
97
+ 50.0*w/h, -50.0, 50.0, -1.0, 1.0);
98
+ end
99
+ GL.MatrixMode(GL::MODELVIEW);
100
+ }
101
+
102
+ # ARGSUSED1 */
103
+ keyboard = Proc.new {|key, x, y|
104
+ case key
105
+ when 27
106
+ exit(0);
107
+ end
108
+ }
109
+
110
+ GLUT.Init
111
+ GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB);
112
+ GLUT.InitWindowSize(500, 500);
113
+ GLUT.InitWindowPosition(100, 100);
114
+ GLUT.CreateWindow($0);
115
+ init();
116
+ GLUT.DisplayFunc(display);
117
+ GLUT.ReshapeFunc(reshape);
118
+ GLUT.KeyboardFunc(keyboard);
119
+ GLUT.MainLoop();
@@ -0,0 +1,140 @@
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
+ # movelight.c
40
+ # This program demonstrates when to issue lighting and
41
+ # transformation commands to render a model with a light
42
+ # which is moved by a modeling transformation (rotate or
43
+ # translate). The light position is reset after the modeling
44
+ # transformation is called. The eye position does not change.
45
+ #
46
+ # A sphere is drawn using a grey material characteristic.
47
+ # A single light source illuminates the object.
48
+ #
49
+ # Interaction: pressing the left mouse button alters
50
+ # the modeling transformation (x rotation) by 30 degrees.
51
+ # The scene is then redrawn with the light in a new position.
52
+ #/
53
+
54
+ require "gl_prev"
55
+ require "glu_prev"
56
+ require "glut_prev"
57
+ require "rational"
58
+ require "mathn"
59
+
60
+ $spin = 0;
61
+
62
+ # Initialize material property, light source, lighting model,
63
+ # and depth buffer.
64
+ #/
65
+ def init
66
+ GL.ClearColor(0.0, 0.0, 0.0, 0.0);
67
+ GL.ShadeModel(GL::SMOOTH);
68
+ GL.Enable(GL::LIGHTING);
69
+ GL.Enable(GL::LIGHT0);
70
+ GL.Enable(GL::DEPTH_TEST);
71
+ end
72
+
73
+ # Here is where the light position is reset after the modeling
74
+ # transformation (glRotated) is called. This places the
75
+ # light at a new position in world coordinates. The cube
76
+ # represents the position of the light.
77
+ #/
78
+ display = Proc.new {
79
+ position = [ 0.0, 0.0, 1.5, 1.0 ];
80
+
81
+ GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
82
+ GL.PushMatrix();
83
+ GLU.LookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
84
+
85
+ GL.PushMatrix();
86
+ GL.Rotate($spin, 1.0, 0.0, 0.0);
87
+ GL.Light(GL::LIGHT0, GL::POSITION, position);
88
+
89
+ GL.Translate(0.0, 0.0, 1.5);
90
+ GL.Disable(GL::LIGHTING);
91
+ GL.Color(0.0, 1.0, 1.0);
92
+ GLUT.WireCube(0.1);
93
+ GL.Enable(GL::LIGHTING);
94
+ GL.PopMatrix();
95
+
96
+ GLUT.SolidTorus(0.275, 0.85, 8, 15);
97
+ GL.PopMatrix();
98
+ GL.Flush();
99
+ }
100
+
101
+ reshape = Proc.new {|w, h|
102
+ GL.Viewport(0, 0, w, h);
103
+ GL.MatrixMode(GL::PROJECTION);
104
+ GL.LoadIdentity();
105
+ # GLU.Perspective(40.0, Rational(w,h), 1.0, 20.0);
106
+ GLU.Perspective(40.0, w/h, 1.0, 20.0);
107
+ GL.MatrixMode(GL::MODELVIEW);
108
+ GL.LoadIdentity();
109
+ }
110
+
111
+ # ARGSUSED2 */
112
+ mouse = Proc.new {|button, state, x, y|
113
+ case button
114
+ when GLUT::LEFT_BUTTON
115
+ if (state == GLUT::DOWN)
116
+ $spin = ($spin + 30) % 360;
117
+ GLUT.PostRedisplay();
118
+ end
119
+ end
120
+ }
121
+
122
+ # ARGSUSED1 */
123
+ keyboard = Proc.new {|key, x, y|
124
+ case key
125
+ when 27
126
+ exit(0);
127
+ end
128
+ }
129
+
130
+ GLUT.Init
131
+ GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB | GLUT::DEPTH);
132
+ GLUT.InitWindowSize(500, 500);
133
+ GLUT.InitWindowPosition(100, 100);
134
+ GLUT.CreateWindow($0);
135
+ init();
136
+ GLUT.DisplayFunc(display);
137
+ GLUT.ReshapeFunc(reshape);
138
+ GLUT.MouseFunc(mouse);
139
+ GLUT.KeyboardFunc(keyboard);
140
+ GLUT.MainLoop();
@@ -0,0 +1,180 @@
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
+ # * pickdepth.c
42
+ # * Picking is demonstrated in this program. In
43
+ # * rendering mode, three overlapping rectangles are
44
+ # * drawn. When the left mouse button is pressed,
45
+ # * selection mode is entered with the picking matrix.
46
+ # * Rectangles which are drawn under the cursor position
47
+ # * are "picked." Pay special attention to the depth
48
+ # * value range, which is returned.
49
+ # */
50
+
51
+ require "gl_prev"
52
+ require "glu_prev"
53
+ require "glut_prev"
54
+
55
+
56
+ def myinit
57
+ GL::ClearColor(0.0, 0.0, 0.0, 0.0);
58
+ GL::DepthFunc(GL::LESS);
59
+ GL::Enable(GL::DEPTH_TEST);
60
+ GL::ShadeModel(GL::FLAT);
61
+ GL::DepthRange(0.0, 1.0); #/* The default z mapping */
62
+ end
63
+
64
+ #/* The three rectangles are drawn. In selection mode,
65
+ # * each rectangle is given the same name. Note that
66
+ # * each rectangle is drawn with a different z value.
67
+ # */
68
+ def drawRects(mode)
69
+ if (mode == GL::SELECT)
70
+ GL::LoadName(1);
71
+ end
72
+ GL::Begin(GL::QUADS);
73
+ GL::Color(1.0, 1.0, 0.0);
74
+ GL::Vertex(2, 0, 0);
75
+ GL::Vertex(2, 6, 0);
76
+ GL::Vertex(6, 6, 0);
77
+ GL::Vertex(6, 0, 0);
78
+ GL::End();
79
+ if (mode == GL::SELECT)
80
+ GL::LoadName(2);
81
+ end
82
+ GL::Begin(GL::QUADS);
83
+ GL::Color(0.0, 1.0, 1.0);
84
+ GL::Vertex(3, 2, -1);
85
+ GL::Vertex(3, 8, -1);
86
+ GL::Vertex(8, 8, -1);
87
+ GL::Vertex(8, 2, -1);
88
+ GL::End();
89
+ if (mode == GL::SELECT)
90
+ GL::LoadName(3);
91
+ end
92
+ GL::Begin(GL::QUADS);
93
+ GL::Color(1.0, 0.0, 1.0);
94
+ GL::Vertex(0, 2, -2);
95
+ GL::Vertex(0, 7, -2);
96
+ GL::Vertex(5, 7, -2);
97
+ GL::Vertex(5, 2, -2);
98
+ GL::End();
99
+ end
100
+
101
+ #/* processHits() prints out the contents of the
102
+ # * selection array.
103
+ # */
104
+ def processHits(hits, buffer)
105
+ printf("hits = %d\n", hits);
106
+ ptr = buffer.unpack("I*")
107
+ p = 0
108
+ for i in 0...hits #/* for each hit */
109
+ names = ptr[p]
110
+ printf(" number of names for hit = %d\n", names); p+=1;
111
+ printf(" z1 is %g;", ptr[p].to_f/0xffffffff); p+=1;
112
+ printf(" z2 is %g\n", ptr[p].to_f/0xffffffff); p+=1;
113
+ printf(" the name is ");
114
+ for j in 0...names # /* for each name */
115
+ printf("%d ", ptr[p]); p+=1
116
+ end
117
+ printf("\n");
118
+ end
119
+ end
120
+
121
+ #/* pickRects() sets up selection mode, name stack,
122
+ # * and projection matrix for picking. Then the objects
123
+ # * are drawn.
124
+ # */
125
+ BUFSIZE=512
126
+
127
+ pickRects = proc {|button, state, x, y|
128
+
129
+ if (button == GLUT::LEFT_BUTTON && state == GLUT::DOWN)
130
+ viewport = GL::GetDoublev(GL::VIEWPORT);
131
+
132
+ selectBuf = GL::SelectBuffer(BUFSIZE);
133
+ GL::RenderMode(GL::SELECT);
134
+
135
+ GL::InitNames();
136
+ GL::PushName(~0);
137
+
138
+ GL::MatrixMode(GL::PROJECTION);
139
+ GL::PushMatrix();
140
+ GL::LoadIdentity();
141
+ #/* create 5x5 pixel picking region near cursor location */
142
+ GLU::PickMatrix( x, viewport[3] - y, 5.0, 5.0, viewport);
143
+ GL::Ortho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5);
144
+ drawRects(GL::SELECT);
145
+ GL::PopMatrix();
146
+ GL::Flush();
147
+
148
+ hits = GL::RenderMode(GL::RENDER);
149
+ processHits(hits, selectBuf);
150
+ end
151
+ }
152
+
153
+ display = proc {
154
+ GL::Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
155
+ drawRects(GL::RENDER);
156
+ GLUT::SwapBuffers();
157
+ }
158
+
159
+ myReshape = proc {|w, h|
160
+ GL::Viewport(0, 0, w, h);
161
+ GL::MatrixMode(GL::PROJECTION);
162
+ GL::LoadIdentity();
163
+ GL::Ortho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5);
164
+ GL::MatrixMode(GL::MODELVIEW);
165
+ GL::LoadIdentity();
166
+ }
167
+
168
+ #/* Main Loop
169
+ # * Open window with initial window size, title bar,
170
+ # * RGBA display mode, depth buffer, and handle input events.
171
+ # */
172
+ GLUT::InitWindowSize(200, 200);
173
+ GLUT::InitDisplayMode(GLUT::DOUBLE | GLUT::RGB | GLUT::DEPTH);
174
+ GLUT::Init();
175
+ GLUT::CreateWindow();
176
+ myinit();
177
+ GLUT::MouseFunc(pickRects);
178
+ GLUT::ReshapeFunc(myReshape);
179
+ GLUT::DisplayFunc(display);
180
+ GLUT::MainLoop();