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;
43 "width:i" => \$arg_screen_width,
44 "height:i" => \$arg_screen_height,
45 "fullscreen!" => \$arg_fullscreen,
57 my $app = new SDL::App ( -title => "Jeff Molofee's GL Code Tutorial ... NeHe '99",
59 -width => $arg_screen_width,
60 -height =>$arg_screen_height,
65 $app->fullscreen() if ($arg_fullscreen);
69 my $event = new SDL::Event;
70 $event->set(SDL_SYSWMEVENT,SDL_IGNORE);#
72 InitGL($arg_screen_width, $arg_screen_height);
84 if ( $event->type == SDL_QUIT ) {
88 if ( $event->type == SDL_KEYDOWN ) {
89 if ( $event->key_sym == SDLK_ESCAPE ) {
101 #########################################################################
102 #Pretty much in original form, but 'Perlised'
107 my ($Width, $Height)=@_;
109 glViewport(0, 0, $Width, $Height);
110 glClearColor(0.0, 0.0, 0.0, 0.0); # This Will Clear The Background Color To Black
111 glClearDepth(1.0); # Enables Clearing Of The Depth Buffer
112 glDepthFunc(GL_LESS()); # The Type Of Depth Test To Do
113 glEnable(GL_DEPTH_TEST()); # Enables Depth Testing
114 glShadeModel(GL_SMOOTH()); # Enables Smooth Color Shading
116 glMatrixMode(GL_PROJECTION());
117 glLoadIdentity(); # Reset The Projection Matrix
119 gluPerspective(45.0, $Width/$Height, 0.1, 100.0); # Calculate The Aspect Ratio Of The Window
121 glMatrixMode(GL_MODELVIEW());
126 # The main drawing function.
129 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); # Clear The Screen And The Depth Buffer
130 glLoadIdentity(); # Reset The View
132 glTranslate(-1.5,0.0,-6.0); # Move Left 1.5 Units And Into The Screen 6.0
135 glBegin(GL_POLYGON); # start drawing a polygon
136 glVertex( 0.0, 1.0, 0.0); # Top
137 glVertex( 1.0,-1.0, 0.0); # Bottom Right
138 glVertex(-1.0,-1.0, 0.0); # Bottom Left
139 glEnd(); # we're done with the polygon
141 glTranslate(3.0,0.0,0.0); # Move Right 3 Units
143 # draw a square (quadrilateral)
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