PageRenderTime 37ms CodeModel.GetById 21ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/t_backcompat/OpenGL/test1.pl

http://github.com/PerlGameDev/SDL
Perl | 94 lines | 67 code | 23 blank | 4 comment | 9 complexity | 4d1c021464f39d5efe6a13c5451e8467 MD5 | raw file
 1#!/usr/bin/env perl
 2
 3use SDL;
 4use SDLx::App;
 5use SDL::Surface;
 6use SDL::Event;
 7use SDL::OpenGL;
 8use SDL::OpenGL::Constants;
 9
10#for ( keys %main:: ) {
11#	print "$_\n";
12#}
13
14print "Starting $0\n";
15
16my $app = SDLx::App->new( -w => 800, -h => 600, -d => 16, -gl => 1 );
17
18print "Initializing OpenGL settings\n";
19printf "%-24s%s\n", "GL_RED_SIZE ",     $app->attribute( SDL_GL_RED_SIZE() );
20printf "%-24s%s\n", "GL_GREEN_SIZE ",   $app->attribute( SDL_GL_GREEN_SIZE() );
21printf "%-24s%s\n", "GL_BLUE_SIZE ",    $app->attribute( SDL_GL_BLUE_SIZE() );
22printf "%-24s%s\n", "GL_DEPTH_SIZE ",   $app->attribute( SDL_GL_DEPTH_SIZE() );
23printf "%-24s%s\n", "GL_DOUBLEBUFFER ", $app->attribute( SDL_GL_DOUBLEBUFFER() );
24
25sub DrawScene {
26
27	glClear( GL_DEPTH_BUFFER_BIT() | GL_COLOR_BUFFER_BIT() );
28
29	glLoadIdentity();
30
31	glTranslate( -1.5, 0, -6 );
32
33	glColor( 1, 1, 1 );
34
35	glBegin( GL_TRIANGLES() );
36	glColor( 1, 0, 0 ) if (@_);
37	glVertex( 0, 1, 0 );
38	glColor( 0, 1, 0 ) if (@_);
39	glVertex( -1, -1, 0 );
40	glColor( 0, 0, 1 ) if (@_);
41	glVertex( 1, -1, 0 );
42	glEnd();
43
44	glTranslate( 3, 0, 0 );
45
46	glBegin( GL_QUADS() );
47	glColor( 1, 0, 0 ) if (@_);
48	glVertex( -1, 1, 0 );
49	glColor( 0, 1, 0 ) if (@_);
50	glVertex( 1, 1, 0 );
51	glColor( 0, 0, 1 ) if (@_);
52	glVertex( 1, -1, 0 );
53	glColor( 1, 1, 0 ) if (@_);
54	glVertex( -1, -1, 0 );
55	glEnd();
56}
57
58sub DrawColorScene {
59	DrawScene 'with color';
60}
61
62sub InitView {
63	glViewport( 0, 0, 800, 600 );
64
65	glMatrixMode( GL_PROJECTION() );
66	glLoadIdentity();
67
68	if (@_) {
69		gluPerspective( 45.0, 4 / 3, 0.1, 100.0 );
70	} else {
71		glFrustum( -0.1, 0.1, -0.075, 0.075, 0.175, 100.0 );
72	}
73
74	glMatrixMode( GL_MODELVIEW() );
75	glLoadIdentity();
76}
77
78InitView();
79
80DrawScene();
81
82$app->sync();
83
84$toggle = 1;
85
86$app->loop(
87	{   SDL_QUIT()    => sub { exit(0); },
88		SDL_KEYDOWN() => sub {
89			$toggle = ($toggle) ? 0 : 1;
90			($toggle) ? DrawScene() : DrawColorScene();
91			$app->sync();
92		},
93	}
94);