Importing SDLPerl 2.2
[sdlgit/SDL_perl.git] / test / OpenGL / test3.sdlpl
1 #!/usr/bin/env perl
2 #
3 # test3.pl
4 #
5 # Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
6 #
7 # ------------------------------------------------------------------------------
8 #
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.
13
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.
18
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
22 #
23 # ------------------------------------------------------------------------------
24 #
25 # Please feel free to send questions, suggestions or improvements to:
26 #
27 #       David J. Goehrig
28 #       dgoehrig@cpan.org
29 #
30
31 use strict;
32 use SDL;
33 use SDL::App;
34 use SDL::Surface;
35 use SDL::Event;
36 use SDL::OpenGL;
37
38 my $app = new SDL::App  -w => 800, -h => 600, -d => 16, -gl => 1;
39
40 my @points = (  [-4.0, -4.0,  0.0 ],
41                 [-2.0,  4.0,  0.0 ],
42                 [ 2.0, -4.0,  0.0 ],
43                 [ 4.0,  4.0,  0.0 ] );
44
45 my $ctrlpoints = pack "d12", map { @$_ } @points;
46
47 sub init {
48         
49         glViewport(0,0,800,600);
50         glMatrixMode(GL_PROJECTION());
51         glLoadIdentity();
52
53         glFrustum (-0.1,0.1,-0.075,0.075,0.3,100.0 );
54         
55         glMatrixMode(GL_MODELVIEW());
56         glLoadIdentity();
57         
58         glTranslate(0,0,-30);
59
60         glClearColor(0.0, 0.0, 0.0, 0.0);       
61         glShadeModel(GL_FLAT());
62         glMap1(GL_MAP1_VERTEX_3(), 0.0, 1.0, 3, 4, $ctrlpoints);
63         glEnable(GL_MAP1_VERTEX_3());
64 }
65
66 sub display {
67         glClear(GL_COLOR_BUFFER_BIT);
68         glColor(1.0,1.0,1.0);
69         glBegin(GL_LINE_STRIP);
70                 for my $i ( 0 .. 30 ) {
71                         glEvalCoord1($i/30);
72                 }
73         glEnd();
74
75         glPointSize(5);
76         glColor(1.0,1.0,0);
77         glBegin(GL_POINTS);
78                 for my $i ( 0 .. 3 ) {
79                         glVertex( @{$points[$i]} );
80                 }
81         glEnd();
82         $app->sync();
83 }
84
85 init();
86 display();
87
88 $app->loop({ SDL_QUIT() => sub { exit(); } });
89