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;
24 "width:i" => \$arg_screen_width,
25 "height:i" => \$arg_screen_height,
26 "fullscreen!" => \$arg_fullscreen,
29 Usage $0 -w 800 -h 600 -d 10 --fullscreen
32 #/* rotation angle for the triangle. */
35 #/* rotation angle for the quadrilateral. */
46 my $app = new SDL::App ( -title => "Jeff Molofee's GL Code Tutorial ... NeHe '99",
48 -width => $arg_screen_width,
49 -height =>$arg_screen_height,
52 $app->fullscreen() if $arg_fullscreen;
56 my $event = new SDL::Event;
57 $event->set(SDL_SYSWMEVENT,SDL_IGNORE);#
61 InitGL($arg_screen_width, $arg_screen_height);
74 if ( $event->type == SDL_QUIT ) {
78 if ( $event->type == SDL_KEYDOWN ) {
79 if ( $event->key_sym == SDLK_ESCAPE ) {
91 #########################################################################
92 #Pretty much in original form, but 'Perlised'
100 my ($Width, $Height)=@_;
102 glViewport(0, 0, $Width, $Height);
103 glClearColor(0.0, 0.0, 0.0, 0.0); # This Will Clear The Background Color To Black
104 glClearDepth(1.0); # Enables Clearing Of The Depth Buffer
105 glDepthFunc(GL_LESS); # The Type Of Depth Test To Do
106 glEnable(GL_DEPTH_TEST); # Enables Depth Testing
107 glShadeModel(GL_SMOOTH); # Enables Smooth Color Shading
109 glMatrixMode(GL_PROJECTION);
110 glLoadIdentity(); # Reset The Projection Matrix
112 gluPerspective(45.0, $Width/$Height, 0.1, 100.0); # Calculate The Aspect Ratio Of The Window
114 glMatrixMode(GL_MODELVIEW);
119 # The main drawing function.
122 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); # Clear The Screen And The Depth Buffer
123 glLoadIdentity(); # Reset The View
125 glTranslate(-1.5,0.0,-6.0); # Move Left 1.5 Units And Into The Screen 6.0
127 glRotate($rtri,0.0,1.0,0.0); # Rotate The Triangle On The Y axis
128 # draw a triangle (in smooth coloring mode)
129 glBegin(GL_POLYGON); # start drawing a polygon
130 glColor(1.0,0.0,0.0); # Set The Color To Red
131 glVertex( 0.0, 1.0, 0.0); # Top
132 glColor(0.0,1.0,0.0); # Set The Color To Green
133 glVertex( 1.0,-1.0, 0.0); # Bottom Right
134 glColor(0.0,0.0,1.0); # Set The Color To Blue
135 glVertex(-1.0,-1.0, 0.0); # Bottom Left
136 glEnd(); # we're done with the polygon (smooth color interpolation)
138 glLoadIdentity(); # make sure we're no longer rotated.
139 glTranslate(1.5,0.0,-6.0); # Move Right 3 Units, and back into the screen 6.0
141 glRotate($rquad,1.0,0.0,0.0); # Rotate The Quad On The X axis
142 # draw a square (quadrilateral)
143 glColor(0.5,0.5,1.0); # set color to a blue shade.
144 glBegin(GL_QUADS); # start drawing a polygon (4 sided)
145 glVertex(-1.0, 1.0, 0.0); # Top Left
146 glVertex( 1.0, 1.0, 0.0); # Top Right
147 glVertex( 1.0,-1.0, 0.0); # Bottom Right
148 glVertex(-1.0,-1.0, 0.0); # Bottom Left
149 glEnd(); # done with the polygon
151 $rtri+=15.0; # Increase The Rotation Variable For The Triangle
152 $rquad-=15.0; # Decrease The Rotation Variable For The Quad