First commit of SDL_Perl-2.1.3
[sdlgit/SDL_perl.git] / test / OpenGL / test3.pl
1 #!/usr/bin/env perl
2 #
3 # Bezier Curve example 
4 #
5
6 use SDL;
7 use SDL::App;
8 use SDL::Surface;
9 use SDL::Event;
10 use SDL::OpenGL;
11
12 my $app = new SDL::App  -w => 800, -h => 600, -d => 16, -gl => 1;
13
14 my @points = (  [-4.0, -4.0,  0.0 ],
15                 [-2.0,  4.0,  0.0 ],
16                 [ 2.0, -4.0,  0.0 ],
17                 [ 4.0,  4.0,  0.0 ] );
18
19 my $ctrlpoints = pack "d12", map { @$_ } @points;
20
21 sub init {
22         
23         glViewport(0,0,800,600);
24         glMatrixMode(GL_PROJECTION());
25         glLoadIdentity();
26
27         glFrustum (-0.1,0.1,-0.075,0.075,0.3,100.0 );
28         
29         glMatrixMode(GL_MODELVIEW());
30         glLoadIdentity();
31         
32         glTranslate(0,0,-30);
33
34         glClearColor(0.0, 0.0, 0.0, 0.0);       
35         glShadeModel(GL_FLAT());
36         glMap1(GL_MAP1_VERTEX_3(), 0.0, 1.0, 3, 4, $ctrlpoints);
37         glEnable(GL_MAP1_VERTEX_3());
38 }
39
40 sub display {
41         glClear(GL_COLOR_BUFFER_BIT);
42         glColor(1.0,1.0,1.0);
43         glBegin(GL_LINE_STRIP);
44                 for my $i ( 0 .. 30 ) {
45                         glEvalCoord1($i/30);
46                 }
47         glEnd();
48
49         glPointSize(5);
50         glColor(1.0,1.0,0);
51         glBegin(GL_POINTS);
52                 for my $i ( 0 .. 3 ) {
53                         glVertex( @{$points[$i]} );
54                 }
55         glEnd();
56         $app->sync();
57 }
58
59 init();
60 display();
61
62 $app->loop({ SDL_QUIT() => sub { exit(); } });
63