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
@@ -0,0 +1,182 @@
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
+ # teapots.c
40
+ # This program demonstrates lots of material properties.
41
+ # A single light source illuminates the objects.
42
+ require 'opengl'
43
+ include Gl,Glu,Glut
44
+
45
+ # Initialize depth buffer, projection matrix, light source, and lighting
46
+ # model. Do not specify a material property here.
47
+ def myinit
48
+ ambient = [0.0, 0.0, 0.0, 1.0]
49
+ diffuse = [1.0, 1.0, 1.0, 1.0]
50
+ position = [0.0, 3.0, 3.0, 0.0]
51
+
52
+ lmodel_ambient = [0.2, 0.2, 0.2, 1.0]
53
+ local_view = [0.0]
54
+
55
+ glLight(GL_LIGHT0, GL_AMBIENT, ambient)
56
+ glLight(GL_LIGHT0, GL_DIFFUSE, diffuse)
57
+ glLight(GL_LIGHT0, GL_POSITION, position)
58
+ glLightModel(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient)
59
+ glLightModel(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view)
60
+
61
+ glFrontFace(GL_CW)
62
+ glEnable(GL_LIGHTING)
63
+ glEnable(GL_LIGHT0)
64
+ glEnable(GL_AUTO_NORMAL)
65
+ glEnable(GL_NORMALIZE)
66
+ glEnable(GL_DEPTH_TEST)
67
+ glDepthFunc(GL_LESS)
68
+ end
69
+
70
+ # Move object into position. Use 3rd through 12th parameters to specify the
71
+ # material property. Draw a teapot.
72
+ def renderTeapot(x, y, ambr, ambg, ambb, difr, difg, difb, specr, specg, specb, shine)
73
+ mat = []
74
+ glPushMatrix()
75
+ glTranslate(x, y, 0.0)
76
+ mat[0] = ambr
77
+ mat[1] = ambg
78
+ mat[2] = ambb
79
+ mat[3] = 1.0
80
+ glMaterial(GL_FRONT, GL_AMBIENT, mat)
81
+ mat[0] = difr
82
+ mat[1] = difg
83
+ mat[2] = difb
84
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat)
85
+ mat[0] = specr
86
+ mat[1] = specg
87
+ mat[2] = specb
88
+ glMaterial(GL_FRONT, GL_SPECULAR, mat)
89
+ glMaterial(GL_FRONT, GL_SHININESS, shine * 128.0)
90
+ glutSolidTeapot(1.0)
91
+ glPopMatrix()
92
+ end
93
+
94
+ # First column: emerald, jade, obsidian, pearl, ruby, turquoise
95
+ # 2nd column: brass, bronze, chrome, copper, gold, silver
96
+ # 3rd column: black, cyan, green, red, white, yellow plastic
97
+ # 4th column: black, cyan, green, red, white, yellow rubber
98
+ display = proc do
99
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
100
+ renderTeapot(2.0, 17.0, 0.0215, 0.1745, 0.0215,
101
+ 0.07568, 0.61424, 0.07568, 0.633, 0.727811, 0.633, 0.6)
102
+ renderTeapot(2.0, 14.0, 0.135, 0.2225, 0.1575,
103
+ 0.54, 0.89, 0.63, 0.316228, 0.316228, 0.316228, 0.1)
104
+ renderTeapot(2.0, 11.0, 0.05375, 0.05, 0.06625,
105
+ 0.18275, 0.17, 0.22525, 0.332741, 0.328634, 0.346435, 0.3)
106
+ renderTeapot(2.0, 8.0, 0.25, 0.20725, 0.20725,
107
+ 1, 0.829, 0.829, 0.296648, 0.296648, 0.296648, 0.088)
108
+ renderTeapot(2.0, 5.0, 0.1745, 0.01175, 0.01175,
109
+ 0.61424, 0.04136, 0.04136, 0.727811, 0.626959, 0.626959, 0.6)
110
+ renderTeapot(2.0, 2.0, 0.1, 0.18725, 0.1745,
111
+ 0.396, 0.74151, 0.69102, 0.297254, 0.30829, 0.306678, 0.1)
112
+ renderTeapot(6.0, 17.0, 0.329412, 0.223529, 0.027451,
113
+ 0.780392, 0.568627, 0.113725, 0.992157, 0.941176, 0.807843,
114
+ 0.21794872)
115
+ renderTeapot(6.0, 14.0, 0.2125, 0.1275, 0.054,
116
+ 0.714, 0.4284, 0.18144, 0.393548, 0.271906, 0.166721, 0.2)
117
+ renderTeapot(6.0, 11.0, 0.25, 0.25, 0.25,
118
+ 0.4, 0.4, 0.4, 0.774597, 0.774597, 0.774597, 0.6)
119
+ renderTeapot(6.0, 8.0, 0.19125, 0.0735, 0.0225,
120
+ 0.7038, 0.27048, 0.0828, 0.256777, 0.137622, 0.086014, 0.1)
121
+ renderTeapot(6.0, 5.0, 0.24725, 0.1995, 0.0745,
122
+ 0.75164, 0.60648, 0.22648, 0.628281, 0.555802, 0.366065, 0.4)
123
+ renderTeapot(6.0, 2.0, 0.19225, 0.19225, 0.19225,
124
+ 0.50754, 0.50754, 0.50754, 0.508273, 0.508273, 0.508273, 0.4)
125
+ renderTeapot(10.0, 17.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.01,
126
+ 0.50, 0.50, 0.50, 0.25)
127
+ renderTeapot(10.0, 14.0, 0.0, 0.1, 0.06, 0.0, 0.50980392, 0.50980392,
128
+ 0.50196078, 0.50196078, 0.50196078, 0.25)
129
+ renderTeapot(10.0, 11.0, 0.0, 0.0, 0.0,
130
+ 0.1, 0.35, 0.1, 0.45, 0.55, 0.45, 0.25)
131
+ renderTeapot(10.0, 8.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0,
132
+ 0.7, 0.6, 0.6, 0.25)
133
+ renderTeapot(10.0, 5.0, 0.0, 0.0, 0.0, 0.55, 0.55, 0.55,
134
+ 0.70, 0.70, 0.70, 0.25)
135
+ renderTeapot(10.0, 2.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.0,
136
+ 0.60, 0.60, 0.50, 0.25)
137
+ renderTeapot(14.0, 17.0, 0.02, 0.02, 0.02, 0.01, 0.01, 0.01,
138
+ 0.4, 0.4, 0.4, 0.078125)
139
+ renderTeapot(14.0, 14.0, 0.0, 0.05, 0.05, 0.4, 0.5, 0.5,
140
+ 0.04, 0.7, 0.7, 0.078125)
141
+ renderTeapot(14.0, 11.0, 0.0, 0.05, 0.0, 0.4, 0.5, 0.4,
142
+ 0.04, 0.7, 0.04, 0.078125)
143
+ renderTeapot(14.0, 8.0, 0.05, 0.0, 0.0, 0.5, 0.4, 0.4,
144
+ 0.7, 0.04, 0.04, 0.078125)
145
+ renderTeapot(14.0, 5.0, 0.05, 0.05, 0.05, 0.5, 0.5, 0.5,
146
+ 0.7, 0.7, 0.7, 0.078125)
147
+ renderTeapot(14.0, 2.0, 0.05, 0.05, 0.0, 0.5, 0.5, 0.4,
148
+ 0.7, 0.7, 0.04, 0.078125)
149
+ glutSwapBuffers()
150
+ end
151
+
152
+ myReshape = proc do |w, h|
153
+ glViewport(0, 0, w, h)
154
+ glMatrixMode(GL_PROJECTION)
155
+ glLoadIdentity()
156
+ if (w <= h)
157
+ glOrtho(0.0, 16.0, 0.0, 16.0 * h.to_f / w, -10.0, 10.0)
158
+ else
159
+ glOrtho(0.0, 16.0 * w.to_f / h, 0.0, 16.0,-10.0, 10.0)
160
+ end
161
+ glMatrixMode(GL_MODELVIEW)
162
+ end
163
+
164
+ keyboard = Proc.new do |key, x, y|
165
+ case (key)
166
+ when 27
167
+ exit(0);
168
+ end
169
+ end
170
+
171
+ # Main Loop Open window with initial window size, title bar, RGBA display
172
+ # mode, and handle input events.
173
+ glutInit()
174
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
175
+ glutInitWindowSize(500, 500)
176
+ glutInitWindowPosition(100, 100)
177
+ glutCreateWindow()
178
+ myinit()
179
+ glutReshapeFunc(myReshape)
180
+ glutDisplayFunc(display)
181
+ glutKeyboardFunc(keyboard)
182
+ glutMainLoop()
@@ -0,0 +1,183 @@
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
+ # tess.c
38
+ # This program demonstrates polygon tessellation.
39
+ # Two tesselated objects are drawn. The first is a
40
+ # rectangle with a triangular hole. The second is a
41
+ # smooth shaded, self-intersecting star.
42
+ #
43
+ # Note the exterior rectangle is drawn with its vertices
44
+ # in counter-clockwise order, but its interior clockwise.
45
+ # Note the combineCallback is needed for the self-intersecting
46
+ # star. Also note that removing the TessProperty for the
47
+ # star will make the interior unshaded (WINDING_ODD).
48
+ require 'opengl'
49
+ include Gl,Glu,Glut
50
+
51
+ $startList = nil
52
+
53
+ display = proc do
54
+ glClear(GL_COLOR_BUFFER_BIT)
55
+ glColor(1.0, 1.0, 1.0)
56
+ glCallList($startList)
57
+ glCallList($startList + 1)
58
+ glutSwapBuffers()
59
+ end
60
+
61
+ $beginCallback = proc do |which|
62
+ glBegin(which)
63
+ end
64
+
65
+ $errorCallback = proc do |errorCode|
66
+ print "Tessellation Error: #{gluErrorString(errorCode)}"
67
+ exit(0)
68
+ end
69
+
70
+ $endCallback = proc do
71
+ glEnd()
72
+ end
73
+
74
+ $vertexCallback = proc do |vertex|
75
+ glColor(vertex[3], vertex[4], vertex[5])
76
+ glVertex(vertex[0], vertex[1], vertex[2])
77
+ end
78
+
79
+ # combineCallback is used to create a new vertex when edges
80
+ # intersect. coordinate location is trivial to calculate,
81
+ # but weight[4] may be used to average color, normal, or texture
82
+ # coordinate data. In this program, color is weighted.
83
+ $combineCallback = proc do |coords, vertex_data, weight|
84
+ vertex = []
85
+ vertex[0] = coords[0]
86
+ vertex[1] = coords[1]
87
+ vertex[2] = coords[2]
88
+ for i in 3...6
89
+ vertex[i] = weight[0] * vertex_data[0][i] + weight[1] * vertex_data[1][i] + weight[2] * vertex_data[2][i] + weight[3] * vertex_data[3][i]
90
+ end
91
+ vertex
92
+ end
93
+
94
+ def init
95
+ rect = [[50.0, 50.0, 0.0],
96
+ [200.0, 50.0, 0.0],
97
+ [200.0, 200.0, 0.0],
98
+ [50.0, 200.0, 0.0]]
99
+ tri = [[75.0, 75.0, 0.0],
100
+ [125.0, 175.0, 0.0],
101
+ [175.0, 75.0, 0.0]]
102
+ star= [[250.0, 50.0, 0.0, 1.0, 0.0, 1.0],
103
+ [325.0, 200.0, 0.0, 1.0, 1.0, 0.0],
104
+ [400.0, 50.0, 0.0, 0.0, 1.0, 1.0],
105
+ [250.0, 150.0, 0.0, 1.0, 0.0, 0.0],
106
+ [400.0, 150.0, 0.0, 0.0, 1.0, 0.0]]
107
+
108
+ glClearColor(0.0, 0.0, 0.0, 0.0)
109
+
110
+ $startList = glGenLists(2)
111
+
112
+ tobj = gluNewTess()
113
+ gluTessCallback(tobj, GLU_TESS_VERTEX, proc do |v| glVertex(v) end )
114
+ gluTessCallback(tobj, GLU_TESS_BEGIN, $beginCallback)
115
+ gluTessCallback(tobj, GLU_TESS_END, $endCallback)
116
+ gluTessCallback(tobj, GLU_TESS_ERROR, $errorCallback)
117
+
118
+ # rectangle with triangular hole inside
119
+ glNewList($startList, GL_COMPILE)
120
+ glShadeModel(GL_FLAT)
121
+ gluTessBeginPolygon(tobj, nil)
122
+ gluTessBeginContour(tobj)
123
+ gluTessVertex(tobj, rect[0], rect[0])
124
+ gluTessVertex(tobj, rect[1], rect[1])
125
+ gluTessVertex(tobj, rect[2], rect[2])
126
+ gluTessVertex(tobj, rect[3], rect[3])
127
+ gluTessEndContour(tobj)
128
+ gluTessBeginContour(tobj)
129
+ gluTessVertex(tobj, tri[0], tri[0])
130
+ gluTessVertex(tobj, tri[1], tri[1])
131
+ gluTessVertex(tobj, tri[2], tri[2])
132
+ gluTessEndContour(tobj)
133
+ gluTessEndPolygon(tobj)
134
+ glEndList()
135
+
136
+ gluTessCallback(tobj, GLU_TESS_VERTEX, $vertexCallback)
137
+ gluTessCallback(tobj, GLU_TESS_BEGIN, $beginCallback)
138
+ gluTessCallback(tobj, GLU_TESS_END, $endCallback)
139
+ gluTessCallback(tobj, GLU_TESS_ERROR, $errorCallback)
140
+ gluTessCallback(tobj, GLU_TESS_COMBINE, $combineCallback)
141
+
142
+
143
+ # smooth shaded, self-intersecting star
144
+ glNewList($startList + 1, GL_COMPILE)
145
+ glShadeModel(GL_SMOOTH)
146
+ gluTessProperty(tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE)
147
+ gluTessBeginPolygon(tobj, nil)
148
+ gluTessBeginContour(tobj)
149
+ gluTessVertex(tobj, star[0], star[0])
150
+ gluTessVertex(tobj, star[1], star[1])
151
+ gluTessVertex(tobj, star[2], star[2])
152
+ gluTessVertex(tobj, star[3], star[3])
153
+ gluTessVertex(tobj, star[4], star[4])
154
+ gluTessEndContour(tobj)
155
+ gluTessEndPolygon(tobj)
156
+ glEndList()
157
+ gluDeleteTess(tobj)
158
+ end
159
+
160
+ reshape = proc do |w, h|
161
+ glViewport(0, 0, w, h)
162
+ glMatrixMode(GL_PROJECTION)
163
+ glLoadIdentity()
164
+ gluOrtho2D(0.0, w, 0.0, h)
165
+ end
166
+
167
+ keyboard = proc do |key, x, y|
168
+ case (key)
169
+ when 27
170
+ exit(0)
171
+ end
172
+ end
173
+
174
+ glutInit()
175
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
176
+ glutInitWindowSize(500, 500)
177
+ glutInitWindowPosition(100, 100)
178
+ glutCreateWindow()
179
+ init()
180
+ glutDisplayFunc(display)
181
+ glutReshapeFunc(reshape)
182
+ glutKeyboardFunc(keyboard)
183
+ glutMainLoop()
@@ -0,0 +1,147 @@
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
+ # texbind.c
39
+ # This program demonstrates using glBindTexture() by
40
+ # creating and managing two textures.
41
+ require 'opengl'
42
+ require 'mathn'
43
+ include Gl,Glu,Glut
44
+
45
+ CheckImageWidth = 64
46
+ CheckImageHeight = 64
47
+ $checkImage = []
48
+ $otherImage = []
49
+
50
+ $texName = []
51
+
52
+ def makeCheckImages
53
+ for i in (0..CheckImageHeight-1)
54
+ for j in (0..CheckImageWidth-1)
55
+ if ((i&0x8==0)!=(j&0x8==0)) then tmp = 1 else tmp=0 end
56
+ #c = ((((i&0x8)==0)^((j&0x8))==0))*255
57
+ c = tmp * 255
58
+ $checkImage[i*CheckImageWidth*4+j*4+0] = c
59
+ $checkImage[i*CheckImageWidth*4+j*4+1] = c
60
+ $checkImage[i*CheckImageWidth*4+j*4+2] = c
61
+ $checkImage[i*CheckImageWidth*4+j*4+3] = 255
62
+ #c = ((((i&0x10)==0)^((j&0x10))==0))*255
63
+ if ((i&0x10==0)!=(j&0x10==0)) then tmp = 1 else tmp=0 end
64
+ c = tmp * 255
65
+ $otherImage[i*CheckImageWidth*4+j*4+0] = c
66
+ $otherImage[i*CheckImageWidth*4+j*4+1] = 0
67
+ $otherImage[i*CheckImageWidth*4+j*4+2] = 0
68
+ $otherImage[i*CheckImageWidth*4+j*4+3] = 255
69
+ end
70
+ end
71
+ end
72
+
73
+ def init
74
+ glClearColor(0.0, 0.0, 0.0, 0.0)
75
+ glShadeModel(GL_FLAT)
76
+ glEnable(GL_DEPTH_TEST)
77
+
78
+ makeCheckImages()
79
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
80
+
81
+ $texName = glGenTextures(2)
82
+ glBindTexture(GL_TEXTURE_2D, $texName[0])
83
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
84
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
85
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST)
86
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST)
87
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, CheckImageWidth,
88
+ CheckImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, $checkImage.pack("C*"))
89
+
90
+ glBindTexture(GL_TEXTURE_2D, $texName[1])
91
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
92
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
93
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
94
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
95
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
96
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, CheckImageWidth, CheckImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
97
+ $otherImage.pack("C*"))
98
+ glEnable(GL_TEXTURE_2D)
99
+ end
100
+
101
+ display = Proc.new do
102
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
103
+ glBindTexture(GL_TEXTURE_2D, $texName[0])
104
+ glBegin(GL_QUADS)
105
+ glTexCoord(0.0, 0.0); glVertex(-2.0, -1.0, 0.0)
106
+ glTexCoord(0.0, 1.0); glVertex(-2.0, 1.0, 0.0)
107
+ glTexCoord(1.0, 1.0); glVertex(0.0, 1.0, 0.0)
108
+ glTexCoord(1.0, 0.0); glVertex(0.0, -1.0, 0.0)
109
+ glEnd()
110
+ glBindTexture(GL_TEXTURE_2D, $texName[1])
111
+ glBegin(GL_QUADS)
112
+ glTexCoord(0.0, 0.0); glVertex(1.0, -1.0, 0.0)
113
+ glTexCoord(0.0, 1.0); glVertex(1.0, 1.0, 0.0)
114
+ glTexCoord(1.0, 1.0); glVertex(2.41421, 1.0, -1.41421)
115
+ glTexCoord(1.0, 0.0); glVertex(2.41421, -1.0, -1.41421)
116
+ glEnd()
117
+ glutSwapBuffers()
118
+ end
119
+
120
+ reshape = Proc.new do |w, h|
121
+ glViewport(0, 0, w, h)
122
+ glMatrixMode(GL_PROJECTION)
123
+ glLoadIdentity()
124
+ gluPerspective(60.0, w/h, 1.0, 30.0)
125
+ glMatrixMode(GL_MODELVIEW)
126
+ glLoadIdentity()
127
+ glTranslate(0.0, 0.0, -3.6)
128
+ end
129
+
130
+ keyboard = Proc.new do |key, x, y|
131
+ case (key)
132
+ when 27
133
+ exit(0)
134
+ end
135
+ end
136
+
137
+ # main
138
+ glutInit
139
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
140
+ glutInitWindowSize(500, 500)
141
+ glutInitWindowPosition(100, 100)
142
+ glutCreateWindow($0)
143
+ init()
144
+ glutReshapeFunc(reshape)
145
+ glutDisplayFunc(display)
146
+ glutKeyboardFunc(keyboard)
147
+ glutMainLoop()