ruby-opengl 0.40.1 → 0.50.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/doc/build_install.txt +48 -28
- data/doc/extensions.txt +361 -0
- data/doc/history.txt +8 -2
- data/doc/requirements_and_design.txt +0 -13
- data/doc/roadmap.txt +11 -13
- data/doc/supplies/page_template.html +11 -5
- data/doc/thanks.txt +2 -4
- data/doc/tutorial.txt +1 -4
- data/examples/{nehe_lesson02.rb → NeHe/nehe_lesson02.rb} +0 -0
- data/examples/{nehe_lesson03.rb → NeHe/nehe_lesson03.rb} +0 -0
- data/examples/{nehe_lesson04.rb → NeHe/nehe_lesson04.rb} +0 -0
- data/examples/{nehe_lesson05.rb → NeHe/nehe_lesson05.rb} +0 -0
- data/examples/NeHe/nehe_lesson36.rb +303 -0
- data/examples/OrangeBook/3Dlabs-License.txt +33 -0
- data/examples/OrangeBook/brick.frag +36 -0
- data/examples/OrangeBook/brick.rb +388 -0
- data/examples/OrangeBook/brick.vert +41 -0
- data/examples/OrangeBook/particle.frag +17 -0
- data/examples/OrangeBook/particle.rb +424 -0
- data/examples/OrangeBook/particle.vert +38 -0
- data/examples/README +13 -83
- data/examples/RedBook/aaindex.rb +97 -0
- data/examples/RedBook/aapoly.rb +142 -0
- data/examples/RedBook/aargb.rb +119 -0
- data/examples/RedBook/accanti.rb +162 -0
- data/examples/RedBook/accpersp.rb +215 -0
- data/examples/RedBook/alpha.rb +123 -0
- data/examples/RedBook/alpha3D.rb +158 -0
- data/examples/RedBook/bezcurve.rb +105 -0
- data/examples/RedBook/bezmesh.rb +137 -0
- data/examples/RedBook/checker.rb +124 -0
- data/examples/RedBook/clip.rb +95 -0
- data/examples/RedBook/colormat.rb +135 -0
- data/examples/RedBook/cube.rb +69 -0
- data/examples/RedBook/depthcue.rb +99 -0
- data/examples/RedBook/dof.rb +205 -0
- data/examples/{legacy → RedBook}/double.rb +59 -58
- data/examples/{legacy → RedBook}/drawf.rb +47 -54
- data/examples/RedBook/feedback.rb +145 -0
- data/examples/RedBook/fog.rb +167 -0
- data/examples/RedBook/font.rb +151 -0
- data/examples/RedBook/hello.rb +79 -0
- data/examples/RedBook/image.rb +137 -0
- data/examples/{legacy → RedBook}/jitter.rb +60 -62
- data/examples/RedBook/lines.rb +128 -0
- data/examples/RedBook/list.rb +111 -0
- data/examples/RedBook/material.rb +275 -0
- data/examples/RedBook/mipmap.rb +156 -0
- data/examples/{legacy → RedBook}/model.rb +66 -72
- data/examples/{legacy → RedBook}/movelight.rb +67 -75
- data/examples/RedBook/pickdepth.rb +179 -0
- data/examples/{legacy → RedBook}/planet.rb +62 -66
- data/examples/RedBook/quadric.rb +158 -0
- data/examples/RedBook/robot.rb +115 -0
- data/examples/RedBook/select.rb +196 -0
- data/examples/RedBook/smooth.rb +95 -0
- data/examples/RedBook/stencil.rb +163 -0
- data/examples/RedBook/stroke.rb +167 -0
- data/examples/RedBook/surface.rb +166 -0
- data/examples/RedBook/teaambient.rb +132 -0
- data/examples/RedBook/teapots.rb +182 -0
- data/examples/RedBook/tess.rb +183 -0
- data/examples/RedBook/texbind.rb +147 -0
- data/examples/RedBook/texgen.rb +169 -0
- data/examples/RedBook/texturesurf.rb +128 -0
- data/examples/RedBook/varray.rb +159 -0
- data/examples/RedBook/wrap.rb +148 -0
- data/examples/misc/anisotropic.rb +194 -0
- data/examples/misc/font-glut.rb +46 -0
- data/examples/{plane.rb → misc/plane.rb} +0 -0
- data/examples/misc/readpixel.rb +65 -0
- data/examples/{smooth.rb → misc/smooth.rb} +0 -0
- data/examples/{test.rb → misc/test.rb} +0 -0
- data/ext/common/common.h +252 -70
- data/ext/common/gl-enums.h +6102 -7334
- data/ext/common/gl-types.h +47 -0
- data/ext/common/glu-enums.h +469 -0
- data/ext/gl/gl-1.0-1.1.c +842 -2464
- data/ext/gl/gl-1.2.c +217 -281
- data/ext/gl/gl-1.3.c +113 -133
- data/ext/gl/gl-1.4.c +98 -334
- data/ext/gl/gl-1.5.c +28 -34
- data/ext/gl/gl-2.0.c +26 -235
- data/ext/gl/gl-2.1.c +31 -124
- data/ext/gl/gl-enums.c +786 -631
- data/ext/gl/gl-ext-arb.c +66 -0
- data/ext/gl/gl-ext-ext.c +218 -0
- data/ext/gl/gl.c +138 -31
- data/ext/gl/mkrf_conf.rb +1 -0
- data/ext/glu/glu-enums.c +163 -0
- data/ext/glu/glu.c +1003 -1205
- data/ext/glu/mkrf_conf.rb +1 -0
- data/ext/glut/glut.c +1056 -1175
- data/lib/opengl.rb +90 -3
- data/test/tc_common.rb +26 -13
- data/test/tc_ext_arb.rb +73 -0
- data/test/tc_ext_ext.rb +74 -0
- data/test/tc_func_12.rb +8 -8
- data/test/tc_func_13.rb +17 -11
- data/test/tc_func_14.rb +8 -8
- data/test/tc_func_15.rb +190 -2
- data/test/tc_func_20.rb +36 -10
- data/test/tc_func_21.rb +445 -2
- data/test/tc_glu.rb +305 -0
- data/test/tc_misc.rb +1 -0
- metadata +84 -68
- data/doc/screenshots.txt +0 -23
- data/examples/legacy/COPYRIGHT +0 -8
- data/examples/legacy/aaindex.rb +0 -98
- data/examples/legacy/aapoly.rb +0 -153
- data/examples/legacy/aargb.rb +0 -139
- data/examples/legacy/accanti.rb +0 -159
- data/examples/legacy/accpersp.rb +0 -216
- data/examples/legacy/alpha.rb +0 -133
- data/examples/legacy/alpha3D.rb +0 -165
- data/examples/legacy/bezcurve.rb +0 -107
- data/examples/legacy/bezmesh.rb +0 -131
- data/examples/legacy/checker.rb +0 -121
- data/examples/legacy/clip.rb +0 -104
- data/examples/legacy/colormat.rb +0 -145
- data/examples/legacy/cube.rb +0 -73
- data/examples/legacy/depthcue.rb +0 -101
- data/examples/legacy/dof.rb +0 -212
- data/examples/legacy/feedback.rb +0 -152
- data/examples/legacy/fog.rb +0 -172
- data/examples/legacy/font-glut.rb +0 -41
- data/examples/legacy/font.rb +0 -158
- data/examples/legacy/hello.rb +0 -75
- data/examples/legacy/image.rb +0 -145
- data/examples/legacy/lines.rb +0 -135
- data/examples/legacy/list.rb +0 -120
- data/examples/legacy/material.rb +0 -290
- data/examples/legacy/mipmap.rb +0 -159
- data/examples/legacy/pickdepth.rb +0 -180
- data/examples/legacy/quadric.rb +0 -180
- data/examples/legacy/readpixel.rb +0 -59
- data/examples/legacy/robot.rb +0 -120
- data/examples/legacy/select.rb +0 -207
- data/examples/legacy/smooth.rb +0 -41
- data/examples/legacy/stencil.rb +0 -154
- data/examples/legacy/stroke.rb +0 -170
- data/examples/legacy/surface.rb +0 -170
- data/examples/legacy/teaambient.rb +0 -132
- data/examples/legacy/teapots.rb +0 -188
- data/examples/legacy/tess.rb +0 -222
- data/examples/legacy/texbind.rb +0 -157
- data/examples/legacy/texgen.rb +0 -171
- data/examples/legacy/texturesurf.rb +0 -128
- data/examples/legacy/varray.rb +0 -167
- data/examples/legacy/wrap.rb +0 -158
- data/lib/gl_prev.rb +0 -46
- data/lib/glu_prev.rb +0 -46
- data/lib/glut_prev.rb +0 -45
@@ -0,0 +1,179 @@
|
|
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
|
+
# pickdepth.c
|
41
|
+
# Picking is demonstrated in this program. In
|
42
|
+
# rendering mode, three overlapping rectangles are
|
43
|
+
# drawn. When the left mouse button is pressed,
|
44
|
+
# selection mode is entered with the picking matrix.
|
45
|
+
# Rectangles which are drawn under the cursor position
|
46
|
+
# are "picked." Pay special attention to the depth
|
47
|
+
# value range, which is returned.
|
48
|
+
require 'opengl'
|
49
|
+
include Gl,Glu,Glut
|
50
|
+
|
51
|
+
def myinit
|
52
|
+
glClearColor(0.0, 0.0, 0.0, 0.0)
|
53
|
+
glDepthFunc(GL_LESS)
|
54
|
+
glEnable(GL_DEPTH_TEST)
|
55
|
+
glShadeModel(GL_FLAT)
|
56
|
+
glDepthRange(0.0, 1.0) #/* The default z mapping */
|
57
|
+
end
|
58
|
+
|
59
|
+
# The three rectangles are drawn. In selection mode,
|
60
|
+
# each rectangle is given the same name. Note that
|
61
|
+
# each rectangle is drawn with a different z value.
|
62
|
+
def drawRects(mode)
|
63
|
+
if (mode == GL_SELECT)
|
64
|
+
glLoadName(1)
|
65
|
+
end
|
66
|
+
glBegin(GL_QUADS)
|
67
|
+
glColor(1.0, 1.0, 0.0)
|
68
|
+
glVertex(2, 0, 0)
|
69
|
+
glVertex(2, 6, 0)
|
70
|
+
glVertex(6, 6, 0)
|
71
|
+
glVertex(6, 0, 0)
|
72
|
+
glEnd()
|
73
|
+
if (mode == GL_SELECT)
|
74
|
+
glLoadName(2)
|
75
|
+
end
|
76
|
+
glBegin(GL_QUADS)
|
77
|
+
glColor(0.0, 1.0, 1.0)
|
78
|
+
glVertex(3, 2, -1)
|
79
|
+
glVertex(3, 8, -1)
|
80
|
+
glVertex(8, 8, -1)
|
81
|
+
glVertex(8, 2, -1)
|
82
|
+
glEnd()
|
83
|
+
if (mode == GL_SELECT)
|
84
|
+
glLoadName(3)
|
85
|
+
end
|
86
|
+
glBegin(GL_QUADS)
|
87
|
+
glColor(1.0, 0.0, 1.0)
|
88
|
+
glVertex(0, 2, -2)
|
89
|
+
glVertex(0, 7, -2)
|
90
|
+
glVertex(5, 7, -2)
|
91
|
+
glVertex(5, 2, -2)
|
92
|
+
glEnd()
|
93
|
+
end
|
94
|
+
|
95
|
+
# processHits() prints out the contents of the
|
96
|
+
# selection array.
|
97
|
+
def processHits(hits, buffer)
|
98
|
+
printf("hits = %d\n", hits)
|
99
|
+
ptr = buffer.unpack("I*")
|
100
|
+
p = 0
|
101
|
+
for i in 0...hits # for each hit
|
102
|
+
names = ptr[p]
|
103
|
+
printf(" number of names for hit = %d\n", names); p+=1
|
104
|
+
printf(" z1 is %g", ptr[p].to_f/0xffffffff); p+=1
|
105
|
+
printf(" z2 is %g\n", ptr[p].to_f/0xffffffff); p+=1
|
106
|
+
printf(" the name is ")
|
107
|
+
for j in 0...names # for each name
|
108
|
+
printf("%d ", ptr[p]) ; p+=1
|
109
|
+
end
|
110
|
+
printf("\n")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# pickRects() sets up selection mode, name stack,
|
115
|
+
# and projection matrix for picking. Then the objects
|
116
|
+
# are drawn.
|
117
|
+
BUFSIZE=512
|
118
|
+
|
119
|
+
pickRects = proc do |button, state, x, y|
|
120
|
+
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
|
121
|
+
viewport = glGetDoublev(GL_VIEWPORT)
|
122
|
+
|
123
|
+
selectBuf = glSelectBuffer(BUFSIZE)
|
124
|
+
glRenderMode(GL_SELECT)
|
125
|
+
|
126
|
+
glInitNames()
|
127
|
+
glPushName(~0)
|
128
|
+
|
129
|
+
glMatrixMode(GL_PROJECTION)
|
130
|
+
glPushMatrix()
|
131
|
+
glLoadIdentity()
|
132
|
+
# create 5x5 pixel picking region near cursor location
|
133
|
+
gluPickMatrix( x, viewport[3] - y, 5.0, 5.0, viewport)
|
134
|
+
glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5)
|
135
|
+
drawRects(GL_SELECT)
|
136
|
+
glPopMatrix()
|
137
|
+
glFlush()
|
138
|
+
|
139
|
+
hits = glRenderMode(GL_RENDER)
|
140
|
+
processHits(hits, selectBuf)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
display = proc do
|
145
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
146
|
+
drawRects(GL_RENDER)
|
147
|
+
glutSwapBuffers()
|
148
|
+
end
|
149
|
+
|
150
|
+
myReshape = proc do |w, h|
|
151
|
+
glViewport(0, 0, w, h)
|
152
|
+
glMatrixMode(GL_PROJECTION)
|
153
|
+
glLoadIdentity()
|
154
|
+
glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5)
|
155
|
+
glMatrixMode(GL_MODELVIEW)
|
156
|
+
glLoadIdentity()
|
157
|
+
end
|
158
|
+
|
159
|
+
keyboard = Proc.new do |key, x, y|
|
160
|
+
case (key)
|
161
|
+
when 27
|
162
|
+
exit(0)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Main Loop
|
167
|
+
# Open window with initial window size, title bar,
|
168
|
+
# RGBA display mode, depth buffer, and handle input events.
|
169
|
+
glutInitWindowSize(500, 500)
|
170
|
+
glutInitWindowPosition(100, 100)
|
171
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
|
172
|
+
glutInit()
|
173
|
+
glutCreateWindow()
|
174
|
+
myinit()
|
175
|
+
glutMouseFunc(pickRects)
|
176
|
+
glutReshapeFunc(myReshape)
|
177
|
+
glutDisplayFunc(display)
|
178
|
+
glutKeyboardFunc(keyboard)
|
179
|
+
glutMainLoop()
|
@@ -33,80 +33,76 @@
|
|
33
33
|
# Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
|
34
34
|
#
|
35
35
|
# OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
|
36
|
-
#/
|
37
|
-
|
38
36
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
|
45
|
-
require
|
46
|
-
|
47
|
-
require "glut_prev"
|
48
|
-
require "rational"
|
37
|
+
# planet.c
|
38
|
+
# This program shows how to composite modeling transformations
|
39
|
+
# to draw translated and rotated models.
|
40
|
+
# Interaction: pressing the d and y keys (day and year)
|
41
|
+
# alters the rotation of the planet around the sun.
|
42
|
+
require 'opengl'
|
43
|
+
require 'rational'
|
44
|
+
include Gl,Glu,Glut
|
49
45
|
|
50
46
|
STDOUT.sync = TRUE
|
51
47
|
|
52
|
-
$year = 0
|
48
|
+
$year = 0
|
49
|
+
$day = 0
|
53
50
|
|
54
51
|
def init
|
55
|
-
|
56
|
-
|
52
|
+
glClearColor(0.0, 0.0, 0.0, 0.0)
|
53
|
+
glShadeModel(GL_FLAT)
|
57
54
|
end
|
58
55
|
|
59
|
-
display = Proc.new
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
56
|
+
display = Proc.new do
|
57
|
+
glClear(GL_COLOR_BUFFER_BIT)
|
58
|
+
glColor(1.0, 1.0, 1.0)
|
59
|
+
|
60
|
+
glPushMatrix()
|
61
|
+
glutWireSphere(1.0, 20, 16) # draw sun
|
62
|
+
glRotate($year, 0.0, 1.0, 0.0)
|
63
|
+
glTranslate(2.0, 0.0, 0.0)
|
64
|
+
glRotate($day, 0.0, 1.0, 0.0)
|
65
|
+
glutWireSphere(0.2, 10, 8) # draw smaller planet
|
66
|
+
glPopMatrix()
|
67
|
+
glutSwapBuffers()
|
68
|
+
end
|
72
69
|
|
73
|
-
reshape = Proc.new
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
70
|
+
reshape = Proc.new do |w, h|
|
71
|
+
glViewport(0, 0, w, h)
|
72
|
+
glMatrixMode(GL_PROJECTION)
|
73
|
+
glLoadIdentity()
|
74
|
+
gluPerspective(60.0, w.to_f/h.to_f, 1.0, 20.0)
|
75
|
+
glMatrixMode(GL_MODELVIEW)
|
76
|
+
glLoadIdentity()
|
77
|
+
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
|
78
|
+
end
|
82
79
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
}
|
80
|
+
keyboard = Proc.new do |key, x, y|
|
81
|
+
case (key)
|
82
|
+
when 'd'[0]
|
83
|
+
$day = ($day + 10) % 360
|
84
|
+
glutPostRedisplay()
|
85
|
+
when 'D'[0]
|
86
|
+
$day = ($day - 10) % 360
|
87
|
+
glutPostRedisplay()
|
88
|
+
when 'y'[0]
|
89
|
+
$year = ($year + 5) % 360
|
90
|
+
glutPostRedisplay()
|
91
|
+
when 'Y'[0]
|
92
|
+
$year = ($year - 5) % 360
|
93
|
+
glutPostRedisplay()
|
94
|
+
when 27
|
95
|
+
exit(0)
|
96
|
+
end
|
97
|
+
end
|
102
98
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
99
|
+
glutInit
|
100
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
|
101
|
+
glutInitWindowSize(500, 500)
|
102
|
+
glutInitWindowPosition(100, 100)
|
103
|
+
glutCreateWindow($0)
|
104
|
+
init()
|
105
|
+
glutDisplayFunc(display)
|
106
|
+
glutReshapeFunc(reshape)
|
107
|
+
glutKeyboardFunc(keyboard)
|
108
|
+
glutMainLoop()
|
@@ -0,0 +1,158 @@
|
|
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
|
+
# quadric.c
|
38
|
+
# This program demonstrates the use of some of the gluQuadric*
|
39
|
+
# routines. Quadric objects are created with some quadric
|
40
|
+
# properties and the callback routine to handle errors.
|
41
|
+
# Note that the cylinder has no top or bottom and the circle
|
42
|
+
# has a hole in it.
|
43
|
+
require 'opengl'
|
44
|
+
require 'mathn'
|
45
|
+
include Gl,Glu,Glut
|
46
|
+
|
47
|
+
$startList = nil
|
48
|
+
|
49
|
+
def init
|
50
|
+
mat_ambient = [ 0.5, 0.5, 0.5, 1.0 ]
|
51
|
+
mat_specular = [ 1.0, 1.0, 1.0, 1.0 ]
|
52
|
+
mat_shininess = [ 50.0 ]
|
53
|
+
light_position = [ 1.0, 1.0, 1.0, 0.0 ]
|
54
|
+
model_ambient = [ 0.5, 0.5, 0.5, 1.0 ]
|
55
|
+
|
56
|
+
glClearColor(0.0, 0.0, 0.0, 0.0)
|
57
|
+
|
58
|
+
glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient)
|
59
|
+
glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
|
60
|
+
glMaterial(GL_FRONT, GL_SHININESS, mat_shininess)
|
61
|
+
glLight(GL_LIGHT0, GL_POSITION, light_position)
|
62
|
+
glLightModel(GL_LIGHT_MODEL_AMBIENT, model_ambient)
|
63
|
+
|
64
|
+
glEnable(GL_LIGHTING)
|
65
|
+
glEnable(GL_LIGHT0)
|
66
|
+
glEnable(GL_DEPTH_TEST)
|
67
|
+
|
68
|
+
# Create 4 display lists, each with a different quadric object.
|
69
|
+
# Different drawing styles and surface normal specifications
|
70
|
+
# are demonstrated.
|
71
|
+
$startList = glGenLists(4)
|
72
|
+
qobj = gluNewQuadric()
|
73
|
+
|
74
|
+
gluQuadricDrawStyle(qobj, GLU_FILL) # smooth shaded
|
75
|
+
gluQuadricNormals(qobj, GLU_SMOOTH)
|
76
|
+
glNewList($startList, GL_COMPILE)
|
77
|
+
gluSphere(qobj, 0.75, 15, 10)
|
78
|
+
glEndList()
|
79
|
+
|
80
|
+
gluQuadricDrawStyle(qobj, GLU_FILL) # flat shaded
|
81
|
+
gluQuadricNormals(qobj, GLU_FLAT)
|
82
|
+
glNewList($startList+1, GL_COMPILE)
|
83
|
+
gluCylinder(qobj, 0.5, 0.3, 1.0, 15, 5)
|
84
|
+
glEndList()
|
85
|
+
|
86
|
+
gluQuadricDrawStyle(qobj, GLU_LINE) # all polygons wireframe
|
87
|
+
gluQuadricNormals(qobj, GLU_NONE)
|
88
|
+
glNewList($startList+2, GL_COMPILE)
|
89
|
+
gluDisk(qobj, 0.25, 1.0, 20, 4)
|
90
|
+
glEndList()
|
91
|
+
|
92
|
+
gluQuadricDrawStyle(qobj, GLU_SILHOUETTE) # boundary only
|
93
|
+
gluQuadricNormals(qobj, GLU_NONE)
|
94
|
+
glNewList($startList+3, GL_COMPILE)
|
95
|
+
gluPartialDisk(qobj, 0.0, 1.0, 20, 4, 0.0, 225.0)
|
96
|
+
glEndList()
|
97
|
+
end
|
98
|
+
|
99
|
+
display = Proc.new do
|
100
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
101
|
+
glPushMatrix()
|
102
|
+
|
103
|
+
glEnable(GL_LIGHTING)
|
104
|
+
glShadeModel(GL_SMOOTH)
|
105
|
+
glTranslate(-1.0, -1.0, 0.0)
|
106
|
+
glCallList($startList)
|
107
|
+
|
108
|
+
glShadeModel(GL_FLAT)
|
109
|
+
glTranslate(0.0, 2.0, 0.0)
|
110
|
+
glPushMatrix()
|
111
|
+
glRotate(300.0, 1.0, 0.0, 0.0)
|
112
|
+
glCallList($startList+1)
|
113
|
+
glPopMatrix()
|
114
|
+
|
115
|
+
glDisable(GL_LIGHTING)
|
116
|
+
glColor(0.0, 1.0, 1.0)
|
117
|
+
glTranslate(2.0, -2.0, 0.0)
|
118
|
+
glCallList($startList+2)
|
119
|
+
|
120
|
+
glColor(1.0, 1.0, 0.0)
|
121
|
+
glTranslate(0.0, 2.0, 0.0)
|
122
|
+
glCallList($startList+3)
|
123
|
+
|
124
|
+
glPopMatrix()
|
125
|
+
glutSwapBuffers()
|
126
|
+
end
|
127
|
+
|
128
|
+
reshape = Proc.new do |w, h|
|
129
|
+
glViewport(0, 0, w, h)
|
130
|
+
glMatrixMode(GL_PROJECTION)
|
131
|
+
glLoadIdentity()
|
132
|
+
if (w <= h)
|
133
|
+
glOrtho(-2.5, 2.5, -2.5*h/w, 2.5*h/w, -10.0, 10.0)
|
134
|
+
else
|
135
|
+
glOrtho(-2.5*w/h, 2.5*w/h, -2.5, 2.5, -10.0, 10.0)
|
136
|
+
end
|
137
|
+
glMatrixMode(GL_MODELVIEW)
|
138
|
+
glLoadIdentity()
|
139
|
+
end
|
140
|
+
|
141
|
+
keyboard = Proc.new do |key, x, y|
|
142
|
+
case (key)
|
143
|
+
when 27
|
144
|
+
exit(0)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# main
|
149
|
+
glutInit
|
150
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
|
151
|
+
glutInitWindowSize(500, 500)
|
152
|
+
glutInitWindowPosition(100, 100)
|
153
|
+
glutCreateWindow($0)
|
154
|
+
init()
|
155
|
+
glutDisplayFunc(display)
|
156
|
+
glutReshapeFunc(reshape)
|
157
|
+
glutKeyboardFunc(keyboard)
|
158
|
+
glutMainLoop()
|