-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplane.pl
109 lines (91 loc) · 3.12 KB
/
plane.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/local/bin/perl
#
# plane
# This program demonstrates the use of local versus
# infinite lighting on a flat plane.
# Adapted from book "OpenGL Programming Guide"
#
BEGIN{ unshift(@INC,"../blib"); } # in case OpenGL is built but not installed
BEGIN{ unshift(@INC,"../blib/arch"); } # 5.002 gamma needs this
BEGIN{ unshift(@INC,"../blib/lib"); } # 5.002 gamma needs this
use OpenGL;
# Initialize material property, light source, and lighting model.
sub myinit{
# mat_specular and mat_shininess are NOT default values
# Its important not to make a mistake on the packing
# there's no type checking for C pointer arguments
$mat_ambient = pack("f4", 0.0, 0.0, 0.0, 1.0 );
$mat_diffuse = pack("f4", 0.4, 0.4, 0.4, 1.0 );
$mat_specular = pack("f4", 1.0, 1.0, 1.0, 1.0 );
$mat_shininess = 15.0 ;
$light_ambient = pack("f4", 0.0, 0.0, 0.0, 1.0 );
$light_diffuse = pack("f4", 1.0, 1.0, 1.0, 1.0 );
$light_specular = pack("f4", 1.0, 1.0, 1.0, 1.0 );
$lmodel_ambient = pack("f4", 0.2, 0.2, 0.2, 1.0 );
glMaterialfv(GL_FRONT, GL_AMBIENT, $mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, $mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, $mat_specular);
glMaterialf(GL_FRONT, GL_SHININESS, $mat_shininess);
glLightfv(GL_LIGHT0, GL_AMBIENT, $light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, $light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, $light_specular);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, $lmodel_ambient);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
}
sub drawPlane {
glBegin (GL_QUADS);
glNormal3f (0.0, 0.0, 1.0);
glVertex3f (-1.0, -1.0, 0.0);
glVertex3f (0.0, -1.0, 0.0);
glVertex3f (0.0, 0.0, 0.0);
glVertex3f (-1.0, 0.0, 0.0);
glNormal3f (0.0, 0.0, 1.0);
glVertex3f (0.0, -1.0, 0.0);
glVertex3f (1.0, -1.0, 0.0);
glVertex3f (1.0, 0.0, 0.0);
glVertex3f (0.0, 0.0, 0.0);
glNormal3f (0.0, 0.0, 1.0);
glVertex3f (0.0, 0.0, 0.0);
glVertex3f (1.0, 0.0, 0.0);
glVertex3f (1.0, 1.0, 0.0);
glVertex3f (0.0, 1.0, 0.0);
glNormal3f (0.0, 0.0, 1.0);
glVertex3f (0.0, 0.0, 0.0);
glVertex3f (0.0, 1.0, 0.0);
glVertex3f (-1.0, 1.0, 0.0);
glVertex3f (-1.0, 0.0, 0.0);
glEnd();
}
sub display {
$infinite_light = pack("f4", 1.0, 1.0, 1.0, 0.0 );
$local_light = pack("f4", 1.0, 1.0, 1.0, 1.0 );
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix ();
glTranslatef (-1.5, 0.0, 0.0);
glLightfv (GL_LIGHT0, GL_POSITION, $infinite_light);
drawPlane ();
glPopMatrix ();
glPushMatrix ();
glTranslatef (1.5, 0.0, 0.0);
glLightfv (GL_LIGHT0, GL_POSITION, $local_light);
drawPlane ();
glPopMatrix ();
glpFlush ();
}
sub myReshape{
# glViewport (0, 0, w, h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (-3.0, 3.0, -3.0, 3.0, -10.0, 10.0);
glMatrixMode (GL_MODELVIEW);
}
# use optional 3rd argument to glpOpenWindow to indicate
# what is needed for the visual just rgb (no double buffer).
glpOpenWindow;
myinit();
myReshape;
display;
glpMainLoop;