File: double.pl

package info (click to toggle)
libopengl-perl 0.7000%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 2,308 kB
  • sloc: perl: 10,178; ansic: 8,576; makefile: 113
file content (75 lines) | stat: -rwxr-xr-x 1,813 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/local/bin/perl
#
#           double
#
#  This program demonstrates double buffering for 
#  flicker-free animation.  
#  Adapted from "double", chapter 1, listing 1-3,
#  page 17, OpenGL Programming Guide 

BEGIN{ unshift(@INC,"../blib"); }  # in case OpenGL is built but not installed
BEGIN{ unshift(@INC,"../blib/arch"); } # 5.002 gamma needs this
BEGIN{ unshift(@INC,"../blib/lib");  } # 5.002 gamma needs this
use OpenGL;
 
$spin = 0.0;


sub myReshape {
    # glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho (-50.0, 50.0, -50.0,50.0,-1.0,1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity ();
}

sub display{
    glClear(GL_COLOR_BUFFER_BIT);

    glPushMatrix();
    glRotatef($spin, 0.0, 0.0, 1.0);
    ($x,$y) = glpXQueryPointer;
    glRectf(-25.0, -25.0, 25+$x/10, 25+$y/10);
    glPopMatrix();

    glFlush();
    glXSwapBuffers;
}
$increment=2.0;
sub spinDisplay {
    $spin = $spin + $increment;
    if ($spin > 360.0) {
	$spin = $spin - 360.0;
    }
    display();
}

glpOpenWindow(attributes=>[GLX_RGBA,GLX_DOUBLEBUFFER]);
glClearColor(0,0,0,1);
glColor3f (1.0, 1.0, 1.0);
glShadeModel (GL_FLAT);
myReshape();
$cb{&ConfigureNotify} = sub { local($e,$w,$h)=@_;glViewport(0,0,$w,$h);
			 # print "viewport $w,$h\n";
			};
$cb{&KeyPress} = sub { # print "@_[1] ",ord(@_[1])," keypress @_\n";
		      local($ss); &$ss(@_[1]) if ($ss=$kcb{@_[1]}); };
$kcb{'q'} = $kcb{'Q'} = $kcb{"\033"} = sub{ print "Good-Bye\n"; exit 0;};
sub setincrement{$increment = $_[0];}
foreach $i (0..9){
	$kcb{"$i"}=\&setincrement;
}
#print "cn=",&ConfigureNotify,"\n";
#print "kn=",KeyPress,"\n";

while(1) {
	spinDisplay();
	while($p=XPending) {
		#print $p,"\n"; 
		@e=&glpXNextEvent;
		#print("e=@e\n");
		&$s(@e) if($s=$cb{$e[0]});
		#print "doncb\n" if ($s);
	}
}