3 # Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
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.
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.
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.
19 # -----------------------------------------------------------------------------
21 # This patch allows running the game on systems without OpenGL support.
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.
27 # Note that the patched sources will need an additional library, SDL_gfx, to
30 # Installing the patch should be pretty straightforward. Simply run the
31 # following command prior to running autogen.sh and configure:
33 # patch -p1 < contrib/supertux-nogl.diff
35 # This patch works for revision 3677. It may break for later revisions.
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
42 - Install instructions for SuperTux -
43 http://supertux.berlios.de/
45 -Last update: October 11, 2005 by Ondra Hosek
46 +Last update: March 4, 2006 by Christoph Sommer
51 Download: ftp://ftp.perforce.com/pub/jam
52 Homepage: http://www.perforce.com/jam/jam.html
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.
59 * SDL 1.2.5 or later (1.2.8 is recommended on MacOS/X)
62 * SDL_image (any version)
63 http://www.libsdl.org/projects/SDL_image
65 +* SDL_gfx (2.0.13 or later)
66 + http://www.ferzkopp.net/Software/SDL_gfx-2.0/
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
75 - An introduction for SuperTux -
76 http://supertux.berlios.de/
78 -Last update: October 13, 2005
79 +Last update: March 4, 2006 by Christoph Sommer
84 Also, notice that SuperTux saves the options, so it's often enough to
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
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
102 dnl Process this file with autoconf to produce a configure script.
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])
110 [AC_MSG_ERROR([Please install SDLImage >= 1.2.1])],
111 [$SDL_CFLAGS], [$SDL_LIBS])
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;]),
118 + [AC_MSG_ERROR([Please install SDL_gfx >= 2.0.13])],
119 + [$SDL_CFLAGS], [$SDL_LIBS])
121 NP_FINDLIB([PHYSFS], [physfs], [physfs >= 1.0.0],
125 [AC_MSG_ERROR([Please intall OpenAL])],
129 -if test "$no_gl" = "yes"; then
130 - AC_MSG_ERROR([Please install opengl libraries and headers])
133 dnl Checks for library functions.
134 AC_CHECK_FUNCS(mkdir strdup strstr)
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
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 ;
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
154 #include <SDL_image.h>
157 #include "gameconfig.hpp"
158 #include "resources.hpp"
160 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
161 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
163 - int flags = SDL_OPENGL;
164 + int flags = SDL_SWSURFACE;
165 if(config->use_fullscreen)
166 flags |= SDL_FULLSCREEN;
167 int width = config->screenwidth;
172 - // setup opengl state and transform
173 - glDisable(GL_DEPTH_TEST);
174 - glDisable(GL_CULL_FACE);
175 - glEnable(GL_TEXTURE_2D);
176 - glEnable(GL_BLEND);
177 - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
179 - glViewport(0, 0, screen->w, screen->h);
180 - glMatrixMode(GL_PROJECTION);
182 - // logical resolution here not real monitor resolution
183 - glOrtho(0, 800, 600, 0, -1.0, 1.0);
184 - glMatrixMode(GL_MODELVIEW);
186 - glTranslatef(0, 0, 0);
188 - check_gl_error("Setting up view matrices");
190 if(texture_manager != NULL)
191 texture_manager->reload_textures();
193 diff -Naur supertux/src/video/drawing_context.cpp supertux-nogl/src/video/drawing_context.cpp
194 --- supertux/src/video/drawing_context.cpp 2006-03-31 04:18:01.000000000 +0200
195 +++ supertux-nogl/src/video/drawing_context.cpp 2006-04-07 04:11:49.000000000 +0200
199 #include <SDL_image.h>
201 +#include <SDL_gfxPrimitives.h>
203 #include "drawing_context.hpp"
204 #include "surface.hpp"
207 screen = SDL_GetVideoSurface();
209 - lightmap_width = screen->w / LIGHTMAP_DIV;
210 - lightmap_height = screen->h / LIGHTMAP_DIV;
211 - unsigned int width = next_po2(lightmap_width);
212 - unsigned int height = next_po2(lightmap_height);
214 - lightmap = new Texture(width, height, GL_RGB);
216 - lightmap_uv_right = static_cast<float>(lightmap_width) / static_cast<float>(width);
217 - lightmap_uv_bottom = static_cast<float>(lightmap_height) / static_cast<float>(height);
218 - texture_manager->register_texture(lightmap);
221 requests = &drawing_requests;
224 DrawingContext::~DrawingContext()
226 - texture_manager->remove_texture(lightmap);
231 DrawingContext::draw_surface(const Surface* surface, const Vector& position,
234 + if(target != NORMAL) return;
236 assert(surface != 0);
238 DrawingRequest request;
240 DrawingContext::draw_surface_part(const Surface* surface, const Vector& source,
241 const Vector& size, const Vector& dest, int layer)
243 + if(target != NORMAL) return;
245 assert(surface != 0);
247 DrawingRequest request;
249 DrawingContext::draw_text(const Font* font, const std::string& text,
250 const Vector& position, FontAlignment alignment, int layer)
252 + if(target != NORMAL) return;
254 DrawingRequest request;
258 DrawingContext::draw_center_text(const Font* font, const std::string& text,
259 const Vector& position, int layer)
261 + if(target != NORMAL) return;
263 draw_text(font, text, Vector(position.x + SCREEN_WIDTH/2, position.y),
264 CENTER_ALLIGN, layer);
268 DrawingContext::draw_gradient(const Color& top, const Color& bottom, int layer)
270 + if(target != NORMAL) return;
272 DrawingRequest request;
274 request.type = GRADIENT;
276 DrawingContext::draw_filled_rect(const Vector& topleft, const Vector& size,
277 const Color& color, int layer)
279 + if(target != NORMAL) return;
281 DrawingRequest request;
283 request.type = FILLRECT;
284 @@ -246,18 +246,21 @@
285 GradientRequest* gradientrequest = (GradientRequest*) request.request_data;
286 const Color& top = gradientrequest->top;
287 const Color& bottom = gradientrequest->bottom;
289 - glDisable(GL_TEXTURE_2D);
291 - glColor4f(top.red, top.green, top.blue, top.alpha);
293 - glVertex2f(SCREEN_WIDTH, 0);
294 - glColor4f(bottom.red, bottom.green, bottom.blue, bottom.alpha);
295 - glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT);
296 - glVertex2f(0, SCREEN_HEIGHT);
298 - glEnable(GL_TEXTURE_2D);
302 + for(int y = 0; y < height; y += 2) {
308 + int r = (int)(255.0 * (((float)(top.red-bottom.red)/(0-height)) * y + top.red));
309 + int g = (int)(255.0 * (((float)(top.green-bottom.green)/(0-height)) * y + top.green));
310 + int b = (int)(255.0 * (((float)(top.blue-bottom.blue)/(0-height)) * y + top.blue));
311 + SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, r, g, b));
314 delete gradientrequest;
317 @@ -277,23 +280,18 @@
319 FillRectRequest* fillrectrequest = (FillRectRequest*) request.request_data;
321 - float x = request.pos.x;
322 - float y = request.pos.y;
323 - float w = fillrectrequest->size.x;
324 - float h = fillrectrequest->size.y;
325 + int x = static_cast<int>(request.pos.x);
326 + int y = static_cast<int>(request.pos.y);
327 + int w = static_cast<int>(fillrectrequest->size.x);
328 + int h = static_cast<int>(fillrectrequest->size.y);
330 - glDisable(GL_TEXTURE_2D);
331 - glColor4f(fillrectrequest->color.red, fillrectrequest->color.green,
332 - fillrectrequest->color.blue, fillrectrequest->color.alpha);
336 - glVertex2f(x+w, y);
337 - glVertex2f(x+w, y+h);
338 - glVertex2f(x, y+h);
340 - glEnable(GL_TEXTURE_2D);
341 + int r = static_cast<int>(255.0 * fillrectrequest->color.red);
342 + int g = static_cast<int>(255.0 * fillrectrequest->color.green);
343 + int b = static_cast<int>(255.0 * fillrectrequest->color.blue);
344 + int a = static_cast<int>(255.0 * fillrectrequest->color.alpha);
346 + boxRGBA(screen, x, y, x + w, y + h, r, g, b, a);
348 delete fillrectrequest;
351 @@ -307,66 +305,10 @@
352 transformstack.clear();
353 target_stack.clear();
355 - bool use_lightmap = lightmap_requests.size() != 0;
357 - // PART1: create lightmap
359 - glViewport(0, screen->h - lightmap_height, lightmap_width, lightmap_height);
360 - glMatrixMode(GL_PROJECTION);
362 - glOrtho(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1.0, 1.0);
363 - glMatrixMode(GL_MODELVIEW);
366 - //glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
367 - glClearColor(0, 0, 0, 1);
368 - glClear(GL_COLOR_BUFFER_BIT);
369 - handle_drawing_requests(lightmap_requests);
370 - lightmap_requests.clear();
372 - glDisable(GL_BLEND);
373 - glBindTexture(GL_TEXTURE_2D, lightmap->get_handle());
374 - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, screen->h - lightmap_height, lightmap_width, lightmap_height);
376 - glViewport(0, 0, screen->w, screen->h);
377 - glMatrixMode(GL_PROJECTION);
379 - glOrtho(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1.0, 1.0);
380 - glMatrixMode(GL_MODELVIEW);
382 - glEnable(GL_BLEND);
385 - //glClear(GL_COLOR_BUFFER_BIT);
386 handle_drawing_requests(drawing_requests);
387 drawing_requests.clear();
390 - glBlendFunc(GL_SRC_ALPHA, GL_ONE);
392 - glBindTexture(GL_TEXTURE_2D, lightmap->get_handle());
395 - glTexCoord2f(0, lightmap_uv_bottom);
398 - glTexCoord2f(lightmap_uv_right, lightmap_uv_bottom);
399 - glVertex2f(SCREEN_WIDTH, 0);
401 - glTexCoord2f(lightmap_uv_right, 0);
402 - glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT);
404 - glTexCoord2f(0, 0);
405 - glVertex2f(0, SCREEN_HEIGHT);
409 - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
412 - assert_gl("drawing");
414 - SDL_GL_SwapBuffers();
420 DrawingContext::set_target(Target target)
422 this->target = target;
423 - if(target == LIGHTMAP)
424 - requests = &lightmap_requests;
426 - requests = &drawing_requests;
429 diff -Naur supertux/src/video/drawing_context.hpp supertux-nogl/src/video/drawing_context.hpp
430 --- supertux/src/video/drawing_context.hpp 2006-03-03 20:34:27.000000000 +0100
431 +++ supertux-nogl/src/video/drawing_context.hpp 2006-04-07 04:11:49.000000000 +0200
444 +#include "glutil.hpp"
449 // some constants for predefined layer values
451 @@ -202,16 +202,12 @@
452 void draw_filled_rect(DrawingRequest& request);
454 DrawingRequests drawing_requests;
455 - DrawingRequests lightmap_requests;
457 DrawingRequests* requests;
461 std::vector<Target> target_stack;
463 - int lightmap_width, lightmap_height;
464 - float lightmap_uv_right, lightmap_uv_bottom;
468 diff -Naur supertux/src/video/glutil.hpp supertux-nogl/src/video/glutil.hpp
469 --- supertux/src/video/glutil.hpp 2006-03-21 16:13:11.000000000 +0100
470 +++ supertux-nogl/src/video/glutil.hpp 2006-04-07 04:11:49.000000000 +0200
474 -static inline void check_gl_error(const char* message)
477 - GLenum error = glGetError();
478 - if(error != GL_NO_ERROR) {
479 - std::ostringstream msg;
480 - msg << "OpenGLError while '" << message << "': ";
482 - case GL_INVALID_ENUM:
483 - msg << "INVALID_ENUM: An unacceptable value is specified for an "
484 - "enumerated argument.";
486 - case GL_INVALID_VALUE:
487 - msg << "INVALID_VALUE: A numeric argument is out of range.";
489 - case GL_INVALID_OPERATION:
490 - msg << "INVALID_OPERATION: The specified operation is not allowed "
491 - "in the current state.";
493 - case GL_STACK_OVERFLOW:
494 - msg << "STACK_OVERFLOW: This command would cause a stack overflow.";
496 - case GL_STACK_UNDERFLOW:
497 - msg << "STACK_UNDERFLOW: This command would cause a stack underflow.";
499 - case GL_OUT_OF_MEMORY:
500 - msg << "OUT_OF_MEMORY: There is not enough memory left to execute the "
503 -#ifdef GL_TABLE_TOO_LARGE
504 - case GL_TABLE_TOO_LARGE:
505 - msg << "TABLE_TOO_LARGE: table is too large";
509 - msg << "Unknown error (code " << error << ")";
512 - throw std::runtime_error(msg.str());
517 -static inline void assert_gl(const char* message)
520 - check_gl_error(message);
527 +#define GL_SRC_ALPHA 0
528 +#define GL_ONE_MINUS_SRC_ALPHA 1
530 diff -Naur supertux/src/video/surface.cpp supertux-nogl/src/video/surface.cpp
531 --- supertux/src/video/surface.cpp 2006-03-25 01:16:31.000000000 +0100
532 +++ supertux-nogl/src/video/surface.cpp 2006-04-07 04:11:49.000000000 +0200
536 #include <SDL_image.h>
537 +#include <SDL_rotozoom.h>
539 #include "gameconfig.hpp"
540 #include "physfs/physfs_sdl.hpp"
543 texture = texture_manager->get(file);
547 - uv_right = texture->get_uv_right();
548 - uv_bottom = texture->get_uv_bottom();
550 - width = texture->get_image_width();
551 - height = texture->get_image_height();
554 + width = static_cast<int>(texture->get_image_width());
555 + height = static_cast<int>(texture->get_image_height());
560 Surface::Surface(const std::string& file, int x, int y, int w, int h)
562 texture = texture_manager->get(file);
565 - float tex_w = static_cast<float> (texture->get_width());
566 - float tex_h = static_cast<float> (texture->get_height());
567 - uv_left = static_cast<float>(x) / tex_w;
568 - uv_top = static_cast<float>(y) / tex_h;
569 - uv_right = static_cast<float>(x+w) / tex_w;
570 - uv_bottom = static_cast<float>(y+h) / tex_h;
580 Surface::Surface(const Surface& other)
582 texture = other.texture;
585 - uv_left = other.uv_left;
586 - uv_top = other.uv_top;
587 - uv_right = other.uv_right;
588 - uv_bottom = other.uv_bottom;
589 + offsetx = other.offsetx;
590 + offsety = other.offsety;
592 height = other.height;
594 + flipx = other.flipx;
600 texture = other.texture;
602 - uv_left = other.uv_left;
603 - uv_top = other.uv_top;
604 - uv_right = other.uv_right;
605 - uv_bottom = other.uv_bottom;
606 + offsetx = other.offsetx;
607 + offsety = other.offsety;
609 height = other.height;
611 + flipx = other.flipx;
620 + for (std::list<TransformedSurface*>::iterator i = transformedSurfaces.begin(); i != transformedSurfaces.end(); i++) {
621 + SDL_FreeSurface((*i)->surface);
629 - std::swap(uv_left, uv_right);
632 -static inline void intern_draw(float left, float top, float right, float bottom, float uv_left, float uv_top,
633 - float uv_right, float uv_bottom,
634 - DrawingEffect effect)
636 - if(effect & HORIZONTAL_FLIP)
637 - std::swap(uv_left, uv_right);
638 - if(effect & VERTICAL_FLIP) {
639 - std::swap(uv_top, uv_bottom);
643 - glTexCoord2f(uv_left, uv_top);
644 - glVertex2f(left, top);
646 - glTexCoord2f(uv_right, uv_top);
647 - glVertex2f(right, top);
649 - glTexCoord2f(uv_right, uv_bottom);
650 - glVertex2f(right, bottom);
652 - glTexCoord2f(uv_left, uv_bottom);
653 - glVertex2f(left, bottom);
659 Surface::draw(float x, float y, float alpha, DrawingEffect effect) const
661 - glColor4f(1.0f, 1.0f, 1.0f, alpha);
662 - glBindTexture(GL_TEXTURE_2D, texture->get_handle());
665 - x + width, y + height,
666 - uv_left, uv_top, uv_right, uv_bottom, effect);
667 + draw_part(0, 0, x, y, width, height, alpha, effect);
671 Surface::draw_part(float src_x, float src_y, float dst_x, float dst_y,
672 - float width, float height, float alpha,
673 + float width, float height, float,
674 DrawingEffect effect) const
676 - float uv_width = uv_right - uv_left;
677 - float uv_height = uv_bottom - uv_top;
679 - float uv_left = this->uv_left + (uv_width * src_x) / this->width;
680 - float uv_top = this->uv_top + (uv_height * src_y) / this->height;
681 - float uv_right = this->uv_left + (uv_width * (src_x + width)) / this->width;
682 - float uv_bottom = this->uv_top + (uv_height * (src_y + height)) / this->height;
684 - glColor4f(1.0f, 1.0f, 1.0f, alpha);
685 - glBindTexture(GL_TEXTURE_2D, texture->get_handle());
687 - intern_draw(dst_x, dst_y,
688 - dst_x + width, dst_y + height,
689 - uv_left, uv_top, uv_right, uv_bottom, effect);
690 + //FIXME: support parameter "alpha"
691 + SDL_Surface* surface = texture->getSurface();
693 + // get and check SDL_Surface
694 + if (surface == 0) {
695 + std::cerr << "Warning: Tried to draw NULL surface, skipped draw" << std::endl;
699 + SDL_Surface* transformedSurface = surface;
701 + if (flipx) effect = HORIZONTAL_FLIP;
703 + if (effect != NO_EFFECT) {
704 + transformedSurface = 0;
706 + // check if we have this effect buffered
707 + for (std::list<TransformedSurface*>::const_iterator i = transformedSurfaces.begin(); i != transformedSurfaces.end(); i++) {
708 + if ((*i)->effect == effect) transformedSurface = (*i)->surface;
711 + // if not: transform and buffer
712 + if (!transformedSurface) {
713 + if (effect == HORIZONTAL_FLIP) transformedSurface = zoomSurface(surface, -1, 1, 0);
714 + if (effect == VERTICAL_FLIP) transformedSurface = zoomSurface(surface, 1, -1, 0);
715 + if (transformedSurface == 0) {
716 + std::cerr << "Warning: No known transformation applies to surface, skipped draw" << std::endl;
719 + TransformedSurface* su = new TransformedSurface();
720 + su->surface = transformedSurface;
721 + su->effect = effect;
723 + transformedSurfaces.push_front(su);
727 + int ox = offsetx; if (effect == HORIZONTAL_FLIP) ox = static_cast<int>(surface->w) - (ox+static_cast<int>(width));
728 + int oy = offsety; if (effect == VERTICAL_FLIP) oy = static_cast<int>(surface->h) - (oy+static_cast<int>(height));
729 + // draw surface to screen
730 + SDL_Surface* screen = SDL_GetVideoSurface();
733 + srcRect.x = static_cast<int>(ox+src_x);
734 + srcRect.y = static_cast<int>(oy+src_y);
735 + srcRect.w = static_cast<int>(width);
736 + srcRect.h = static_cast<int>(height);
739 + dstRect.x = static_cast<int>(dst_x);
740 + dstRect.y = static_cast<int>(dst_y);
742 + SDL_BlitSurface(transformedSurface, &srcRect, screen, &dstRect);
745 diff -Naur supertux/src/video/surface.hpp supertux-nogl/src/video/surface.hpp
746 --- supertux/src/video/surface.hpp 2006-03-03 20:34:27.000000000 +0100
747 +++ supertux-nogl/src/video/surface.hpp 2006-04-07 04:11:49.000000000 +0200
749 #ifndef __SURFACE_HPP__
750 #define __SURFACE_HPP__
752 +#include <SDL_image.h>
762 + * Helper class to buffer a pre-transformed SDL_Surface
764 +class TransformedSurface {
766 + SDL_Surface* surface;
767 + DrawingEffect effect;
771 * A rectangular image.
772 * The class basically holds a reference to a texture with additional UV
773 * coordinates that specify a rectangular area on this texture
776 ImageTexture* texture;
784 + /** draw the surface on the screen, applying a ::DrawingEffect on-the-fly. Transformed Surfaces will be cached in ::transformedSurfaces */
785 void draw(float x, float y, float alpha, DrawingEffect effect) const;
787 + /** draw the surface on the screen, applying a ::DrawingEffect on-the-fly. Transformed Surfaces will be cached in ::transformedSurfaces */
788 void draw_part(float src_x, float src_y, float dst_x, float dst_y,
789 float width, float height,
790 float alpha, DrawingEffect effect) const;
794 + int offsetx; /**< Region in ::surface to be used for blitting */
795 + int offsety; /**< Region in ::surface to be used for blitting */
796 + int width; /**< Region in ::surface to be used for blitting */
797 + int height; /**< Region in ::surface to be used for blitting */
799 + mutable std::list<TransformedSurface*> transformedSurfaces; /**< Cache for pre-transformed surfaces */
802 Surface(const std::string& file);
803 Surface(const std::string& file, int x, int y, int w, int h);
804 diff -Naur supertux/src/video/texture.cpp supertux-nogl/src/video/texture.cpp
805 --- supertux/src/video/texture.cpp 2006-03-03 20:34:27.000000000 +0100
806 +++ supertux-nogl/src/video/texture.cpp 2006-04-07 04:11:49.000000000 +0200
809 #include "texture.hpp"
813 #include "glutil.hpp"
816 return (v & (v-1)) == 0;
819 -Texture::Texture(unsigned int w, unsigned int h, GLenum glformat)
820 +Texture::Texture(unsigned int w, unsigned int h, GLenum)
822 assert(is_power_of_2(w));
823 assert(is_power_of_2(h));
828 - assert_gl("before creating texture");
829 - glGenTextures(1, &handle);
832 - glBindTexture(GL_TEXTURE_2D, handle);
834 - glTexImage2D(GL_TEXTURE_2D, 0, glformat, width, height, 0, GL_RGBA,
835 - GL_UNSIGNED_BYTE, 0);
837 - set_texture_params();
839 - glDeleteTextures(1, &handle);
846 -Texture::Texture(SDL_Surface* image, GLenum glformat)
847 +Texture::Texture(SDL_Surface* image, GLenum)
849 const SDL_PixelFormat* format = image->format;
850 if(!is_power_of_2(image->w) || !is_power_of_2(image->h))
851 throw std::runtime_error("image has no power of 2 size");
852 if(format->BitsPerPixel != 24 && format->BitsPerPixel != 32)
853 throw std::runtime_error("image has no 24 or 32 bit color depth");
856 this->width = image->w;
857 this->height = image->h;
859 - assert_gl("before creating texture");
860 - glGenTextures(1, &handle);
864 - if(format->BytesPerPixel == 3)
865 - sdl_format = GL_RGB;
866 - else if(format->BytesPerPixel == 4)
867 - sdl_format = GL_RGBA;
871 - glBindTexture(GL_TEXTURE_2D, handle);
872 - glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
873 - glPixelStorei(GL_UNPACK_ROW_LENGTH, image->pitch/format->BytesPerPixel);
874 - glTexImage2D(GL_TEXTURE_2D, 0, glformat, width, height, 0, sdl_format,
875 - GL_UNSIGNED_BYTE, image->pixels);
877 - assert_gl("creating texture");
879 - set_texture_params();
881 - glDeleteTextures(1, &handle);
884 + surface = SDL_DisplayFormatAlpha(image);
889 - glDeleteTextures(1, &handle);
893 Texture::set_texture_params()
895 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
896 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
897 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
898 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
900 - assert_gl("set texture params");
903 diff -Naur supertux/src/video/texture.hpp supertux-nogl/src/video/texture.hpp
904 --- supertux/src/video/texture.hpp 2006-03-03 20:34:27.000000000 +0100
905 +++ supertux-nogl/src/video/texture.hpp 2006-04-07 04:11:49.000000000 +0200
907 #define __TEXTURE_HPP__
911 +#include "glutil.hpp"
914 * This class is a wrapper around a texture handle. It stores the texture width
919 + SDL_Surface* surface; /**< non-GL branch stores optimized surface */
921 friend class TextureManager;
927 Texture(SDL_Surface* surface, GLenum glformat);
930 - GLuint get_handle() const
935 unsigned int get_width() const
942 + SDL_Surface* getSurface() {
946 + void setSurface(SDL_Surface* surface) {
947 + this->surface = surface;
951 void set_texture_params();
953 diff -Naur supertux/src/video/texture_manager.cpp supertux-nogl/src/video/texture_manager.cpp
954 --- supertux/src/video/texture_manager.cpp 2006-04-07 03:32:13.000000000 +0200
955 +++ supertux-nogl/src/video/texture_manager.cpp 2006-04-07 04:11:49.000000000 +0200
959 #include <SDL_image.h>
961 -#include <GL/glext.h>
967 TextureManager::save_textures()
969 - glPixelStorei(GL_PACK_ROW_LENGTH, 0);
970 - glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
971 - glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
972 - glPixelStorei(GL_PACK_SKIP_ROWS, 0);
973 - glPixelStorei(GL_PACK_SKIP_IMAGES, 0);
974 - glPixelStorei(GL_PACK_ALIGNMENT, 1);
975 for(Textures::iterator i = textures.begin(); i != textures.end(); ++i) {
978 @@ -146,75 +138,16 @@
980 SavedTexture saved_texture;
981 saved_texture.texture = texture;
982 - glBindTexture(GL_TEXTURE_2D, texture->get_handle());
983 - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH,
984 - &saved_texture.width);
985 - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT,
986 - &saved_texture.height);
987 - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BORDER,
988 - &saved_texture.border);
989 - glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
990 - &saved_texture.min_filter);
991 - glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
992 - &saved_texture.mag_filter);
993 - glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
994 - &saved_texture.wrap_s);
995 - glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
996 - &saved_texture.wrap_t);
998 size_t pixelssize = saved_texture.width * saved_texture.height * 4;
999 saved_texture.pixels = new char[pixelssize];
1001 - glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1002 - saved_texture.pixels);
1004 saved_textures.push_back(saved_texture);
1006 - glDeleteTextures(1, &(texture->handle));
1007 - texture->handle = 0;
1009 - assert_gl("retrieving texture for save");
1013 TextureManager::reload_textures()
1015 - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1016 - glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
1017 - glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
1018 - glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
1019 - glPixelStorei(GL_UNPACK_SKIP_IMAGES, 0);
1020 - glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1022 - for(std::vector<SavedTexture>::iterator i = saved_textures.begin();
1023 - i != saved_textures.end(); ++i) {
1024 - SavedTexture& saved_texture = *i;
1027 - glGenTextures(1, &handle);
1028 - assert_gl("creating texture handle");
1030 - glBindTexture(GL_TEXTURE_2D, handle);
1031 - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
1032 - saved_texture.width, saved_texture.height,
1033 - saved_texture.border, GL_RGBA,
1034 - GL_UNSIGNED_BYTE, saved_texture.pixels);
1035 - delete[] saved_texture.pixels;
1036 - assert_gl("uploading texture pixel data");
1038 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
1039 - saved_texture.min_filter);
1040 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
1041 - saved_texture.mag_filter);
1042 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
1043 - saved_texture.wrap_s);
1044 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
1045 - saved_texture.wrap_t);
1047 - assert_gl("setting texture_params");
1048 - saved_texture.texture->handle = handle;
1051 saved_textures.clear();
1054 diff -Naur supertux/src/video/texture_manager.hpp supertux-nogl/src/video/texture_manager.hpp
1055 --- supertux/src/video/texture_manager.hpp 2006-03-03 20:34:27.000000000 +0100
1056 +++ supertux-nogl/src/video/texture_manager.hpp 2006-04-07 04:11:49.000000000 +0200
1058 #ifndef __IMAGE_TEXTURE_MANAGER_HPP__
1059 #define __IMAGE_TEXTURE_MANAGER_HPP__
1062 +#include "video/glutil.hpp"