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,
36 my $app = new SDL::App ( -title => "Jeff Molofee's GL Code Tutorial ... NeHe '99",
38 -width => $arg_screen_width,
39 -height =>$arg_screen_height,
43 $app->fullscreen() if $arg_fullscreen;
47 my $event = new SDL::Event;
48 $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
114 # draw a triangle (in smooth coloring mode)
115 glBegin(GL_POLYGON); # start drawing a polygon
116 glColor(1.0,0.0,0.0); # Set The Color To Red
117 glVertex( 0.0, 1.0, 0.0); # Top
118 glColor(0.0,1.0,0.0); # Set The Color To Green
119 glVertex( 1.0,-1.0, 0.0); # Bottom Right
120 glColor(0.0,0.0,1.0); # Set The Color To Blue
121 glVertex(-1.0,-1.0, 0.0); # Bottom Left
122 glEnd(); # we're done with the polygon (smooth color interpolation)
124 glTranslate(3.0,0.0,0.0); # Move Right 3 Units
126 # draw a square (quadrilateral)
127 glColor(0.5,0.5,1.0); # set color to a blue shade.
128 glBegin(GL_QUADS); # start drawing a polygon (4 sided)
129 glVertex(-1.0, 1.0, 0.0); # Top Left
130 glVertex( 1.0, 1.0, 0.0); # Top Right
131 glVertex( 1.0,-1.0, 0.0); # Bottom Right
132 glVertex(-1.0,-1.0, 0.0); # Bottom Left
133 glEnd(); # done with the polygon