Updated -nogl patch to reflect video subsys changes
[supertux.git] / contrib / supertux-nogl.diff
1 #
2 #  SuperTux -nogl patch
3 #  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
4 #
5 #  This program is free software; you can redistribute it and/or
6 #  modify it under the terms of the GNU General Public License
7 #  as published by the Free Software Foundation; either version 2
8 #  of the License, or (at your option) any later version.
9 #
10 #  This program is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #  GNU General Public License for more details.
14 #
15 #  You should have received a copy of the GNU General Public License
16 #  along with this program; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 #
19 # -----------------------------------------------------------------------------
20 #
21 #  This patch allows running the game on systems without OpenGL support. 
22 #
23 #  It modifies the video portion of the SuperTux engine to render all graphics
24 #  with SDL functions only. Many features are removed from the video engine,
25 #  so don't expect much.
26 #
27 #  Note that the patched sources will need an additional library, SDL_gfx, to 
28 #  compile.
29 #
30 #  Installing the patch should be pretty straightforward. Simply run the
31 #  following command prior to running autogen.sh and configure:
32 #
33 #  patch -p1 < contrib/supertux-nogl.diff
34 #
35 #  This patch works for revision 3294. It may break for later revisions.
36 #
37 # -----------------------------------------------------------------------------
38 diff -Naur supertux/INSTALL supertux-nogl/INSTALL
39 --- supertux/INSTALL    2006-03-03 21:49:07.000000000 +0100
40 +++ supertux-nogl/INSTALL       2006-04-07 04:13:00.000000000 +0200
41 @@ -1,7 +1,7 @@
42  - Install instructions for SuperTux -
43  http://supertux.berlios.de/
44  
45 -Last update: October 11, 2005 by Ondra Hosek
46 +Last update: March 4, 2006 by Christoph Sommer
47  
48  BINARIES
49  --------
50 @@ -34,17 +34,15 @@
51      Download: ftp://ftp.perforce.com/pub/jam
52      Homepage: http://www.perforce.com/jam/jam.html
53  
54 -* OpenGL headers and libraries
55 -    opengl libraries and headers are specific to your graphics card. Make sure
56 -    that you have hardware accelerated opengl drivers installed. Software
57 -    renderers like Mesa will make supertux unplayable slow.
58 -
59  * SDL 1.2.5 or later (1.2.8 is recommended on MacOS/X)
60      http://www.libsdl.org
61  
62  * SDL_image (any version)
63      http://www.libsdl.org/projects/SDL_image
64  
65 +* SDL_gfx (2.0.13 or later)
66 +    http://www.ferzkopp.net/Software/SDL_gfx-2.0/
67 +
68  * PhysicsFS (1.0.0, the development branch 1.1.x is buggy and does not work,
69               1.2.0 and later should work when it is released)
70      http://www.icculus.org/physfs
71 diff -Naur supertux/README supertux-nogl/README
72 --- supertux/README     2006-03-03 20:43:38.000000000 +0100
73 +++ supertux-nogl/README        2006-04-07 04:13:00.000000000 +0200
74 @@ -2,7 +2,7 @@
75  - An introduction for SuperTux -
76  http://supertux.berlios.de/
77  
78 -Last update: October 13, 2005
79 +Last update: March 4, 2006 by Christoph Sommer
80  
81  DESCRIPTION
82  -----------
83 @@ -75,10 +75,9 @@
84    Also, notice that SuperTux saves the options, so it's often enough to
85    specify them once.
86  
87 -  The game uses OpenGL to render the graphics. You will either need a CPU
88 -  with about 10 GHz or an accelerated video card with the vendor's drivers.
89 -  (On Linux, the team recommends using cards from NVidia with the proprietary
90 -  drivers, but ATI or another verndor should do.)
91 +  The game uses SDL to render the graphics. You will either need a CPU
92 +  with about 1 GHz or go get the original version of SuperTux which uses
93 +  OpenGL.
94  
95  
96  PLAYING THE GAME
97 diff -Naur supertux/configure.ac supertux-nogl/configure.ac
98 --- supertux/configure.ac       2006-03-03 20:43:38.000000000 +0100
99 +++ supertux-nogl/configure.ac  2006-04-07 04:13:00.000000000 +0200
100 @@ -11,7 +11,7 @@
101  
102  dnl Process this file with autoconf to produce a configure script.
103  AC_PREREQ([2.54])
104 -AC_INIT(supertux, 0.2-svn)
105 +AC_INIT(supertux, 0.2-nogl-svn)
106  AC_CONFIG_SRCDIR([src/main.cpp])
107  AC_CONFIG_AUX_DIR([mk/autoconf])
108  AC_CANONICAL_TARGET
109 @@ -105,6 +105,14 @@
110          [AC_MSG_ERROR([Please install SDLImage >= 1.2.1])],
111          [$SDL_CFLAGS], [$SDL_LIBS])
112  
113 +dnl FIXME: This is far from perfect
114 +NP_FINDLIB([SDLGFX], [SDL_gfx], [SDL_gfx >= 2.0.13],
115 +        NP_LANG_PROGRAM([#include <SDL_rotozoom.h>], [0;]),
116 +        [], [-lSDL_gfx],
117 +        [],
118 +        [AC_MSG_ERROR([Please install SDL_gfx >= 2.0.13])],
119 +        [$SDL_CFLAGS], [$SDL_LIBS])
120 +
121  NP_FINDLIB([PHYSFS], [physfs], [physfs >= 1.0.0],
122          NP_LANG_PROGRAM([
123  #include <stdio.h>
124 @@ -124,11 +132,6 @@
125           [AC_MSG_ERROR([Please intall OpenAL])],
126           [], [])
127  
128 -AX_CHECK_GL
129 -if test "$no_gl" = "yes"; then
130 -  AC_MSG_ERROR([Please install opengl libraries and headers])
131 -fi
132 -
133  dnl Checks for library functions.
134  AC_CHECK_FUNCS(mkdir strdup strstr)
135  
136 diff -Naur supertux/src/Jamfile supertux-nogl/src/Jamfile
137 --- supertux/src/Jamfile        2006-03-03 20:34:49.000000000 +0100
138 +++ supertux-nogl/src/Jamfile   2006-04-07 04:11:50.000000000 +0200
139 @@ -24,7 +24,7 @@
140  Application supertux : $(sources) $(wrapper_objects) ;
141  C++Flags supertux : -DAPPDATADIR='\"$(appdatadir)\"' ;
142  LinkWith supertux : squirrel ;
143 -ExternalLibs supertux : SDL SDLIMAGE GL OPENAL VORBIS VORBISFILE OGG ICONV PHYSFS BINRELOC ;
144 +ExternalLibs supertux : SDL SDLIMAGE SDLGFX OPENAL VORBIS VORBISFILE OGG ICONV PHYSFS BINRELOC ;
145  Help supertux : "Build the supertux executable" ;
146  IncludeDir supertux : squirrel/include ;
147  
148 diff -Naur supertux/src/main.cpp supertux-nogl/src/main.cpp
149 --- supertux/src/main.cpp       2006-04-07 03:32:14.000000000 +0200
150 +++ supertux-nogl/src/main.cpp  2006-04-07 04:11:50.000000000 +0200
151 @@ -35,7 +35,6 @@
152  #include <physfs.h>
153  #include <SDL.h>
154  #include <SDL_image.h>
155 -#include <SDL_opengl.h>
156  
157  #include "gameconfig.hpp"
158  #include "resources.hpp"
159 @@ -266,44 +265,6 @@
160        ;
161  }
162  
163 -static void check_gl_error()
164 -{
165 -  GLenum glerror = glGetError();
166 -  std::string errormsg;
167 -  
168 -  if(glerror != GL_NO_ERROR) {
169 -    switch(glerror) {
170 -      case GL_INVALID_ENUM:
171 -        errormsg = "Invalid enumeration value";
172 -        break;
173 -      case GL_INVALID_VALUE:
174 -        errormsg = "Numeric argzment out of range";
175 -        break;
176 -      case GL_INVALID_OPERATION:
177 -        errormsg = "Invalid operation";
178 -        break;
179 -      case GL_STACK_OVERFLOW:
180 -        errormsg = "stack overflow";
181 -        break;
182 -      case GL_STACK_UNDERFLOW:
183 -        errormsg = "stack underflow";
184 -        break;
185 -      case GL_OUT_OF_MEMORY:
186 -        errormsg = "out of memory";
187 -        break;
188 -      case GL_TABLE_TOO_LARGE:
189 -        errormsg = "table too large";
190 -        break;
191 -      default:
192 -        errormsg = "unknown error number";
193 -        break;
194 -    }
195 -    std::stringstream msg;
196 -    msg << "OpenGL Error: " << errormsg;
197 -    throw std::runtime_error(msg.str());
198 -  }
199 -}
200 -
201  void init_video()
202  {
203    if(texture_manager != NULL)
204 @@ -314,7 +275,7 @@
205    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
206    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
207    
208 -  int flags = SDL_OPENGL;
209 +  int flags = SDL_SWSURFACE;
210    if(config->use_fullscreen)
211      flags |= SDL_FULLSCREEN;
212    int width = config->screenwidth;
213 @@ -344,24 +305,6 @@
214    }
215  #endif
216  
217 -  // setup opengl state and transform
218 -  glDisable(GL_DEPTH_TEST);
219 -  glDisable(GL_CULL_FACE);
220 -  glEnable(GL_TEXTURE_2D);
221 -  glEnable(GL_BLEND);
222 -  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
223 -
224 -  glViewport(0, 0, screen->w, screen->h);
225 -  glMatrixMode(GL_PROJECTION);
226 -  glLoadIdentity();
227 -  // logical resolution here not real monitor resolution
228 -  glOrtho(0, 800, 600, 0, -1.0, 1.0);
229 -  glMatrixMode(GL_MODELVIEW);
230 -  glLoadIdentity();
231 -  glTranslatef(0, 0, 0);
232 -
233 -  check_gl_error();
234 -
235    if(texture_manager != NULL)
236      texture_manager->reload_textures();
237    else
238 diff -Naur supertux/src/video/drawing_context.cpp supertux-nogl/src/video/drawing_context.cpp
239 --- supertux/src/video/drawing_context.cpp      2006-03-31 04:18:01.000000000 +0200
240 +++ supertux-nogl/src/video/drawing_context.cpp 2006-04-07 04:11:49.000000000 +0200
241 @@ -22,8 +22,6 @@
242  #include <cassert>
243  #include <iostream>
244  #include <SDL_image.h>
245 -#include <GL/gl.h>
246 -#include <GL/glu.h>
247  
248  #include "drawing_context.hpp"
249  #include "surface.hpp"
250 @@ -49,30 +47,20 @@
251  {
252    screen = SDL_GetVideoSurface();
253  
254 -  lightmap_width = screen->w / LIGHTMAP_DIV;
255 -  lightmap_height = screen->h / LIGHTMAP_DIV;
256 -  unsigned int width = next_po2(lightmap_width);
257 -  unsigned int height = next_po2(lightmap_height);
258 -
259 -  lightmap = new Texture(width, height, GL_RGB);
260 -
261 -  lightmap_uv_right = static_cast<float>(lightmap_width) / static_cast<float>(width);
262 -  lightmap_uv_bottom = static_cast<float>(lightmap_height) / static_cast<float>(height);
263 -  texture_manager->register_texture(lightmap);
264 -
265 +  target = NORMAL;
266    requests = &drawing_requests;
267  }
268  
269  DrawingContext::~DrawingContext()
270  {
271 -  texture_manager->remove_texture(lightmap);
272 -  delete lightmap;
273  }
274  
275  void
276  DrawingContext::draw_surface(const Surface* surface, const Vector& position,
277      int layer)
278  {
279 +  if(target != NORMAL) return;
280 +
281    assert(surface != 0);
282    
283    DrawingRequest request;
284 @@ -97,6 +85,8 @@
285  DrawingContext::draw_surface_part(const Surface* surface, const Vector& source,
286      const Vector& size, const Vector& dest, int layer)
287  {
288 +  if(target != NORMAL) return;
289 +
290    assert(surface != 0);
291  
292    DrawingRequest request;
293 @@ -136,6 +126,8 @@
294  DrawingContext::draw_text(const Font* font, const std::string& text,
295      const Vector& position, FontAlignment alignment, int layer)
296  {
297 +  if(target != NORMAL) return;
298 +
299    DrawingRequest request;
300  
301    request.type = TEXT;
302 @@ -157,6 +149,8 @@
303  DrawingContext::draw_center_text(const Font* font, const std::string& text,
304      const Vector& position, int layer)
305  {
306 +  if(target != NORMAL) return;
307 +
308    draw_text(font, text, Vector(position.x + SCREEN_WIDTH/2, position.y),
309        CENTER_ALLIGN, layer);
310  }
311 @@ -164,6 +158,8 @@
312  void
313  DrawingContext::draw_gradient(const Color& top, const Color& bottom, int layer)
314  {
315 +  if(target != NORMAL) return;
316 +
317    DrawingRequest request;
318  
319    request.type = GRADIENT;
320 @@ -185,6 +181,8 @@
321  DrawingContext::draw_filled_rect(const Vector& topleft, const Vector& size,
322                                   const Color& color, int layer)
323  {
324 +  if(target != NORMAL) return;
325 +
326    DrawingRequest request;
327  
328    request.type = FILLRECT;
329 @@ -218,23 +216,55 @@
330    delete surfacepartrequest;
331  }
332  
333 +namespace
334 +{
335 +  void fillrect(SDL_Surface* screen, float x, float y, float w, float h, int r, int g, int b, int a)
336 +  {
337 +    if(w < 0) {
338 +      x += w;
339 +      w = -w;
340 +    }
341 +    if(h < 0) {
342 +      y += h;
343 +      h = -h;
344 +    }
345 +
346 +    SDL_Rect src, rect;
347 +    SDL_Surface *temp = NULL;
348 +
349 +    rect.x = (int)x;
350 +    rect.y = (int)y;
351 +    rect.w = (int)w;
352 +    rect.h = (int)h;
353 +
354 +    if(a != 255) {
355 +      temp = SDL_CreateRGBSurface(screen->flags, rect.w, rect.h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
356 +
357 +      src.x = 0;
358 +      src.y = 0;
359 +      src.w = rect.w;
360 +      src.h = rect.h;
361 +
362 +      SDL_FillRect(temp, &src, SDL_MapRGB(screen->format, r, g, b));
363 +      SDL_SetAlpha(temp, SDL_SRCALPHA, a);
364 +      SDL_BlitSurface(temp,0,screen,&rect);
365 +      SDL_FreeSurface(temp);
366 +    } else {
367 +      SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, r, g, b));
368 +    }
369 +  }
370 +}
371 +
372  void
373  DrawingContext::draw_gradient(DrawingRequest& request)
374  {
375    GradientRequest* gradientrequest = (GradientRequest*) request.request_data;
376    const Color& top = gradientrequest->top;
377    const Color& bottom = gradientrequest->bottom;
378 -  
379 -  glDisable(GL_TEXTURE_2D);
380 -  glBegin(GL_QUADS);
381 -  glColor4f(top.red, top.green, top.blue, top.alpha);
382 -  glVertex2f(0, 0);
383 -  glVertex2f(SCREEN_WIDTH, 0);
384 -  glColor4f(bottom.red, bottom.green, bottom.blue, bottom.alpha);
385 -  glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT);
386 -  glVertex2f(0, SCREEN_HEIGHT);
387 -  glEnd();
388 -  glEnable(GL_TEXTURE_2D);
389 +
390 +  int width = 800;
391 +  int height = 600;
392 +  for(float y = 0; y < height; y += 2) ::fillrect(screen, 0, (int)y, width, 2, (int)(((float)(top.red-bottom.red)/(0-height)) * y + top.red), (int)(((float)(top.green-bottom.green)/(0-height)) * y + top.green), (int)(((float)(top.blue-bottom.blue)/(0-height)) * y + top.blue), 255);
393  
394    delete gradientrequest;
395  }
396 @@ -260,17 +290,12 @@
397    float w = fillrectrequest->size.x;
398    float h = fillrectrequest->size.y;
399  
400 -  glDisable(GL_TEXTURE_2D);
401 -  glColor4f(fillrectrequest->color.red, fillrectrequest->color.green,
402 -            fillrectrequest->color.blue, fillrectrequest->color.alpha);
403
404 -  glBegin(GL_QUADS);
405 -  glVertex2f(x, y);
406 -  glVertex2f(x+w, y);
407 -  glVertex2f(x+w, y+h);
408 -  glVertex2f(x, y+h);
409 -  glEnd();
410 -  glEnable(GL_TEXTURE_2D);
411 +  int r = static_cast<int>(fillrectrequest->color.red);
412 +  int g = static_cast<int>(fillrectrequest->color.green);
413 +  int b = static_cast<int>(fillrectrequest->color.blue);
414 +  int a = static_cast<int>(fillrectrequest->color.alpha);
415 +
416 +  ::fillrect(screen, x, y, w, h, r, g, b, a);
417  
418    delete fillrectrequest;
419  }
420 @@ -285,66 +310,10 @@
421    transformstack.clear();
422    target_stack.clear();
423  
424 -  bool use_lightmap = lightmap_requests.size() != 0;
425 -  
426 -  // PART1: create lightmap
427 -  if(use_lightmap) {
428 -    glViewport(0, screen->h - lightmap_height, lightmap_width, lightmap_height);
429 -    glMatrixMode(GL_PROJECTION);
430 -    glLoadIdentity();               
431 -    glOrtho(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1.0, 1.0);
432 -    glMatrixMode(GL_MODELVIEW);
433 -    glLoadIdentity();
434 -
435 -    //glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
436 -    glClearColor(0, 0, 0, 1);
437 -    glClear(GL_COLOR_BUFFER_BIT);
438 -    handle_drawing_requests(lightmap_requests);
439 -    lightmap_requests.clear();
440 -  
441 -    glDisable(GL_BLEND);
442 -    glBindTexture(GL_TEXTURE_2D, lightmap->get_handle());
443 -    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, screen->h - lightmap_height, lightmap_width, lightmap_height);
444 -
445 -    glViewport(0, 0, screen->w, screen->h);
446 -    glMatrixMode(GL_PROJECTION);
447 -    glLoadIdentity();               
448 -    glOrtho(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1.0, 1.0);
449 -    glMatrixMode(GL_MODELVIEW);    
450 -    glLoadIdentity();
451 -    glEnable(GL_BLEND);
452 -  }
453 -
454 -  //glClear(GL_COLOR_BUFFER_BIT);
455    handle_drawing_requests(drawing_requests);
456    drawing_requests.clear();
457  
458 -  if(use_lightmap) {
459 -    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
460 -
461 -    glBindTexture(GL_TEXTURE_2D, lightmap->get_handle());
462 -    glBegin(GL_QUADS);
463 -
464 -    glTexCoord2f(0, lightmap_uv_bottom);
465 -    glVertex2f(0, 0);
466 -
467 -    glTexCoord2f(lightmap_uv_right, lightmap_uv_bottom);
468 -    glVertex2f(SCREEN_WIDTH, 0);
469 -
470 -    glTexCoord2f(lightmap_uv_right, 0);
471 -    glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT);
472 -
473 -    glTexCoord2f(0, 0);
474 -    glVertex2f(0, SCREEN_HEIGHT);
475 -    
476 -    glEnd();
477 -
478 -    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
479 -  }
480 -
481 -  assert_gl("drawing");
482 -
483 -  SDL_GL_SwapBuffers();
484 +  SDL_Flip(screen);
485  }
486  
487  void
488 @@ -433,9 +402,5 @@
489  DrawingContext::set_target(Target target)
490  {
491    this->target = target;
492 -  if(target == LIGHTMAP)
493 -    requests = &lightmap_requests;
494 -  else
495 -    requests = &drawing_requests;
496  }
497  
498 diff -Naur supertux/src/video/drawing_context.hpp supertux-nogl/src/video/drawing_context.hpp
499 --- supertux/src/video/drawing_context.hpp      2006-03-03 20:34:27.000000000 +0100
500 +++ supertux-nogl/src/video/drawing_context.hpp 2006-04-07 04:11:49.000000000 +0200
501 @@ -23,7 +23,6 @@
502  #include <string>
503  #include <stdint.h>
504  
505 -#include <GL/gl.h>
506  #include <SDL.h>
507  #include <stdint.h>
508  #include <memory>
509 @@ -33,8 +32,9 @@
510  #include "font.hpp"
511  #include "color.hpp"
512  
513 +#include "glutil.hpp"
514 +
515  class Surface;
516 -class Texture;
517  
518  // some constants for predefined layer values
519  enum {
520 @@ -202,16 +202,12 @@
521    void draw_filled_rect(DrawingRequest& request);
522    
523    DrawingRequests drawing_requests;
524 -  DrawingRequests lightmap_requests;
525  
526    DrawingRequests* requests;
527  
528    SDL_Surface* screen;
529    Target target;
530    std::vector<Target> target_stack;
531 -  Texture* lightmap;
532 -  int lightmap_width, lightmap_height;
533 -  float lightmap_uv_right, lightmap_uv_bottom;
534  };
535  
536  #endif
537 diff -Naur supertux/src/video/glutil.hpp supertux-nogl/src/video/glutil.hpp
538 --- supertux/src/video/glutil.hpp       2006-03-21 16:13:11.000000000 +0100
539 +++ supertux-nogl/src/video/glutil.hpp  2006-04-07 04:11:49.000000000 +0200
540 @@ -21,45 +21,14 @@
541  
542  #include <sstream>
543  #include <stdexcept>
544 -#include <GL/gl.h>
545  
546 -static inline void assert_gl(const char* message)
547 -{
548 -#ifdef DEBUG
549 -  GLenum error = glGetError();
550 -  if(error != GL_NO_ERROR) {
551 -    std::ostringstream msg;
552 -    msg << "OpenGLError while '" << message << "': ";
553 -    switch(error) {
554 -      case GL_INVALID_ENUM:
555 -        msg << "INVALID_ENUM: An unacceptable value is specified for an "
556 -               "enumerated argument.";
557 -        break;
558 -      case GL_INVALID_VALUE:
559 -        msg << "INVALID_VALUE: A numeric argument is out of range.";
560 -        break;
561 -      case GL_INVALID_OPERATION:
562 -        msg << "INVALID_OPERATION: The specified operation is not allowed "
563 -               "in the current state.";
564 -        break;
565 -      case GL_STACK_OVERFLOW:
566 -        msg << "STACK_OVERFLOW: This command would cause a stack overflow.";
567 -        break;
568 -      case GL_STACK_UNDERFLOW:
569 -        msg << "STACK_UNDERFLOW: This command would cause a stack underflow.";
570 -        break;
571 -      case GL_OUT_OF_MEMORY:
572 -        msg << "OUT_OF_MEMORY: There is not enough memory left to execute the "
573 -               "command.";
574 -        break;
575 -      default:
576 -        msg << "Unknown error (code " << error << ")";
577 -    }
578 -        
579 -    throw std::runtime_error(msg.str());
580 -  }
581 -#endif
582 -}
583 +#define GLenum int
584 +#define GLint int
585 +#define GL_SRC_ALPHA 0
586 +#define GL_ONE_MINUS_SRC_ALPHA 1
587 +#define GL_RGBA 2
588 +
589 +
590  
591  #endif
592  
593 diff -Naur supertux/src/video/screen.cpp supertux-nogl/src/video/screen.cpp
594 --- supertux/src/video/screen.cpp       2006-04-07 03:32:13.000000000 +0200
595 +++ supertux-nogl/src/video/screen.cpp  2006-04-07 04:11:49.000000000 +0200
596 @@ -38,61 +38,70 @@
597  
598  static const float LOOP_DELAY = 20.0;
599  
600 -void fillrect(float x, float y, float w, float h, const Color& col)
601 -{
602 -  if(w < 0) {
603 -    x += w;
604 -    w = -w;
605 -  }
606 -  if(h < 0) {
607 -    y += h;
608 -    h = -h;
609 -  }
610 -
611 -  glColor4f(col.red, col.green, col.blue, col.alpha);
612  
613 -  glDisable(GL_TEXTURE_2D);
614 -  glBegin(GL_POLYGON);
615 -  glVertex2f(x, y);
616 -  glVertex2f(x+w, y);
617 -  glVertex2f(x+w, y+h);
618 -  glVertex2f(x, y+h);
619 -  glEnd();
620 -  glEnable(GL_TEXTURE_2D);
621 -
622 -  glColor4f(0, 0, 0, 1);
623 +void fillrect(float x, float y, float w, float h, int r, int g, int b, int a)
624 +  {
625 +    SDL_Surface* screen = SDL_GetVideoSurface();
626 +
627 +    if(w < 0) {
628 +      x += w;
629 +      w = -w;
630 +    }
631 +    if(h < 0) {
632 +      y += h;
633 +      h = -h;
634 +    }
635 +
636 +    SDL_Rect src, rect;
637 +    SDL_Surface *temp = NULL;
638 +
639 +    rect.x = (int)x;
640 +    rect.y = (int)y;
641 +    rect.w = (int)w;
642 +    rect.h = (int)h;
643 +
644 +    if(a != 255) {
645 +      temp = SDL_CreateRGBSurface(screen->flags, rect.w, rect.h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
646 +
647 +      src.x = 0;
648 +      src.y = 0;
649 +      src.w = rect.w;
650 +      src.h = rect.h;
651 +
652 +      SDL_FillRect(temp, &src, SDL_MapRGB(screen->format, r, g, b));
653 +      SDL_SetAlpha(temp, SDL_SRCALPHA, a);
654 +      SDL_BlitSurface(temp,0,screen,&rect);
655 +      SDL_FreeSurface(temp);
656 +    }
657 +    else
658 +    SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, r, g, b));
659  }
660  
661  void fadeout(float fade_time)
662  {
663 -  float alpha_inc  = LOOP_DELAY / fade_time;
664 -  Color c(0, 0, 0, alpha_inc);
665 -  float alpha = 1.0;
666 +  float alpha_inc  = 256 / (fade_time / LOOP_DELAY);
667 +  float alpha = 256;
668  
669 -  while(alpha >= 0) {
670 +  while(alpha > 0) {
671      alpha -= alpha_inc;
672 -    fillrect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, c);
673 -    // left side
674 +    fillrect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0,0,0, (int)alpha_inc);  // left side
675      
676 -    SDL_GL_SwapBuffers();
677 +    SDL_Flip(SDL_GetVideoSurface());
678      sound_manager->update();
679      
680      SDL_Delay(int(LOOP_DELAY));
681 -    alpha -= alpha_inc; 
682    }
683 -
684 -  fillrect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, Color());
685 +  fillrect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0, 255);
686  }
687  
688  void shrink_fade(const Vector& point, float fade_time)
689  {
690 -  float left_inc  = point.x / (fade_time / LOOP_DELAY);
691 -  float right_inc = (SCREEN_WIDTH - point.x) / (fade_time / LOOP_DELAY);
692 -  float up_inc    = point.y / (fade_time / LOOP_DELAY);
693 -  float down_inc  = (SCREEN_HEIGHT - point.y) / (fade_time / LOOP_DELAY);
694 +  float left_inc  = point.x / ((float)fade_time / LOOP_DELAY);
695 +  float right_inc = (SCREEN_WIDTH - point.x) / ((float)fade_time / LOOP_DELAY);
696 +  float up_inc    = point.y / ((float)fade_time / LOOP_DELAY);
697 +  float down_inc  = (SCREEN_HEIGHT - point.y) / ((float)fade_time / LOOP_DELAY);
698                                                                                  
699    float left_cor = 0, right_cor = 0, up_cor = 0, down_cor = 0;
700 -  Color c;
701                                                                                  
702    while(left_cor < point.x && right_cor < SCREEN_WIDTH - point.x &&
703        up_cor < point.y && down_cor < SCREEN_HEIGHT - point.y) {
704 @@ -101,15 +110,14 @@
705      up_cor    += up_inc;
706      down_cor  += down_inc;
707                                                                                  
708 -    fillrect(0, 0, left_cor, SCREEN_HEIGHT, c);  // left side
709 -    fillrect(SCREEN_WIDTH - right_cor, 0, right_cor, SCREEN_HEIGHT, c);  // right side
710 -    fillrect(0, 0, SCREEN_WIDTH, up_cor, c);  // up side
711 -    fillrect(0, SCREEN_HEIGHT - down_cor, SCREEN_WIDTH, down_cor+1, c);  // down side
712 +    fillrect(0, 0, left_cor, SCREEN_HEIGHT, 0,0,0, 255);  // left side
713 +    fillrect(SCREEN_WIDTH - right_cor, 0, right_cor, SCREEN_HEIGHT, 0,0,0, 255);  // right side
714 +    fillrect(0, 0, SCREEN_WIDTH, up_cor, 0,0,0, 255);  // up side
715 +    fillrect(0, SCREEN_HEIGHT - down_cor, SCREEN_WIDTH, down_cor+1, 0,0,0, 255);  // down side
716  
717 -    SDL_GL_SwapBuffers();
718 +    SDL_Flip(SDL_GetVideoSurface());
719    
720      sound_manager->update();
721      SDL_Delay(int(LOOP_DELAY));
722    }
723  }
724 -
725 diff -Naur supertux/src/video/screen.hpp supertux-nogl/src/video/screen.hpp
726 --- supertux/src/video/screen.hpp       2006-04-07 03:32:13.000000000 +0200
727 +++ supertux-nogl/src/video/screen.hpp  2006-04-07 04:11:49.000000000 +0200
728 @@ -20,7 +20,6 @@
729  #define SUPERTUX_SCREEN_H
730  
731  #include <SDL.h>
732 -#include <GL/gl.h>
733  #include <iostream>
734  
735  #include <vector>
736 diff -Naur supertux/src/video/surface.cpp supertux-nogl/src/video/surface.cpp
737 --- supertux/src/video/surface.cpp      2006-03-25 01:16:31.000000000 +0100
738 +++ supertux-nogl/src/video/surface.cpp 2006-04-07 04:11:49.000000000 +0200
739 @@ -28,6 +29,7 @@
740  
741  #include <SDL.h>
742  #include <SDL_image.h>
743 +#include <SDL_rotozoom.h>
744  
745  #include "gameconfig.hpp"
746  #include "physfs/physfs_sdl.hpp"
747 @@ -40,13 +42,13 @@
748  {
749    texture = texture_manager->get(file);
750    texture->ref();
751 -  uv_left = 0;
752 -  uv_top = 0;
753 -  uv_right = texture->get_uv_right();
754 -  uv_bottom = texture->get_uv_bottom();
755  
756 -  width = texture->get_image_width();
757 -  height = texture->get_image_height();
758 +  offsetx = 0;
759 +  offsety = 0;
760 +  width = static_cast<int>(texture->get_image_width());
761 +  height = static_cast<int>(texture->get_image_height());
762 +
763 +  flipx = false;
764  }
765  
766  Surface::Surface(const std::string& file, int x, int y, int w, int h)
767 @@ -54,15 +56,12 @@
768    texture = texture_manager->get(file);
769    texture->ref();
770  
771 -  float tex_w = static_cast<float> (texture->get_width());
772 -  float tex_h = static_cast<float> (texture->get_height());
773 -  uv_left = static_cast<float>(x) / tex_w;
774 -  uv_top = static_cast<float>(y) / tex_h;
775 -  uv_right = static_cast<float>(x+w) / tex_w;
776 -  uv_bottom = static_cast<float>(y+h) / tex_h;
777 -
778 +  offsetx = x;
779 +  offsety = y;
780    width = w;
781    height = h;
782 +
783 +  flipx = false;
784  }
785  
786  Surface::Surface(const Surface& other)
787 @@ -70,12 +69,12 @@
788    texture = other.texture;
789    texture->ref();
790  
791 -  uv_left = other.uv_left;
792 -  uv_top = other.uv_top;
793 -  uv_right = other.uv_right;
794 -  uv_bottom = other.uv_bottom;
795 +  offsetx = other.offsetx;
796 +  offsety = other.offsety;
797    width = other.width;
798    height = other.height;
799 +
800 +  flipx = other.flipx;
801  }
802  
803  const Surface&
804 @@ -85,81 +84,95 @@
805    texture->unref();
806    texture = other.texture;
807  
808 -  uv_left = other.uv_left;
809 -  uv_top = other.uv_top;
810 -  uv_right = other.uv_right;
811 -  uv_bottom = other.uv_bottom;
812 +  offsetx = other.offsetx;
813 +  offsety = other.offsety;
814    width = other.width;
815    height = other.height;
816  
817 +  flipx = other.flipx;
818 +
819    return *this;
820  }
821  
822  Surface::~Surface()
823  {
824    texture->unref();
825 +
826 +  for (std::list<TransformedSurface*>::iterator i = transformedSurfaces.begin(); i != transformedSurfaces.end(); i++) {
827 +    SDL_FreeSurface((*i)->surface);
828 +    delete (*i);
829 +  }
830  }
831  
832  void
833  Surface::hflip()
834  {
835 -  std::swap(uv_left, uv_right);
836 -}
837 -
838 -static inline void intern_draw(float left, float top, float right, float bottom,                               float uv_left, float uv_top,
839 -                               float uv_right, float uv_bottom,
840 -                               DrawingEffect effect)
841 -{
842 -  if(effect & HORIZONTAL_FLIP)
843 -    std::swap(uv_left, uv_right);
844 -  if(effect & VERTICAL_FLIP) {
845 -    std::swap(uv_top, uv_bottom);
846 -  }
847 -  
848 -  glBegin(GL_QUADS);
849 -  glTexCoord2f(uv_left, uv_top);
850 -  glVertex2f(left, top);
851 -  
852 -  glTexCoord2f(uv_right, uv_top);
853 -  glVertex2f(right, top);
854 -
855 -  glTexCoord2f(uv_right, uv_bottom);
856 -  glVertex2f(right, bottom);
857 -
858 -  glTexCoord2f(uv_left, uv_bottom);
859 -  glVertex2f(left, bottom);
860 -  glEnd();
861 +  flipx = !flipx;
862  }
863  
864  void
865  Surface::draw(float x, float y, float alpha, DrawingEffect effect) const
866  {
867 -  glColor4f(1.0f, 1.0f, 1.0f, alpha);
868 -  glBindTexture(GL_TEXTURE_2D, texture->get_handle());
869 -
870 -  intern_draw(x, y,
871 -              x + width, y + height,
872 -              uv_left, uv_top, uv_right, uv_bottom, effect);
873 +  draw_part(0, 0, x, y, width, height, alpha, effect);
874  }
875  
876  void
877  Surface::draw_part(float src_x, float src_y, float dst_x, float dst_y,
878 -                   float width, float height, float alpha,
879 +                   float width, float height, float,
880                     DrawingEffect effect) const
881  {
882 -  float uv_width = uv_right - uv_left;
883 -  float uv_height = uv_bottom - uv_top;
884 -  
885 -  float uv_left = this->uv_left + (uv_width * src_x) / this->width;
886 -  float uv_top = this->uv_top + (uv_height * src_y) / this->height;
887 -  float uv_right = this->uv_left + (uv_width * (src_x + width)) / this->width;
888 -  float uv_bottom = this->uv_top + (uv_height * (src_y + height)) / this->height;
889 -  
890 -  glColor4f(1.0f, 1.0f, 1.0f, alpha);
891 -  glBindTexture(GL_TEXTURE_2D, texture->get_handle());  
892 -  
893 -  intern_draw(dst_x, dst_y,
894 -              dst_x + width, dst_y + height,
895 -              uv_left, uv_top, uv_right, uv_bottom, effect);
896 +  //FIXME: support parameter "alpha"
897 +  SDL_Surface* surface = texture->getSurface();
898 +
899 +  // get and check SDL_Surface
900 +  if (surface == 0) {
901 +    std::cerr << "Warning: Tried to draw NULL surface, skipped draw" << std::endl;
902 +    return;
903 +  }    
904 +
905 +  SDL_Surface* transformedSurface = surface;
906 +
907 +  if (flipx) effect = HORIZONTAL_FLIP;
908 +
909 +  if (effect != NO_EFFECT) {
910 +    transformedSurface = 0;
911 +
912 +    // check if we have this effect buffered
913 +    for (std::list<TransformedSurface*>::const_iterator i = transformedSurfaces.begin(); i != transformedSurfaces.end(); i++) {
914 +      if ((*i)->effect == effect) transformedSurface = (*i)->surface;
915 +    }
916 +
917 +    // if not: transform and buffer
918 +    if (!transformedSurface) {
919 +      if (effect == HORIZONTAL_FLIP) transformedSurface = zoomSurface(surface, -1, 1, 0);
920 +      if (effect == VERTICAL_FLIP) transformedSurface = zoomSurface(surface, 1, -1, 0);
921 +      if (transformedSurface == 0) {
922 +        std::cerr << "Warning: No known transformation applies to surface, skipped draw" << std::endl;
923 +        return;
924 +      }        
925 +      TransformedSurface* su = new TransformedSurface();
926 +      su->surface = transformedSurface;
927 +      su->effect = effect;
928 +
929 +      transformedSurfaces.push_front(su);
930 +    }
931 +  }
932 +
933 +  int ox = offsetx; if (effect == HORIZONTAL_FLIP) ox = static_cast<int>(surface->w) - (ox+static_cast<int>(width));
934 +  int oy = offsety; if (effect == VERTICAL_FLIP) oy = static_cast<int>(surface->h) - (oy+static_cast<int>(height));
935 +  // draw surface to screen
936 +  SDL_Surface* screen = SDL_GetVideoSurface();
937 +
938 +  SDL_Rect srcRect;
939 +  srcRect.x = static_cast<int>(ox+src_x);
940 +  srcRect.y = static_cast<int>(oy+src_y);
941 +  srcRect.w = static_cast<int>(width);
942 +  srcRect.h = static_cast<int>(height);
943 +
944 +  SDL_Rect dstRect;
945 +  dstRect.x = static_cast<int>(dst_x);
946 +  dstRect.y = static_cast<int>(dst_y);
947 +
948 +  SDL_BlitSurface(transformedSurface, &srcRect, screen, &dstRect);
949  }
950  
951 diff -Naur supertux/src/video/surface.hpp supertux-nogl/src/video/surface.hpp
952 --- supertux/src/video/surface.hpp      2006-03-03 20:34:27.000000000 +0100
953 +++ supertux-nogl/src/video/surface.hpp 2006-04-07 04:11:49.000000000 +0200
954 @@ -20,7 +20,9 @@
955  #ifndef __SURFACE_HPP__
956  #define __SURFACE_HPP__
957  
958 +#include <SDL_image.h>
959  #include <string>
960 +#include <list>
961  
962  class ImageTexture;
963  
964 @@ -35,6 +37,15 @@
965  };
966  
967  /**
968 + * Helper class to buffer a pre-transformed SDL_Surface
969 + */
970 +class TransformedSurface {
971 +    public:
972 +       SDL_Surface* surface;
973 +       DrawingEffect effect;
974 +};
975 +
976 +/**
977   * A rectangular image.
978   * The class basically holds a reference to a texture with additional UV
979   * coordinates that specify a rectangular area on this texture
980 @@ -46,18 +57,23 @@
981    friend class Font;
982    ImageTexture* texture;
983  
984 -  float uv_left;
985 -  float uv_top;
986 -  float uv_right;
987 -  float uv_bottom;
988 +  bool flipx;
989  
990 +  /** draw the surface on the screen, applying a ::DrawingEffect on-the-fly. Transformed Surfaces will be cached in ::transformedSurfaces */
991    void draw(float x, float y, float alpha, DrawingEffect effect) const;
992 +
993 +  /** draw the surface on the screen, applying a ::DrawingEffect on-the-fly. Transformed Surfaces will be cached in ::transformedSurfaces */
994    void draw_part(float src_x, float src_y, float dst_x, float dst_y,
995                   float width, float height,
996                   float alpha, DrawingEffect effect) const;
997  
998 -  float width;
999 -  float height;
1000 +  int offsetx; /**< Region in ::surface to be used for blitting */
1001 +  int offsety; /**< Region in ::surface to be used for blitting */
1002 +  int width;   /**< Region in ::surface to be used for blitting */
1003 +  int height;  /**< Region in ::surface to be used for blitting */
1004 +
1005 +  mutable std::list<TransformedSurface*> transformedSurfaces; /**< Cache for pre-transformed surfaces */
1006 +
1007  public:
1008    Surface(const std::string& file);
1009    Surface(const std::string& file, int x, int y, int w, int h);
1010 diff -Naur supertux/src/video/texture.cpp supertux-nogl/src/video/texture.cpp
1011 --- supertux/src/video/texture.cpp      2006-03-03 20:34:27.000000000 +0100
1012 +++ supertux-nogl/src/video/texture.cpp 2006-04-07 04:11:49.000000000 +0200
1013 @@ -20,7 +20,6 @@
1014  
1015  #include "texture.hpp"
1016  
1017 -#include <GL/gl.h>
1018  #include <assert.h>
1019  #include "glutil.hpp"
1020  
1021 @@ -29,81 +28,37 @@
1022    return (v & (v-1)) == 0;
1023  }
1024  
1025 -Texture::Texture(unsigned int w, unsigned int h, GLenum glformat)
1026 +Texture::Texture(unsigned int w, unsigned int h, GLenum)
1027  {
1028    assert(is_power_of_2(w));
1029    assert(is_power_of_2(h));
1030  
1031    this->width = w;
1032    this->height = h;
1033 -  
1034 -  assert_gl("before creating texture");
1035 -  glGenTextures(1, &handle);
1036 -  
1037 -  try {
1038 -    glBindTexture(GL_TEXTURE_2D, handle);
1039 -
1040 -    glTexImage2D(GL_TEXTURE_2D, 0, glformat, width, height, 0, GL_RGBA,
1041 -                 GL_UNSIGNED_BYTE, 0);
1042 -
1043 -    set_texture_params();
1044 -  } catch(...) {
1045 -    glDeleteTextures(1, &handle);
1046 -    throw;
1047 -  }
1048 +
1049 +  surface = 0;
1050  }
1051  
1052 -Texture::Texture(SDL_Surface* image, GLenum glformat)
1053 +Texture::Texture(SDL_Surface* image, GLenum)
1054  {
1055    const SDL_PixelFormat* format = image->format;
1056    if(!is_power_of_2(image->w) || !is_power_of_2(image->h))
1057      throw std::runtime_error("image has no power of 2 size");
1058    if(format->BitsPerPixel != 24 && format->BitsPerPixel != 32)
1059      throw std::runtime_error("image has no 24 or 32 bit color depth");
1060 -  
1061 +
1062    this->width = image->w;
1063    this->height = image->h;
1064  
1065 -  assert_gl("before creating texture");
1066 -  glGenTextures(1, &handle);
1067 -  
1068 -  try {
1069 -    GLenum sdl_format;
1070 -    if(format->BytesPerPixel == 3)
1071 -      sdl_format = GL_RGB;
1072 -    else if(format->BytesPerPixel == 4)
1073 -      sdl_format = GL_RGBA;
1074 -    else
1075 -      assert(false);
1076 -
1077 -    glBindTexture(GL_TEXTURE_2D, handle);
1078 -    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1079 -    glPixelStorei(GL_UNPACK_ROW_LENGTH, image->pitch/format->BytesPerPixel);
1080 -    glTexImage2D(GL_TEXTURE_2D, 0, glformat, width, height, 0, sdl_format,
1081 -            GL_UNSIGNED_BYTE, image->pixels);
1082 -
1083 -    assert_gl("creating texture");
1084 -
1085 -    set_texture_params();    
1086 -  } catch(...) {
1087 -    glDeleteTextures(1, &handle);
1088 -    throw;
1089 -  }
1090 +  surface = SDL_DisplayFormatAlpha(image);
1091  }
1092  
1093  Texture::~Texture()
1094  {
1095 -  glDeleteTextures(1, &handle);
1096  }
1097  
1098  void
1099  Texture::set_texture_params()
1100  {
1101 -  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1102 -  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1103 -  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
1104 -  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
1105 -
1106 -  assert_gl("set texture params");
1107  }
1108  
1109 diff -Naur supertux/src/video/texture.hpp supertux-nogl/src/video/texture.hpp
1110 --- supertux/src/video/texture.hpp      2006-03-03 20:34:27.000000000 +0100
1111 +++ supertux-nogl/src/video/texture.hpp 2006-04-07 04:11:49.000000000 +0200
1112 @@ -20,7 +20,7 @@
1113  #define __TEXTURE_HPP__
1114  
1115  #include <SDL.h>
1116 -#include <GL/gl.h>
1117 +#include "glutil.hpp"
1118  
1119  /**
1120   * This class is a wrapper around a texture handle. It stores the texture width
1121 @@ -30,8 +30,9 @@
1122  class Texture
1123  {
1124  protected:
1125 +  SDL_Surface* surface; /**< non-GL branch stores optimized surface */
1126 +
1127    friend class TextureManager;
1128 -  GLuint handle;
1129    unsigned int width;
1130    unsigned int height;
1131  
1132 @@ -40,11 +41,6 @@
1133    Texture(SDL_Surface* surface, GLenum glformat);
1134    virtual ~Texture();
1135    
1136 -  GLuint get_handle() const
1137 -  {
1138 -    return handle;
1139 -  }
1140 -
1141    unsigned int get_width() const
1142    {
1143      return width;
1144 @@ -55,6 +51,14 @@
1145      return height;
1146    }
1147  
1148 +  SDL_Surface* getSurface() {
1149 +    return surface;
1150 +  }
1151 +
1152 +  void setSurface(SDL_Surface* surface) {
1153 +    this->surface = surface;
1154 +  }
1155 +
1156  private:
1157    void set_texture_params();
1158  };
1159 diff -Naur supertux/src/video/texture_manager.cpp supertux-nogl/src/video/texture_manager.cpp
1160 --- supertux/src/video/texture_manager.cpp      2006-04-07 03:32:13.000000000 +0200
1161 +++ supertux-nogl/src/video/texture_manager.cpp 2006-04-07 04:11:49.000000000 +0200
1162 @@ -5,8 +5,6 @@
1163  #include <assert.h>
1164  #include <SDL.h>
1165  #include <SDL_image.h>
1166 -#include <GL/gl.h>
1167 -#include <GL/glext.h>
1168  #include <iostream>
1169  #include <sstream>
1170  #include <stdexcept>
1171 @@ -126,12 +124,6 @@
1172  void
1173  TextureManager::save_textures()
1174  {
1175 -  glPixelStorei(GL_PACK_ROW_LENGTH, 0);
1176 -  glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
1177 -  glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
1178 -  glPixelStorei(GL_PACK_SKIP_ROWS, 0);
1179 -  glPixelStorei(GL_PACK_SKIP_IMAGES, 0);
1180 -  glPixelStorei(GL_PACK_ALIGNMENT, 1);
1181    for(Textures::iterator i = textures.begin(); i != textures.end(); ++i) {
1182      save_texture(*i);
1183    }
1184 @@ -146,75 +138,16 @@
1185  {
1186    SavedTexture saved_texture;
1187    saved_texture.texture = texture;
1188 -  glBindTexture(GL_TEXTURE_2D, texture->get_handle());
1189 -  glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH,
1190 -                           &saved_texture.width);
1191 -  glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT,
1192 -                           &saved_texture.height);
1193 -  glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BORDER,
1194 -                           &saved_texture.border);
1195 -  glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
1196 -                      &saved_texture.min_filter);
1197 -  glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
1198 -                      &saved_texture.mag_filter);
1199 -  glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
1200 -                      &saved_texture.wrap_s);
1201 -  glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
1202 -                      &saved_texture.wrap_t);
1203  
1204    size_t pixelssize = saved_texture.width * saved_texture.height * 4;
1205    saved_texture.pixels = new char[pixelssize];
1206 -  
1207 -  glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1208 -                saved_texture.pixels);
1209  
1210    saved_textures.push_back(saved_texture);
1211 -
1212 -  glDeleteTextures(1, &(texture->handle));
1213 -  texture->handle = 0;
1214 -
1215 -  assert_gl("retrieving texture for save");
1216  }
1217  
1218  void
1219  TextureManager::reload_textures()
1220  {
1221 -  glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1222 -  glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
1223 -  glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
1224 -  glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
1225 -  glPixelStorei(GL_UNPACK_SKIP_IMAGES, 0);
1226 -  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1227 -  
1228 -  for(std::vector<SavedTexture>::iterator i = saved_textures.begin();
1229 -      i != saved_textures.end(); ++i) {
1230 -    SavedTexture& saved_texture = *i;
1231 -    
1232 -    GLuint handle;
1233 -    glGenTextures(1, &handle);
1234 -    assert_gl("creating texture handle");
1235 -
1236 -    glBindTexture(GL_TEXTURE_2D, handle);
1237 -    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
1238 -                 saved_texture.width, saved_texture.height,
1239 -                 saved_texture.border, GL_RGBA,
1240 -                 GL_UNSIGNED_BYTE, saved_texture.pixels);
1241 -    delete[] saved_texture.pixels;
1242 -    assert_gl("uploading texture pixel data");
1243 -
1244 -    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
1245 -                    saved_texture.min_filter);
1246 -    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
1247 -                    saved_texture.mag_filter);
1248 -    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
1249 -                    saved_texture.wrap_s);
1250 -    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
1251 -                    saved_texture.wrap_t);
1252 -
1253 -    assert_gl("setting texture_params");
1254 -    saved_texture.texture->handle = handle;
1255 -  }
1256 -
1257    saved_textures.clear();
1258  }
1259  
1260 diff -Naur supertux/src/video/texture_manager.hpp supertux-nogl/src/video/texture_manager.hpp
1261 --- supertux/src/video/texture_manager.hpp      2006-03-03 20:34:27.000000000 +0100
1262 +++ supertux-nogl/src/video/texture_manager.hpp 2006-04-07 04:11:49.000000000 +0200
1263 @@ -1,7 +1,7 @@
1264  #ifndef __IMAGE_TEXTURE_MANAGER_HPP__
1265  #define __IMAGE_TEXTURE_MANAGER_HPP__
1266  
1267 -#include <GL/gl.h>
1268 +#include "video/glutil.hpp"
1269  #include <string>
1270  #include <vector>
1271  #include <map>