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:
37 my $arg_screen_width =640;
38 my $arg_screen_height=512;
42 "width:i" => \$arg_screen_width,
43 "height:i" => \$arg_screen_height,
44 "fullscreen!" => \$arg_fullscreen,
55 my $app = new SDL::App ( -title => "Jeff Molofee's GL Code Tutorial ... NeHe '99",
57 -width => $arg_screen_width,
58 -height =>$arg_screen_height,
62 $app->fullscreen() if $arg_fullscreen;
66 my $event = new SDL::Event;
67 $event->set(SDL_SYSWMEVENT,SDL_IGNORE);#
71 InitGL($arg_screen_width, $arg_screen_height);
83 if ( $event->type == SDL_QUIT ) {
87 if ( $event->type == SDL_KEYDOWN ) {
88 if ( $event->key_sym == SDLK_ESCAPE ) {
100 #########################################################################
101 #Pretty much in original form, but 'Perlised'
106 my ($Width, $Height)=@_;
108 glViewport(0, 0, $Width, $Height);
109 glClearColor(0.0, 0.0, 0.0, 0.0); # This Will Clear The Background Color To Black
110 glClearDepth(1.0); # Enables Clearing Of The Depth Buffer
111 glDepthFunc(GL_LESS); # The Type Of Depth Test To Do
112 glEnable(GL_DEPTH_TEST); # Enables Depth Testing
113 glShadeModel(GL_SMOOTH); # Enables Smooth Color Shading
115 glMatrixMode(GL_PROJECTION);
116 glLoadIdentity(); # Reset The Projection Matrix
118 gluPerspective(45.0, $Width/$Height, 0.1, 100.0); # Calculate The Aspect Ratio Of The Window
120 glMatrixMode(GL_MODELVIEW);
125 # The main drawing function.
128 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); # Clear The Screen And The Depth Buffer
129 glLoadIdentity(); # Reset The View
131 glTranslate(-1.5,0.0,-6.0); # Move Left 1.5 Units And Into The Screen 6.0
133 # draw a triangle (in smooth coloring mode)
134 glBegin(GL_POLYGON); # start drawing a polygon
135 glColor(1.0,0.0,0.0); # Set The Color To Red
136 glVertex( 0.0, 1.0, 0.0); # Top
137 glColor(0.0,1.0,0.0); # Set The Color To Green
138 glVertex( 1.0,-1.0, 0.0); # Bottom Right
139 glColor(0.0,0.0,1.0); # Set The Color To Blue
140 glVertex(-1.0,-1.0, 0.0); # Bottom Left
141 glEnd(); # we're done with the polygon (smooth color interpolation)
143 glTranslate(3.0,0.0,0.0); # Move Right 3 Units
145 # draw a square (quadrilateral)
146 glColor(0.5,0.5,1.0); # set color to a blue shade.
147 glBegin(GL_QUADS); # start drawing a polygon (4 sided)
148 glVertex(-1.0, 1.0, 0.0); # Top Left
149 glVertex( 1.0, 1.0, 0.0); # Top Right
150 glVertex( 1.0,-1.0, 0.0); # Bottom Right
151 glVertex(-1.0,-1.0, 0.0); # Bottom Left
152 glEnd(); # done with the polygon