5 # Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
7 # ------------------------------------------------------------------------------
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 # ------------------------------------------------------------------------------
25 # Please feel free to send questions, suggestions or improvements to:
38 my $app = new SDL::App -w => 800, -h => 600, -d => 16, -gl => 1;
40 my @points = ( [-1.5, -1.5, 4.0 ], [-0.5, -1.5, 2.0 ],
41 [-0.5, -1.5, -1.0 ], [ 1.5, -1.5, 2.0 ],
42 [-1.5, -0.5, 1.0 ], [-0.5, -0.5, 3.0 ],
43 [ 0.5, -0.5, 0.0 ], [ 1.5, -0.5, -1.0 ],
44 [-1.5, 0.5, 4.0 ], [-0.5, 0.5, 0.0 ],
45 [ 0.5, 0.5, 3.0 ], [ 1.5, 0.5, 4.0 ],
46 [-1.5, 1.5, -2.0 ], [-0.5, 1.5, -2.0 ],
47 [ 0.5, 1.5, 0.0 ], [ 1.5, 1.5, -1.0 ],
50 my $ctrlpoints = pack "d48", map { @$_ } @points;
54 glViewport(0,0,800,600);
55 glMatrixMode(GL_PROJECTION());
58 glFrustum (-0.1,0.1,-0.075,0.075,0.3,100.0 );
60 glMatrixMode(GL_MODELVIEW());
65 glClearColor(0.0, 0.0, 0.0, 0.0);
66 glMap2(GL_MAP2_VERTEX_3(), 0, 1, 3, 4, 0, 1, 12, 4, $ctrlpoints);
67 glEnable(GL_MAP2_VERTEX_3());
68 glMapGrid2(20,0,1,20,0,1);
69 glEnable(GL_DEPTH_TEST);
70 glShadeModel(GL_SMOOTH());
75 glEnable(GL_LIGHTING());
76 glEnable(GL_LIGHT0());
78 glLight(GL_LIGHT0(),GL_AMBIENT(),0.2,0.2,0.2,1.0);
79 glLight(GL_LIGHT0(),GL_POSITION(), 0.0,0.0,2.0,1.0);
81 glMaterial(GL_FRONT(), GL_DIFFUSE(),0.6,0.6,0.6,1.0);
82 glMaterial(GL_FRONT(), GL_SPECULAR(), 1.0, 1.0, 1.0, 1.0);
83 glMaterial(GL_FRONT(), GL_SHININESS(), 50.0);
87 my ($a1,$a2) = (89,305);
90 glClear(GL_COLOR_BUFFER_BIT() | GL_DEPTH_BUFFER_BIT());
93 glRotate($a1 % 360, 0.0, 1.0, 1.0);
94 glRotate($a2 % 360, 1.0, 1.0, 0.0);
96 glEvalMesh2(GL_FILL,0,20,0,20);
98 glBegin(GL_LINE_STRIP);
99 for my $j ( 0 .. 8 ) {
100 for my $i ( 0 .. 30 ) {
101 glEvalCoord2($i/30,$j/8);
103 for my $i ( 0 .. 30 ) {
104 glEvalCoord2($j/8,$i/30);
113 print STDERR <<USAGE;
115 Press: t Toggle wireframe / solid
118 any Rotate Bezier Surface
125 my $event = new SDL::Event;
127 SDL_QUIT() => sub { exit(); },
128 SDL_KEYDOWN() => sub {
130 if ( $event->key_sym() == SDLK_f ) {
133 } elsif ( $event->key_sym() == SDLK_t ) {
134 $toggle = $toggle ? 0 : 1;
136 } elsif ( $event->key_sym() == SDLK_q ) {