2 # This code was created by Jeff Molofee '99
3 # (ported to SDL by Sam Lantinga '2000)
4 # (ported to Perl/SDL by Wayne Keenan '2000)
6 # If you've found this code useful, please let me know.
8 # Visit me at www.demonews.com/hosted/nehe
18 my $arg_screen_width =640;
19 my $arg_screen_height=512;
23 "width:i" => \$arg_screen_width,
24 "height:i" => \$arg_screen_height,
25 "fullscreen!" => \$arg_fullscreen,
37 my $app = new SDL::App ( -title => "Jeff Molofee's GL Code Tutorial ... NeHe '99",
39 -width => $arg_screen_width,
40 -height =>$arg_screen_height,
45 $app->fullscreen() if ($arg_fullscreen);
49 my $event = new SDL::Event;
50 $event->set(SDL_SYSWMEVENT,SDL_IGNORE);#
52 InitGL($arg_screen_width, $arg_screen_height);
64 if ( $event->type == SDL_QUIT ) {
68 if ( $event->type == SDL_KEYDOWN ) {
69 if ( $event->key_sym == SDLK_ESCAPE ) {
81 #########################################################################
82 #Pretty much in original form, but 'Perlised'
87 my ($Width, $Height)=@_;
89 glViewport(0, 0, $Width, $Height);
90 glClearColor(0.0, 0.0, 0.0, 0.0); # This Will Clear The Background Color To Black
91 glClearDepth(1.0); # Enables Clearing Of The Depth Buffer
92 glDepthFunc(GL_LESS()); # The Type Of Depth Test To Do
93 glEnable(GL_DEPTH_TEST()); # Enables Depth Testing
94 glShadeModel(GL_SMOOTH()); # Enables Smooth Color Shading
96 glMatrixMode(GL_PROJECTION());
97 glLoadIdentity(); # Reset The Projection Matrix
99 gluPerspective(45.0, $Width/$Height, 0.1, 100.0); # Calculate The Aspect Ratio Of The Window
101 glMatrixMode(GL_MODELVIEW());
106 # The main drawing function.
109 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); # Clear The Screen And The Depth Buffer
110 glLoadIdentity(); # Reset The View
112 glTranslate(-1.5,0.0,-6.0); # Move Left 1.5 Units And Into The Screen 6.0
115 glBegin(GL_POLYGON); # start drawing a polygon
116 glVertex( 0.0, 1.0, 0.0); # Top
117 glVertex( 1.0,-1.0, 0.0); # Bottom Right
118 glVertex(-1.0,-1.0, 0.0); # Bottom Left
119 glEnd(); # we're done with the polygon
121 glTranslate(3.0,0.0,0.0); # Move Right 3 Units
123 # draw a square (quadrilateral)
124 glBegin(GL_QUADS); # start drawing a polygon (4 sided)
125 glVertex(-1.0, 1.0, 0.0); # Top Left
126 glVertex( 1.0, 1.0, 0.0); # Top Right
127 glVertex( 1.0,-1.0, 0.0); # Bottom Right
128 glVertex(-1.0,-1.0, 0.0); # Bottom Left
129 glEnd(); # done with the polygon