danabr75-opengl 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.autotest +29 -0
- data/.gemtest +0 -0
- data/.gitignore +6 -0
- data/.travis.yml +19 -0
- data/Gemfile +8 -0
- data/History.md +101 -0
- data/MIT-LICENSE +18 -0
- data/Manifest.txt +142 -0
- data/README.rdoc +105 -0
- data/Rakefile +170 -0
- data/danabr75-opengl.gemspec +32 -0
- data/examples/NeHe/NeHe.png +0 -0
- data/examples/NeHe/crate.png +0 -0
- data/examples/NeHe/glass.png +0 -0
- data/examples/NeHe/nehe_lesson02.rb +117 -0
- data/examples/NeHe/nehe_lesson03.rb +123 -0
- data/examples/NeHe/nehe_lesson04.rb +132 -0
- data/examples/NeHe/nehe_lesson05.rb +182 -0
- data/examples/NeHe/nehe_lesson06.rb +186 -0
- data/examples/NeHe/nehe_lesson07.rb +240 -0
- data/examples/NeHe/nehe_lesson08.rb +255 -0
- data/examples/NeHe/nehe_lesson09.rb +203 -0
- data/examples/NeHe/nehe_lesson11.rb +176 -0
- data/examples/NeHe/nehe_lesson12.rb +203 -0
- data/examples/NeHe/nehe_lesson16.rb +211 -0
- data/examples/NeHe/nehe_lesson19.rb +209 -0
- data/examples/NeHe/nehe_lesson36.rb +308 -0
- data/examples/NeHe/particle.png +0 -0
- data/examples/NeHe/star.png +0 -0
- data/examples/NeHe/tim.png +0 -0
- data/examples/OrangeBook/3Dlabs-License.txt +33 -0
- data/examples/OrangeBook/brick.frag +36 -0
- data/examples/OrangeBook/brick.rb +378 -0
- data/examples/OrangeBook/brick.vert +41 -0
- data/examples/OrangeBook/particle.frag +17 -0
- data/examples/OrangeBook/particle.rb +408 -0
- data/examples/OrangeBook/particle.vert +38 -0
- data/examples/README +16 -0
- data/examples/RedBook/aapoly.rb +143 -0
- data/examples/RedBook/aargb.rb +121 -0
- data/examples/RedBook/accanti.rb +164 -0
- data/examples/RedBook/accpersp.rb +217 -0
- data/examples/RedBook/alpha.rb +125 -0
- data/examples/RedBook/alpha3D.rb +160 -0
- data/examples/RedBook/bezcurve.rb +107 -0
- data/examples/RedBook/bezmesh.rb +139 -0
- data/examples/RedBook/checker.rb +126 -0
- data/examples/RedBook/clip.rb +97 -0
- data/examples/RedBook/colormat.rb +137 -0
- data/examples/RedBook/cube.rb +71 -0
- data/examples/RedBook/depthcue.rb +101 -0
- data/examples/RedBook/dof.rb +206 -0
- data/examples/RedBook/double.rb +107 -0
- data/examples/RedBook/drawf.rb +93 -0
- data/examples/RedBook/feedback.rb +147 -0
- data/examples/RedBook/fog.rb +168 -0
- data/examples/RedBook/font.rb +153 -0
- data/examples/RedBook/hello.rb +81 -0
- data/examples/RedBook/image.rb +139 -0
- data/examples/RedBook/jitter.rb +207 -0
- data/examples/RedBook/light.rb +157 -0
- data/examples/RedBook/lines.rb +130 -0
- data/examples/RedBook/list.rb +113 -0
- data/examples/RedBook/material.rb +276 -0
- data/examples/RedBook/mipmap.rb +158 -0
- data/examples/RedBook/model.rb +115 -0
- data/examples/RedBook/movelight.rb +134 -0
- data/examples/RedBook/pickdepth.rb +181 -0
- data/examples/RedBook/planet.rb +110 -0
- data/examples/RedBook/quadric.rb +160 -0
- data/examples/RedBook/robot.rb +117 -0
- data/examples/RedBook/select.rb +198 -0
- data/examples/RedBook/smooth.rb +97 -0
- data/examples/RedBook/stencil.rb +165 -0
- data/examples/RedBook/stroke.rb +169 -0
- data/examples/RedBook/surface.rb +168 -0
- data/examples/RedBook/teaambient.rb +134 -0
- data/examples/RedBook/teapots.rb +184 -0
- data/examples/RedBook/tess.rb +185 -0
- data/examples/RedBook/texbind.rb +149 -0
- data/examples/RedBook/texgen.rb +171 -0
- data/examples/RedBook/texturesurf.rb +130 -0
- data/examples/RedBook/varray.rb +161 -0
- data/examples/RedBook/wrap.rb +150 -0
- data/examples/misc/OGLBench.rb +338 -0
- data/examples/misc/anisotropic.rb +196 -0
- data/examples/misc/fbo_test.rb +357 -0
- data/examples/misc/font-glut.rb +47 -0
- data/examples/misc/glfwtest.rb +30 -0
- data/examples/misc/plane.rb +161 -0
- data/examples/misc/readpixel.rb +66 -0
- data/examples/misc/sdltest.rb +36 -0
- data/examples/misc/trislam.rb +829 -0
- data/ext/opengl/GL/gl.h +2115 -0
- data/ext/opengl/GL/glext.h +11770 -0
- data/ext/opengl/common.h +372 -0
- data/ext/opengl/conv.h +247 -0
- data/ext/opengl/extconf.rb +19 -0
- data/ext/opengl/fptr_struct.h +912 -0
- data/ext/opengl/funcdef.h +279 -0
- data/ext/opengl/gl-1.0-1.1.c +3345 -0
- data/ext/opengl/gl-1.2.c +155 -0
- data/ext/opengl/gl-1.3.c +447 -0
- data/ext/opengl/gl-1.4.c +346 -0
- data/ext/opengl/gl-1.5.c +225 -0
- data/ext/opengl/gl-2.0.c +665 -0
- data/ext/opengl/gl-2.1.c +57 -0
- data/ext/opengl/gl-3.0.c +502 -0
- data/ext/opengl/gl-enums.c +4853 -0
- data/ext/opengl/gl-enums.h +14528 -0
- data/ext/opengl/gl-error.c +110 -0
- data/ext/opengl/gl-error.h +25 -0
- data/ext/opengl/gl-ext-3dfx.c +27 -0
- data/ext/opengl/gl-ext-arb.c +880 -0
- data/ext/opengl/gl-ext-ati.c +41 -0
- data/ext/opengl/gl-ext-ext.c +885 -0
- data/ext/opengl/gl-ext-gremedy.c +41 -0
- data/ext/opengl/gl-ext-nv.c +679 -0
- data/ext/opengl/gl.c +265 -0
- data/ext/opengl/gl_buffer.c +202 -0
- data/ext/opengl/glimpl.c +187 -0
- data/ext/opengl/glimpl.h +47 -0
- data/ext/opengl/opengl.c +9 -0
- data/lib/gl.rb +1 -0
- data/lib/opengl.rb +79 -0
- data/lib/opengl/bindings_version.rb +4 -0
- data/lib/opengl/implementation.rb +38 -0
- data/lib/opengl/test_case.rb +86 -0
- data/test/dummy.xorg.conf +140 -0
- data/test/test_gl.rb +45 -0
- data/test/test_gl_10_11.rb +1363 -0
- data/test/test_gl_12.rb +71 -0
- data/test/test_gl_13.rb +221 -0
- data/test/test_gl_14.rb +218 -0
- data/test/test_gl_15.rb +258 -0
- data/test/test_gl_20.rb +417 -0
- data/test/test_gl_21.rb +436 -0
- data/test/test_gl_ext_arb.rb +508 -0
- data/test/test_gl_ext_ati.rb +28 -0
- data/test/test_gl_ext_ext.rb +608 -0
- data/test/test_gl_ext_gremedy.rb +29 -0
- data/test/test_gl_ext_nv.rb +349 -0
- data/test/test_glimpl.rb +23 -0
- data/test/test_opengl_buffer.rb +122 -0
- data/utils/README +6 -0
- data/utils/enumgen.rb +108 -0
- data/utils/extlistgen.rb +90 -0
- metadata +326 -0
@@ -0,0 +1,137 @@
|
|
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
|
+
# colormat.c
|
38
|
+
# After initialization, the program will be in
|
39
|
+
# ColorMaterial mode. Interaction: pressing the
|
40
|
+
# mouse buttons will change the diffuse reflection values.
|
41
|
+
require 'opengl'
|
42
|
+
require 'glu'
|
43
|
+
require 'glut'
|
44
|
+
require 'mathn'
|
45
|
+
include Gl,Glu,Glut
|
46
|
+
|
47
|
+
$diffuseMaterial = [0.5,0.5,0.5,1.0]
|
48
|
+
|
49
|
+
# Initialize material property, light source, lighting model,
|
50
|
+
# and depth buffer.
|
51
|
+
def init
|
52
|
+
mat_specular = [ 1.0, 1.0, 1.0, 1.0 ]
|
53
|
+
light_position = [ 1.0, 1.0, 1.0, 0.0 ]
|
54
|
+
|
55
|
+
glClearColor(0.0, 0.0, 0.0, 0.0)
|
56
|
+
glShadeModel(GL_SMOOTH)
|
57
|
+
glEnable(GL_DEPTH_TEST)
|
58
|
+
glMaterial(GL_FRONT, GL_DIFFUSE, $diffuseMaterial)
|
59
|
+
glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
|
60
|
+
glMaterial(GL_FRONT, GL_SHININESS, 25.0)
|
61
|
+
glLight(GL_LIGHT0, GL_POSITION, light_position)
|
62
|
+
glEnable(GL_LIGHTING)
|
63
|
+
glEnable(GL_LIGHT0)
|
64
|
+
|
65
|
+
glColorMaterial(GL_FRONT, GL_DIFFUSE)
|
66
|
+
glEnable(GL_COLOR_MATERIAL)
|
67
|
+
end
|
68
|
+
|
69
|
+
display = Proc.new do
|
70
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
71
|
+
glutSolidSphere(1.0, 20, 16)
|
72
|
+
glutSwapBuffers()
|
73
|
+
end
|
74
|
+
|
75
|
+
reshape = Proc.new do |w, h|
|
76
|
+
glViewport(0, 0, w, h)
|
77
|
+
glMatrixMode(GL_PROJECTION)
|
78
|
+
glLoadIdentity()
|
79
|
+
if (w <= h)
|
80
|
+
glOrtho(-1.5, 1.5, -1.5*h/w, 1.5*h/w, -10.0, 10.0)
|
81
|
+
else
|
82
|
+
glOrtho(-1.5*w/h, 1.5*w/h, -1.5, 1.5, -10.0, 10.0)
|
83
|
+
end
|
84
|
+
glMatrixMode(GL_MODELVIEW)
|
85
|
+
glLoadIdentity()
|
86
|
+
end
|
87
|
+
|
88
|
+
mouse = Proc.new do |button, state, x, y|
|
89
|
+
case (button)
|
90
|
+
when GLUT_LEFT_BUTTON
|
91
|
+
if (state == GLUT_DOWN)
|
92
|
+
$diffuseMaterial[0] = $diffuseMaterial[0] + 0.1
|
93
|
+
if ($diffuseMaterial[0] > 1.0)
|
94
|
+
$diffuseMaterial[0] = 0.0
|
95
|
+
end
|
96
|
+
glColor($diffuseMaterial)
|
97
|
+
glutPostRedisplay()
|
98
|
+
end
|
99
|
+
when GLUT_MIDDLE_BUTTON
|
100
|
+
if (state == GLUT_DOWN)
|
101
|
+
$diffuseMaterial[1] = $diffuseMaterial[1] + 0.1
|
102
|
+
if ($diffuseMaterial[1] > 1.0)
|
103
|
+
$diffuseMaterial[1] = 0.0
|
104
|
+
end
|
105
|
+
glColor($diffuseMaterial)
|
106
|
+
glutPostRedisplay()
|
107
|
+
end
|
108
|
+
when GLUT_RIGHT_BUTTON
|
109
|
+
if (state == GLUT_DOWN)
|
110
|
+
$diffuseMaterial[2] = $diffuseMaterial[2] + 0.1
|
111
|
+
if ($diffuseMaterial[2] > 1.0)
|
112
|
+
$diffuseMaterial[2] = 0.0
|
113
|
+
end
|
114
|
+
glColor($diffuseMaterial)
|
115
|
+
glutPostRedisplay()
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
keyboard = Proc.new do |key, x, y|
|
121
|
+
case (key)
|
122
|
+
when ?\e
|
123
|
+
exit(0)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
glutInit
|
128
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
|
129
|
+
glutInitWindowSize(500, 500)
|
130
|
+
glutInitWindowPosition(100, 100)
|
131
|
+
glutCreateWindow($0)
|
132
|
+
init()
|
133
|
+
glutDisplayFunc(display)
|
134
|
+
glutReshapeFunc(reshape)
|
135
|
+
glutMouseFunc(mouse)
|
136
|
+
glutKeyboardFunc(keyboard)
|
137
|
+
glutMainLoop()
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby -rubygems
|
2
|
+
require 'opengl'
|
3
|
+
require 'glu'
|
4
|
+
require 'glut'
|
5
|
+
include Gl,Glu,Glut
|
6
|
+
|
7
|
+
$light_diffuse = [1.0, 0.0, 0.0, 1.0]
|
8
|
+
$light_position = [1.0, 1.0, 1.0, 0.0]
|
9
|
+
$n = [
|
10
|
+
[-1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0],
|
11
|
+
[0.0, -1.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, -1.0] ]
|
12
|
+
$faces = [
|
13
|
+
[0, 1, 2, 3], [3, 2, 6, 7], [7, 6, 5, 4],
|
14
|
+
[4, 5, 1, 0], [5, 6, 2, 1], [7, 4, 0, 3] ]
|
15
|
+
$v = 0
|
16
|
+
|
17
|
+
def drawBox
|
18
|
+
for i in (0..5)
|
19
|
+
glBegin(GL_QUADS)
|
20
|
+
glNormal(*($n[i]))
|
21
|
+
glVertex($v[$faces[i][0]])
|
22
|
+
glVertex($v[$faces[i][1]])
|
23
|
+
glVertex($v[$faces[i][2]])
|
24
|
+
glVertex($v[$faces[i][3]])
|
25
|
+
glEnd()
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
display = Proc.new do
|
30
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
31
|
+
drawBox
|
32
|
+
glutSwapBuffers
|
33
|
+
end
|
34
|
+
|
35
|
+
def myinit
|
36
|
+
$v = [[-1, -1,1],[-1, -1,-1], [-1,1,-1], [-1,1,1], [1, -1,1],
|
37
|
+
[1, -1,-1], [1, 1,-1], [1,1,1]]
|
38
|
+
|
39
|
+
glLight(GL_LIGHT0, GL_DIFFUSE, $light_diffuse)
|
40
|
+
glLight(GL_LIGHT0, GL_POSITION, $light_position)
|
41
|
+
glEnable(GL_LIGHT0)
|
42
|
+
glEnable(GL_LIGHTING)
|
43
|
+
|
44
|
+
glEnable(GL_DEPTH_TEST)
|
45
|
+
|
46
|
+
glMatrixMode(GL_PROJECTION)
|
47
|
+
gluPerspective(40.0, 1.0, 1.0, 10.0)
|
48
|
+
glMatrixMode(GL_MODELVIEW)
|
49
|
+
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
|
50
|
+
|
51
|
+
glTranslate(0.0, 0.0, -1.0)
|
52
|
+
glRotate(60, 1.0, 0.0, 0.0)
|
53
|
+
glRotate(-20, 0.0, 0.0, 1.0)
|
54
|
+
end
|
55
|
+
|
56
|
+
keyboard = Proc.new do |key, x, y|
|
57
|
+
case (key)
|
58
|
+
when ?\e
|
59
|
+
exit(0);
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
glutInit
|
64
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
|
65
|
+
glutInitWindowSize(500, 500)
|
66
|
+
glutInitWindowPosition(100, 100)
|
67
|
+
glutCreateWindow("red 3D lighted cube")
|
68
|
+
glutDisplayFunc(display)
|
69
|
+
glutKeyboardFunc(keyboard)
|
70
|
+
myinit
|
71
|
+
glutMainLoop()
|
@@ -0,0 +1,101 @@
|
|
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
|
+
# depthcue.c
|
40
|
+
# This program draws a wireframe model, which uses
|
41
|
+
# intensity (brightness) to give clues to distance.
|
42
|
+
# Fog is used to achieve this effect.
|
43
|
+
require 'opengl'
|
44
|
+
require 'glu'
|
45
|
+
require 'glut'
|
46
|
+
require 'mathn'
|
47
|
+
include Gl,Glu,Glut
|
48
|
+
|
49
|
+
# Initialize linear fog for depth cueing.
|
50
|
+
def myinit
|
51
|
+
fogColor = [0.0, 0.0, 0.0, 1.0]
|
52
|
+
|
53
|
+
glEnable(GL_FOG)
|
54
|
+
glFog(GL_FOG_MODE, GL_LINEAR)
|
55
|
+
glHint(GL_FOG_HINT, GL_NICEST) # per pixel
|
56
|
+
glFog(GL_FOG_START, 3.0)
|
57
|
+
glFog(GL_FOG_END, 5.0)
|
58
|
+
glFog(GL_FOG_COLOR, fogColor)
|
59
|
+
glClearColor(0.0, 0.0, 0.0, 1.0)
|
60
|
+
|
61
|
+
glDepthFunc(GL_LESS)
|
62
|
+
glEnable(GL_DEPTH_TEST)
|
63
|
+
glShadeModel(GL_FLAT)
|
64
|
+
end
|
65
|
+
|
66
|
+
# display() draws an icosahedron.
|
67
|
+
display = Proc.new do
|
68
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
69
|
+
glColor(1.0, 1.0, 1.0)
|
70
|
+
glutWireIcosahedron()
|
71
|
+
glFlush()
|
72
|
+
end
|
73
|
+
|
74
|
+
myReshape = Proc.new do |w, h|
|
75
|
+
glViewport(0, 0, w, h)
|
76
|
+
glMatrixMode(GL_PROJECTION)
|
77
|
+
glLoadIdentity()
|
78
|
+
gluPerspective(45.0, w/h, 3.0, 5.0)
|
79
|
+
glMatrixMode(GL_MODELVIEW)
|
80
|
+
glLoadIdentity()
|
81
|
+
glTranslate(0.0, 0.0, -4.0) # move object into view
|
82
|
+
end
|
83
|
+
|
84
|
+
keyboard = Proc.new do |key, x, y|
|
85
|
+
case (key)
|
86
|
+
when ?\e
|
87
|
+
exit(0)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Main Loop
|
92
|
+
glutInit
|
93
|
+
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)
|
94
|
+
glutInitWindowSize(500, 500)
|
95
|
+
glutInitWindowPosition(100, 100)
|
96
|
+
glutCreateWindow($0)
|
97
|
+
myinit()
|
98
|
+
glutReshapeFunc(myReshape)
|
99
|
+
glutDisplayFunc(display)
|
100
|
+
glutKeyboardFunc(keyboard)
|
101
|
+
glutMainLoop()
|
@@ -0,0 +1,206 @@
|
|
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
|
+
# dof.c
|
40
|
+
# This program demonstrates use of the accumulation buffer to
|
41
|
+
# create an out-of-focus depth-of-field effect. The teapots
|
42
|
+
# are drawn several times into the accumulation buffer. The
|
43
|
+
# viewing volume is jittered, except at the focal point, where
|
44
|
+
# the viewing volume is at the same position, each time. In
|
45
|
+
# this case, the gold teapot remains in focus.
|
46
|
+
require 'opengl'
|
47
|
+
require 'glu'
|
48
|
+
require 'glut'
|
49
|
+
require_relative 'jitter'
|
50
|
+
include Gl,Glu,Glut
|
51
|
+
|
52
|
+
# accFrustum()
|
53
|
+
# The first 6 arguments are identical to the glFrustum() call.
|
54
|
+
#
|
55
|
+
# pixdx and pixdy are anti-alias jitter in pixels.
|
56
|
+
# Set both equal to 0.0 for no anti-alias jitter.
|
57
|
+
# eyedx and eyedy are depth-of field jitter in pixels.
|
58
|
+
# Set both equal to 0.0 for no depth of field effects.
|
59
|
+
#
|
60
|
+
# focus is distance from eye to plane in focus.
|
61
|
+
# focus must be greater than, but not equal to 0.0.
|
62
|
+
#
|
63
|
+
# Note that accFrustum() calls glTranslatef(). You will
|
64
|
+
# probably want to insure that your ModelView matrix has been
|
65
|
+
# initialized to identity before calling accFrustum().
|
66
|
+
def accFrustum(left, right, bottom, top, nnear, ffar, pixdx, pixdy, eyedx, eyedy, focus)
|
67
|
+
viewport = glGetDoublev(GL_VIEWPORT)
|
68
|
+
|
69
|
+
xwsize = right - left
|
70
|
+
ywsize = top - bottom
|
71
|
+
|
72
|
+
dx = -(pixdx*xwsize/viewport[2] + eyedx*nnear/focus)
|
73
|
+
dy = -(pixdy*ywsize/viewport[3] + eyedy*nnear/focus)
|
74
|
+
|
75
|
+
glMatrixMode(GL_PROJECTION)
|
76
|
+
glLoadIdentity()
|
77
|
+
glFrustum(left + dx, right + dx, bottom + dy, top + dy, nnear, ffar)
|
78
|
+
glMatrixMode(GL_MODELVIEW)
|
79
|
+
glLoadIdentity()
|
80
|
+
glTranslate(-eyedx, -eyedy, 0.0)
|
81
|
+
end
|
82
|
+
|
83
|
+
# accPerspective()
|
84
|
+
#
|
85
|
+
# The first 4 arguments are identical to the gluPerspective() call.
|
86
|
+
# pixdx and pixdy are anti-alias jitter in pixels.
|
87
|
+
# Set both equal to 0.0 for no anti-alias jitter.
|
88
|
+
# eyedx and eyedy are depth-of field jitter in pixels.
|
89
|
+
# Set both equal to 0.0 for no depth of field effects.
|
90
|
+
#
|
91
|
+
# focus is distance from eye to plane in focus.
|
92
|
+
# focus must be greater than, but not equal to 0.0.
|
93
|
+
#
|
94
|
+
# Note that accPerspective() calls accFrustum().
|
95
|
+
def accPerspective(fovy, aspect, nnear, ffar, pixdx, pixdy, eyedx, eyedy, focus)
|
96
|
+
fov2 = ((fovy*Math::PI) / 180.0) / 2.0
|
97
|
+
|
98
|
+
top = nnear / (Math::cos(fov2) / Math::sin(fov2))
|
99
|
+
bottom = -top
|
100
|
+
|
101
|
+
right = top * aspect
|
102
|
+
left = -right
|
103
|
+
|
104
|
+
accFrustum(left, right, bottom, top, nnear, ffar, pixdx, pixdy, eyedx, eyedy, focus)
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def myinit
|
109
|
+
ambient = [ 0.0, 0.0, 0.0, 1.0 ]
|
110
|
+
diffuse = [ 1.0, 1.0, 1.0, 1.0 ]
|
111
|
+
position = [ 0.0, 3.0, 3.0, 0.0 ]
|
112
|
+
|
113
|
+
lmodel_ambient = [ 0.2, 0.2, 0.2, 1.0 ]
|
114
|
+
local_view = [ 0.0 ]
|
115
|
+
|
116
|
+
glEnable(GL_DEPTH_TEST)
|
117
|
+
glDepthFunc(GL_LESS)
|
118
|
+
|
119
|
+
glLight(GL_LIGHT0, GL_AMBIENT, ambient)
|
120
|
+
glLight(GL_LIGHT0, GL_DIFFUSE, diffuse)
|
121
|
+
glLight(GL_LIGHT0, GL_POSITION, position)
|
122
|
+
|
123
|
+
glLightModel(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient)
|
124
|
+
glLightModel(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view)
|
125
|
+
|
126
|
+
glFrontFace(GL_CW)
|
127
|
+
glEnable(GL_LIGHTING)
|
128
|
+
glEnable(GL_LIGHT0)
|
129
|
+
glEnable(GL_AUTO_NORMAL)
|
130
|
+
glEnable(GL_NORMALIZE)
|
131
|
+
|
132
|
+
glMatrixMode(GL_MODELVIEW)
|
133
|
+
glLoadIdentity()
|
134
|
+
|
135
|
+
glClearColor(0.0, 0.0, 0.0, 0.0)
|
136
|
+
glClearAccum(0.0, 0.0, 0.0, 0.0)
|
137
|
+
end
|
138
|
+
|
139
|
+
def renderTeapot (x, y, z, ambr, ambg, ambb, difr, difg, difb, specr, specg, specb, shine)
|
140
|
+
glPushMatrix()
|
141
|
+
glTranslate(x, y, z)
|
142
|
+
mat = []
|
143
|
+
mat[0] = ambr; mat[1] = ambg; mat[2] = ambb; mat[3] = 1.0
|
144
|
+
glMaterial(GL_FRONT, GL_AMBIENT, mat)
|
145
|
+
mat[0] = difr; mat[1] = difg; mat[2] = difb
|
146
|
+
glMaterial(GL_FRONT, GL_DIFFUSE, mat)
|
147
|
+
mat[0] = specr; mat[1] = specg; mat[2] = specb
|
148
|
+
glMaterial(GL_FRONT, GL_SPECULAR, mat)
|
149
|
+
glMaterial(GL_FRONT, GL_SHININESS, shine*128.0)
|
150
|
+
glutSolidTeapot(0.5)
|
151
|
+
glPopMatrix()
|
152
|
+
end
|
153
|
+
|
154
|
+
# display() draws 5 teapots into the accumulation buffer
|
155
|
+
# several times each time with a jittered perspective.
|
156
|
+
# The focal point is at z = 5.0, so the gold teapot will
|
157
|
+
# stay in focus. The amount of jitter is adjusted by the
|
158
|
+
# magnitude of the accPerspective() jitter in this example, 0.33.
|
159
|
+
# In this example, the teapots are drawn 8 times. See jitter.rb
|
160
|
+
display = proc do
|
161
|
+
viewport = glGetDoublev(GL_VIEWPORT)
|
162
|
+
glClear(GL_ACCUM_BUFFER_BIT)
|
163
|
+
|
164
|
+
for jitter in 0...8
|
165
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
166
|
+
accPerspective(45.0,
|
167
|
+
viewport[2]/ viewport[3],
|
168
|
+
1.0, 15.0, 0.0, 0.0,
|
169
|
+
0.33*$j8[jitter][0], 0.33*$j8[jitter][1], 5.0)
|
170
|
+
# ruby, gold, silver, emerald, and cyan teapots
|
171
|
+
renderTeapot(-1.1, -0.5, -4.5, 0.1745, 0.01175, 0.01175, 0.61424, 0.04136, 0.04136, 0.727811, 0.626959, 0.626959, 0.6)
|
172
|
+
renderTeapot(-0.5, -0.5, -5.0, 0.24725, 0.1995, 0.0745, 0.75164, 0.60648, 0.22648, 0.628281, 0.555802, 0.366065, 0.4)
|
173
|
+
renderTeapot(0.2, -0.5, -5.5, 0.19225, 0.19225, 0.19225, 0.50754, 0.50754, 0.50754, 0.508273, 0.508273, 0.508273, 0.4)
|
174
|
+
renderTeapot(1.0, -0.5, -6.0, 0.0215, 0.1745, 0.0215, 0.07568, 0.61424, 0.07568, 0.633, 0.727811, 0.633, 0.6)
|
175
|
+
renderTeapot(1.8, -0.5, -6.5, 0.0, 0.1, 0.06, 0.0, 0.50980392, 0.50980392, 0.50196078, 0.50196078, 0.50196078, 0.25)
|
176
|
+
glAccum(GL_ACCUM, 0.125)
|
177
|
+
end
|
178
|
+
|
179
|
+
glAccum(GL_RETURN, 1.0)
|
180
|
+
glutSwapBuffers()
|
181
|
+
end
|
182
|
+
|
183
|
+
myReshape = proc do |w, h|
|
184
|
+
glViewport(0, 0, w, h)
|
185
|
+
end
|
186
|
+
|
187
|
+
keyboard = proc do |key, x, y|
|
188
|
+
case (key)
|
189
|
+
when ?\e
|
190
|
+
exit(0)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
# Main Loop
|
195
|
+
# Open window with initial window size, title bar,
|
196
|
+
# RGBA display mode, depth buffer, and handle input events.
|
197
|
+
glutInit()
|
198
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_ACCUM | GLUT_DEPTH)
|
199
|
+
glutInitWindowSize(500, 500)
|
200
|
+
glutInitWindowPosition(100, 100)
|
201
|
+
glutCreateWindow()
|
202
|
+
myinit()
|
203
|
+
glutReshapeFunc(myReshape)
|
204
|
+
glutDisplayFunc(display)
|
205
|
+
glutKeyboardFunc(keyboard)
|
206
|
+
glutMainLoop()
|