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:
37 my $app = new SDL::App -w => 800, -h => 600, -d => 16, -gl => 1;
40 my $knots = pack "f8", 0,0,0,0,1,1,1,1;
41 my $edgePts = pack "f10", 0,0,1,0,1,1,0,1,0,0;
42 my $curvePts = pack "f8", 0.25,0.5,0.25,0.75,0.75,0.75,0.75,0.5;
43 my $curveKnots = pack "f8", 0,0,0,0,1,1,1,1;
44 my $pwlPts = pack "f8", 0.75, 0.5, 0.5, 0.25, 0.25, 0.5, 0, 0;
47 glViewport(0,0,800,600);
48 glMatrixMode(GL_PROJECTION());
50 glFrustum (-0.1,0.1,-0.075,0.075,0.3,100.0 );
51 glMatrixMode(GL_MODELVIEW());
54 glClearColor(0.0, 0.0, 0.0, 0.0);
55 glShadeModel(GL_SMOOTH());
59 glEnable(GL_LIGHTING());
60 glEnable(GL_LIGHT0());
61 glEnable(GL_DEPTH_TEST());
62 glEnable(GL_AUTO_NORMAL());
63 glEnable(GL_NORMALIZE());
64 glLight(GL_LIGHT0(),GL_AMBIENT(),0.3,0.3,0.3,1.0);
65 glLight(GL_LIGHT0(),GL_POSITION(), 1.0,0.0,2.0,1.0);
66 glMaterial(GL_FRONT(), GL_DIFFUSE(),0.6,0.6,0.6,1.0);
67 glMaterial(GL_FRONT(), GL_SPECULAR(), 1.0, 1.0, 1.0, 1.0);
68 glMaterial(GL_FRONT(), GL_SHININESS(), 40.0);
76 for my $u ( 0 .. 3 ) {
77 for my $v ( 0 .. 3 ) {
78 push @points, 2.0 * ($u - 1.5);
79 push @points, 2.0 * ($v - 1.5);
80 if (( $u == 1 || $u == 2 ) && ( $v == 1 || $v == 2 )) {
87 $ctrldata = pack "f48", @points;
91 glClear(GL_COLOR_BUFFER_BIT() | GL_DEPTH_BUFFER_BIT());
93 glRotate($a%360,0,1,0);
94 glRotate($b%360,-1,0,0);
96 my $nurb = gluNewNurbsRenderer();
97 gluNurbsProperty($nurb,GLU_CULLING,GL_TRUE);
98 gluBeginSurface($nurb);
99 gluNurbsSurface($nurb, 8, $knots, 8, $knots,
101 4, 4, GL_MAP2_VERTEX_3);
104 gluPwlCurve($nurb,5,$edgePts,2,GLU_MAP1_TRIM_2);
107 gluNurbsCurve($nurb,8,$curveKnots, 2, $curvePts, 4, GLU_MAP1_TRIM_2);
108 gluPwlCurve($nurb,3,$pwlPts,2,GLU_MAP1_TRIM_2);
112 gluEndSurface($nurb);
123 print STDERR <<USAGE;
126 t Toggle Curve & Trim
128 Up/Down/Left/Right Rotate
132 my $event = new SDL::Event;
134 SDL_QUIT() => sub { exit(); },
135 SDL_KEYDOWN() => sub {
137 if ( $event->key_sym() == SDLK_f ) {
140 } elsif ( $event->key_sym() == SDLK_t ) {
141 $toggle = $toggle ? 0 : 1;
143 } elsif ( $event->key_sym() == SDLK_q ) {
146 if ($event->key_sym() == SDLK_LEFT()) {
148 } elsif ($event->key_sym() == SDLK_RIGHT()) {
150 } elsif ($event->key_sym() == SDLK_UP()) {
152 } elsif ($event->key_sym() == SDLK_DOWN()) {