File: test1.pl

package info (click to toggle)
sdlperl 1.20.3dfsg-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,808 kB
  • ctags: 2,171
  • sloc: perl: 7,394; ansic: 232; makefile: 76; sh: 1
file content (92 lines) | stat: -rwxr-xr-x 1,765 bytes parent folder | download | duplicates (3)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env perl

use SDL;
use SDL::App;
use SDL::Surface;
use SDL::Event;
use SDL::OpenGL;

#for ( keys %main:: ) {
#	print "$_\n";
#}

print "Starting $0\n";

my $app = new SDL::App	-w => 800, -h => 600, -d => 16, -gl => 1;

print "Initializing OpenGL settings\n";
printf "%-24s%s\n", "GL_RED_SIZE ", $app->attribute( SDL_GL_RED_SIZE() );
printf "%-24s%s\n", "GL_GREEN_SIZE ", $app->attribute( SDL_GL_GREEN_SIZE());
printf "%-24s%s\n", "GL_BLUE_SIZE ", $app->attribute( SDL_GL_BLUE_SIZE() );
printf "%-24s%s\n", "GL_DEPTH_SIZE ", $app->attribute( SDL_GL_DEPTH_SIZE() );
printf "%-24s%s\n", "GL_DOUBLEBUFFER ", $app->attribute( SDL_GL_DOUBLEBUFFER() );

sub DrawScene {

	glClear( GL_DEPTH_BUFFER_BIT() 
		| GL_COLOR_BUFFER_BIT());

	glLoadIdentity();

	glTranslate(-1.5,0,-6);
	
	glColor(1,1,1);

	glBegin(GL_TRIANGLES());
		glColor(1,0,0) if (@_);
		glVertex(0,1,0);
		glColor(0,1,0) if (@_);
		glVertex(-1,-1,0);
		glColor(0,0,1) if (@_);
		glVertex(1,-1,0);
	glEnd();

	glTranslate(3,0,0);

	glBegin(GL_QUADS());
		glColor(1,0,0) if (@_);
		glVertex(-1,1,0);
		glColor(0,1,0) if (@_);
		glVertex(1,1,0);
		glColor(0,0,1) if (@_);
		glVertex(1,-1,0);
		glColor(1,1,0) if (@_);
		glVertex(-1,-1,0);
	glEnd();
}

sub DrawColorScene {
	DrawScene 'with color';
}

sub InitView {
	glViewport(0,0,800,600);

	glMatrixMode(GL_PROJECTION());
	glLoadIdentity();

	if ( @_ ) {
		glPerspective(45.0,4/3,0.1,100.0);
	} else {
		glFrustum(-0.1,0.1,-0.075,0.075,0.175,100.0);
	}

	glMatrixMode(GL_MODELVIEW());
	glLoadIdentity();
}

InitView();

DrawScene();

$app->sync();

$toggle = 1;

$app->loop( { 
	SDL_QUIT() => sub { exit(0); },
	SDL_KEYDOWN() => sub { 	$toggle = ($toggle) ? 0 : 1; 
				($toggle) ? DrawScene() : DrawColorScene(); 
				$app->sync();
				},
	} );