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