3 <h3 id="TOP">Index</h3>
5 <ul><li><a href="#NAME">NAME</a></li>
6 <li><a href="#CATEGORY">CATEGORY</a></li>
7 <li><a href="#DESCRIPTION">DESCRIPTION</a>
8 <ul><li><a href="#EXAMPLE">EXAMPLE</a></li>
11 <li><a href="#SEE_ALSO">SEE ALSO</a></li>
12 <li><a href="#AUTHORS">AUTHORS</a>
17 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
18 <div id="NAME_CONTENT">
19 <p>SDL::Cookbook::OpenGL - Using SDL with OpenGL</p>
22 <h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
23 <div id="CATEGORY_CONTENT">
27 <h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
28 <div id="DESCRIPTION_CONTENT">
29 <p>As of release 2.5 SDL no longer maintains it's own bindings of openGL. Support for openGL has been moved over to a more mature implementation. </p>
30 <p>This implementation is the POGL project. <a href="http://search.cpan.org/perldoc?OpenGL">OpenGL</a> is faster and more complete; and works with SDL seemlessly.</p>
33 <h2 id="EXAMPLE">EXAMPLE</h2>
34 <div id="EXAMPLE_CONTENT">
35 <p>Expanded from Floyd-ATC's OpenGL example.</p>
50 <p>You can use OpenGL as needed here.</p>
51 <pre> my ($SDLAPP, $WIDTH, $HEIGHT, $SDLEVENT);
56 $SDLAPP = SDLx::App->new(title => "Opengl App", width => $WIDTH, height => $HEIGHT, gl => 1);
57 $SDLEVENT = SDL::Event->new;
60 <p>SDLx::App can start an OpenGL application with the parameter gl => 1.</p>
61 <pre> glEnable(GL_DEPTH_TEST);
62 glMatrixMode(GL_PROJECTION);
64 gluPerspective(60, $WIDTH / $HEIGHT, 1, 1000);
65 glTranslatef(0, 0, -20);
68 <p>Above we enable GL and set the correct prespective</p>
71 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
72 glRotatef(.1, 1, 1, 1);
78 <p>For SDLx::App sync handles the GL buffer clean.</p>
80 my ($color, $x, $y, $z);
84 glTranslatef($_ * 3, 0, 0);
97 my (@indices, @vertices, $face, $vertex, $index, $coords);
99 @indices = qw(4 5 6 7 1 2 6 5 0 1 5 4
100 0 3 2 1 0 4 7 3 2 3 7 6);
101 @vertices = ([-1, -1, -1], [ 1, -1, -1],
102 [ 1, 1, -1], [-1, 1, -1],
103 [-1, -1, 1], [ 1, -1, 1],
104 [ 1, 1, 1], [-1, 1, 1]);
108 foreach my $face (0..5) {
109 foreach my $vertex (0..3) {
110 $index = $indices[4 * $face + $vertex];
111 $coords = $vertices[$index];
113 glVertex3d(@$coords);
123 <p>Below we can use SDL::Events as normal:</p>
124 <pre> sub handlepolls {
127 SDL::Events::pump_events();
129 while (SDL::Events::poll_event($SDLEVENT)) {
130 $type = $SDLEVENT->type();
131 $key = ($type == 2 or $type == 3) ? $SDLEVENT->key_sym : "";
133 if ($type == 4) { printf("You moved the mouse! x=%s y=%s xrel=%s yrel=%s\n", $SDLEVENT->motion_x, $SDLEVENT->motion_y, $SDLEVENT->motion_xrel, $SDLEVENT->motion_yrel) }
134 elsif ($type == 2) { print "You are pressing $key\n" }
135 elsif ($type == 3) { print "You released $key\n" }
136 elsif ($type == 12) { exit }
137 else { print "TYPE $type UNKNOWN!\n" }
140 if ($key eq "q" or $key eq "escape") { exit }
150 <h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
151 <div id="SEE_ALSO_CONTENT">
152 <p><a href="http://search.cpan.org/perldoc?perl">perl</a> <a href="SDLx-App.html">SDLx::App</a> <a href="http://search.cpan.org/perldoc?OpenGL">OpenGL</a> </p>
155 <h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
156 <div id="AUTHORS_CONTENT">
157 <p>See <a href="/SDL.html#AUTHORS">/SDL.html#AUTHORS</a>.</p>