3 # Bezier Surface example
11 my $app = new SDL::App -w => 800, -h => 600, -d => 16, -gl => 1;
13 my @points = ( [-1.5, -1.5, 4.0 ], [-0.5, -1.5, 2.0 ],
14 [-0.5, -1.5, -1.0 ], [ 1.5, -1.5, 2.0 ],
15 [-1.5, -0.5, 1.0 ], [-0.5, -0.5, 3.0 ],
16 [ 0.5, -0.5, 0.0 ], [ 1.5, -0.5, -1.0 ],
17 [-1.5, 0.5, 4.0 ], [-0.5, 0.5, 0.0 ],
18 [ 0.5, 0.5, 3.0 ], [ 1.5, 0.5, 4.0 ],
19 [-1.5, 1.5, -2.0 ], [-0.5, 1.5, -2.0 ],
20 [ 0.5, 1.5, 0.0 ], [ 1.5, 1.5, -1.0 ],
23 my $ctrlpoints = pack "d48", map { @$_ } @points;
27 glViewport(0,0,800,600);
28 glMatrixMode(GL_PROJECTION());
31 glFrustum (-0.1,0.1,-0.075,0.075,0.3,100.0 );
33 glMatrixMode(GL_MODELVIEW());
38 glClearColor(0.0, 0.0, 0.0, 0.0);
39 glMap2(GL_MAP2_VERTEX_3(), 0, 1, 3, 4, 0, 1, 12, 4, $ctrlpoints);
40 glEnable(GL_MAP2_VERTEX_3());
41 glMapGrid2(20,0,1,20,0,1);
42 glEnable(GL_DEPTH_TEST);
43 glShadeModel(GL_SMOOTH());
48 glEnable(GL_LIGHTING());
49 glEnable(GL_LIGHT0());
51 glLight(GL_LIGHT0(),GL_AMBIENT(),0.2,0.2,0.2,1.0);
52 glLight(GL_LIGHT0(),GL_POSITION(), 0.0,0.0,2.0,1.0);
54 glMaterial(GL_FRONT(), GL_DIFFUSE(),0.6,0.6,0.6,1.0);
55 glMaterial(GL_FRONT(), GL_SPECULAR(), 1.0, 1.0, 1.0, 1.0);
56 glMaterial(GL_FRONT(), GL_SHININESS(), 50.0);
60 my ($a1,$a2) = (89,305);
63 glClear(GL_COLOR_BUFFER_BIT() | GL_DEPTH_BUFFER_BIT());
66 glRotate($a1 % 360, 0.0, 1.0, 1.0);
67 glRotate($a2 % 360, 1.0, 1.0, 0.0);
69 glEvalMesh2(GL_FILL,0,20,0,20);
71 glBegin(GL_LINE_STRIP);
72 for my $j ( 0 .. 8 ) {
73 for my $i ( 0 .. 30 ) {
74 glEvalCoord2($i/30,$j/8);
76 for my $i ( 0 .. 30 ) {
77 glEvalCoord2($j/8,$i/30);
88 Press: t Toggle wireframe / solid
91 any Rotate Bezier Surface
98 my $event = new SDL::Event;
100 SDL_QUIT() => sub { exit(); },
101 SDL_KEYDOWN() => sub {
103 if ( $event->key_sym() == SDLK_f ) {
106 } elsif ( $event->key_sym() == SDLK_t ) {
107 $toggle = $toggle ? 0 : 1;
109 } elsif ( $event->key_sym() == SDLK_q ) {