5 # Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
7 # ------------------------------------------------------------------------------
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 # ------------------------------------------------------------------------------
25 # Please feel free to send questions, suggestions or improvements to:
38 my $arg_screen_width =640;
39 my $arg_screen_height=512;
44 "width:i" => \$arg_screen_width,
45 "height:i" => \$arg_screen_height,
46 "fullscreen!" => \$arg_fullscreen,
49 Usage $0 -w 800 -h 600 -d 10 --fullscreen
52 #/* rotation angle for the triangle. */
55 #/* rotation angle for the quadrilateral. */
66 my $app = new SDL::App ( -title => "Jeff Molofee's GL Code Tutorial ... NeHe '99",
68 -width => $arg_screen_width,
69 -height =>$arg_screen_height,
72 $app->fullscreen() if $arg_fullscreen;
76 my $event = new SDL::Event;
77 $event->set(SDL_SYSWMEVENT,SDL_IGNORE);#
81 InitGL($arg_screen_width, $arg_screen_height);
94 if ( $event->type == SDL_QUIT ) {
98 if ( $event->type == SDL_KEYDOWN ) {
99 if ( $event->key_sym == SDLK_ESCAPE ) {
111 #########################################################################
112 #Pretty much in original form, but 'Perlised'
120 my ($Width, $Height)=@_;
122 glViewport(0, 0, $Width, $Height);
123 glClearColor(0.0, 0.0, 0.0, 0.0); # This Will Clear The Background Color To Black
124 glClearDepth(1.0); # Enables Clearing Of The Depth Buffer
125 glDepthFunc(GL_LESS); # The Type Of Depth Test To Do
126 glEnable(GL_DEPTH_TEST); # Enables Depth Testing
127 glShadeModel(GL_SMOOTH); # Enables Smooth Color Shading
129 glMatrixMode(GL_PROJECTION);
130 glLoadIdentity(); # Reset The Projection Matrix
132 gluPerspective(45.0, $Width/$Height, 0.1, 100.0); # Calculate The Aspect Ratio Of The Window
134 glMatrixMode(GL_MODELVIEW);
139 # The main drawing function.
142 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); # Clear The Screen And The Depth Buffer
143 glLoadIdentity(); # Reset The View
145 glTranslate(-1.5,0.0,-6.0); # Move Left 1.5 Units And Into The Screen 6.0
147 glRotate($rtri,0.0,1.0,0.0); # Rotate The Triangle On The Y axis
148 # draw a triangle (in smooth coloring mode)
149 glBegin(GL_POLYGON); # start drawing a polygon
150 glColor(1.0,0.0,0.0); # Set The Color To Red
151 glVertex( 0.0, 1.0, 0.0); # Top
152 glColor(0.0,1.0,0.0); # Set The Color To Green
153 glVertex( 1.0,-1.0, 0.0); # Bottom Right
154 glColor(0.0,0.0,1.0); # Set The Color To Blue
155 glVertex(-1.0,-1.0, 0.0); # Bottom Left
156 glEnd(); # we're done with the polygon (smooth color interpolation)
158 glLoadIdentity(); # make sure we're no longer rotated.
159 glTranslate(1.5,0.0,-6.0); # Move Right 3 Units, and back into the screen 6.0
161 glRotate($rquad,1.0,0.0,0.0); # Rotate The Quad On The X axis
162 # draw a square (quadrilateral)
163 glColor(0.5,0.5,1.0); # set color to a blue shade.
164 glBegin(GL_QUADS); # start drawing a polygon (4 sided)
165 glVertex(-1.0, 1.0, 0.0); # Top Left
166 glVertex( 1.0, 1.0, 0.0); # Top Right
167 glVertex( 1.0,-1.0, 0.0); # Bottom Right
168 glVertex(-1.0,-1.0, 0.0); # Bottom Left
169 glEnd(); # done with the polygon
171 $rtri+=15.0; # Increase The Rotation Variable For The Triangle
172 $rquad-=15.0; # Decrease The Rotation Variable For The Quad