summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rwxr-xr-xconfigure.ac2
-rw-r--r--src/Makefile.am6
-rw-r--r--src/graphics.cpp13
-rw-r--r--src/graphics.h6
-rw-r--r--src/gui/gui.cpp24
-rw-r--r--src/gui/gui.h2
-rw-r--r--src/openglgraphics.cpp115
-rw-r--r--src/openglgraphics.h7
-rw-r--r--src/resources/image.cpp66
-rw-r--r--src/resources/image.h7
-rw-r--r--src/resources/imageloader.cpp99
-rw-r--r--src/resources/imageloader.h69
-rw-r--r--src/resources/openglsdlimageloader.cpp41
-rw-r--r--src/resources/openglsdlimageloader.h38
-rw-r--r--src/resources/sdlimageloader.cpp34
-rw-r--r--src/resources/sdlimageloader.h37
17 files changed, 311 insertions, 269 deletions
diff --git a/ChangeLog b/ChangeLog
index 2e0e1b2e..93d2d122 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2007-08-25 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+
+ * configure.ac: Removed dependency on Guichan's OpenGL library.
+ * src/Makefile.am, src/resources/sdlimageloader.cpp,
+ src/resources/sdlimageloader.h, src/resources/openglsdlimageloader.h,
+ src/resources/openglsdlimageloader.cpp, src/resources/imageloader.cpp,
+ src/resources/imageloader.h, src/gui/gui.cpp, src/gui/gui.h: Replaced
+ Guichan's image loaders with our owns, so that we have control over all
+ the images used as textures.
+ * src/resources/image.cpp, src/openglgraphics.h, src/resources/image.h,
+ src/openglgraphics.cpp, src/graphics.cpp, src/graphics.h: Added support
+ for rectangle OpenGL textures when available, in order to reduce video
+ memory usage.
+
2007-08-19 Bjørn Lindeijer <bjorn@lindeijer.nl>
* src/CMakeLists.txt: Updated CMake file.
diff --git a/configure.ac b/configure.ac
index 5e106045..c3f14337 100755
--- a/configure.ac
+++ b/configure.ac
@@ -100,8 +100,6 @@ else
with_opengl=yes
AC_CHECK_LIB([GL], [glBegin], ,
AC_MSG_ERROR([ *** Unable to find OpenGL library]))
- AC_CHECK_LIB([guichan_opengl], [gcnOpenGL], ,
- AC_MSG_ERROR([ *** Unable to find Guichan OpenGL library (guichan.sf.net)]))
AC_DEFINE(USE_OPENGL, 1, [Defines if tmw should use an OpenGL display])
fi
diff --git a/src/Makefile.am b/src/Makefile.am
index ea40d5de..1fe12518 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -196,6 +196,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \
resources/equipmentinfo.h \
resources/image.cpp \
resources/image.h \
+ resources/imageloader.cpp \
+ resources/imageloader.h \
resources/imagewriter.cpp \
resources/imagewriter.h \
resources/itemdb.cpp \
@@ -210,14 +212,10 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \
resources/monsterinfo.cpp \
resources/music.h \
resources/music.cpp \
- resources/openglsdlimageloader.h \
- resources/openglsdlimageloader.cpp \
resources/resource.cpp \
resources/resource.h \
resources/resourcemanager.cpp \
resources/resourcemanager.h \
- resources/sdlimageloader.h \
- resources/sdlimageloader.cpp \
resources/soundeffect.h \
resources/soundeffect.cpp \
resources/spritedef.h \
diff --git a/src/graphics.cpp b/src/graphics.cpp
index 1e31f903..5ece979d 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -21,11 +21,13 @@
* $Id$
*/
+#include <cassert>
+
#include "graphics.h"
#include "log.h"
-
#include "resources/image.h"
+#include "resources/imageloader.h"
Graphics::Graphics():
mScreen(0)
@@ -146,6 +148,15 @@ bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY,
return !(SDL_BlitSurface(image->mImage, &srcRect, mScreen, &dstRect) < 0);
}
+void Graphics::drawImage(gcn::Image const *image, int srcX, int srcY,
+ int dstX, int dstY, int width, int height)
+{
+ ProxyImage const *srcImage =
+ dynamic_cast< ProxyImage const * >(image);
+ assert(srcImage);
+ drawImage(srcImage->getImage(), srcX, srcY, dstX, dstY, width, height);
+}
+
void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h)
{
int iw = image->getWidth();
diff --git a/src/graphics.h b/src/graphics.h
index 4637973f..e12b066e 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -86,6 +86,12 @@ class Graphics : public gcn::SDLGraphics {
bool drawImage(Image *image, int x, int y);
/**
+ * Overrides with our own drawing method.
+ */
+ void drawImage(gcn::Image const *image, int srcX, int srcY,
+ int dstX, int dstY, int width, int height);
+
+ /**
* Blits an image onto the screen.
*
* @return <code>true</code> if the image was blitted properly
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 8f1cc7f4..620dfb0b 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -30,10 +30,6 @@
// Should stay here because of Guichan being sensitive to headers order
#include <guichan/sdl/sdlinput.hpp>
-#ifdef USE_OPENGL
-#include "../resources/openglsdlimageloader.h"
-#endif
-
#include "focushandler.h"
#include "window.h"
#include "windowcontainer.h"
@@ -46,10 +42,7 @@
#include "../resources/image.h"
#include "../resources/resourcemanager.h"
-#include "../resources/sdlimageloader.h"
-#ifdef USE_OPENGL
-#include "../resources/openglsdlimageloader.h"
-#endif
+#include "../resources/imageloader.h"
// Guichan stuff
Gui *gui;
@@ -82,7 +75,6 @@ class GuiConfigListener : public ConfigListener
};
Gui::Gui(Graphics *graphics):
- mHostImageLoader(NULL),
mMouseCursor(NULL),
mCustomCursor(false)
{
@@ -91,21 +83,13 @@ Gui::Gui(Graphics *graphics):
setGraphics(graphics);
// Set image loader
-#ifdef USE_OPENGL
- if (config.getValue("opengl", 0)) {
- mImageLoader = new OpenGLSDLImageLoader();
- } else
-#endif
- {
- mImageLoader = new SDLImageLoader();
- }
+ static ImageLoader imageLoader;
+ gcn::Image::setImageLoader(&imageLoader);
// Set input
guiInput = new gcn::SDLInput();
setInput(guiInput);
- gcn::Image::setImageLoader(mImageLoader);
-
// Set focus handler
delete mFocusHandler;
mFocusHandler = new FocusHandler();
@@ -189,8 +173,6 @@ Gui::~Gui()
delete speechFont;
delete viewport;
delete mTop;
- delete mImageLoader;
- delete mHostImageLoader;
delete guiInput;
}
diff --git a/src/gui/gui.h b/src/gui/gui.h
index caf27744..5f2cc810 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -86,8 +86,6 @@ class Gui : public gcn::Gui
private:
GuiConfigListener *mConfigListener;
- gcn::ImageLoader *mHostImageLoader; /**< For loading images in GL */
- gcn::ImageLoader *mImageLoader; /**< For loading images */
gcn::Font *mGuiFont; /**< The global GUI font */
Image *mMouseCursor; /**< Mouse cursor image */
bool mCustomCursor; /**< Show custom cursor */
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index f4cda0b9..b1e6ef81 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -27,6 +27,7 @@
#include "openglgraphics.h"
+#include <cstring>
#include <SDL.h>
#ifdef __APPLE__
@@ -83,6 +84,23 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
logger->log("Using OpenGL %s double buffering.",
(gotDoubleBuffer ? "with" : "without"));
+ char const *glExtensions = (char const *)glGetString(GL_EXTENSIONS);
+ int texSize;
+ bool rectTex = strstr(glExtensions, "GL_ARB_texture_rectangle");
+ if (rectTex)
+ {
+ Image::mTextureType = GL_TEXTURE_RECTANGLE_ARB;
+ glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &texSize);
+ }
+ else
+ {
+ Image::mTextureType = GL_TEXTURE_2D;
+ glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
+ }
+ Image::mTextureSize = texSize;
+ logger->log("OpenGL texture size: %d pixels%s", Image::mTextureSize,
+ rectTex ? " (rectangle textures)" : "");
+
return true;
}
@@ -92,17 +110,44 @@ bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY,
srcX += image->mBounds.x;
srcY += image->mBounds.y;
- // Find OpenGL texture coordinates
- float texX1 = srcX / (float)image->mTexWidth;
- float texY1 = srcY / (float)image->mTexHeight;
- float texX2 = (srcX + width) / (float)image->mTexWidth;
- float texY2 = (srcY + height) / (float)image->mTexHeight;
-
glColor4f(1.0f, 1.0f, 1.0f, image->mAlpha);
- glBindTexture(GL_TEXTURE_2D, image->mGLImage);
+ glBindTexture(Image::mTextureType, image->mGLImage);
+
+ setTexturingAndBlending(true);
+
+ // Draw a textured quad.
+ glBegin(GL_QUADS);
- drawTexedQuad(dstX, dstY, width, height, texX1, texY1, texX2, texY2);
+ if (Image::mTextureType == GL_TEXTURE_2D)
+ {
+ // Find OpenGL normalized texture coordinates.
+ float texX1 = srcX / (float)image->mTexWidth;
+ float texY1 = srcY / (float)image->mTexHeight;
+ float texX2 = (srcX + width) / (float)image->mTexWidth;
+ float texY2 = (srcY + height) / (float)image->mTexHeight;
+
+ glTexCoord2f(texX1, texY1);
+ glVertex2i(dstX, dstY);
+ glTexCoord2f(texX2, texY1);
+ glVertex2i(dstX + width, dstY);
+ glTexCoord2f(texX2, texY2);
+ glVertex2i(dstX + width, dstY + height);
+ glTexCoord2f(texX1, texY2);
+ glVertex2i(dstX, dstY + height);
+ }
+ else
+ {
+ glTexCoord2i(srcX, srcY);
+ glVertex2i(dstX, dstY);
+ glTexCoord2i(srcX + width, srcY);
+ glVertex2i(dstX + width, dstY);
+ glTexCoord2i(srcX + width, srcY + height);
+ glVertex2i(dstX + width, dstY + height);
+ glTexCoord2i(srcX, srcY + height);
+ glVertex2i(dstX, dstY + height);
+ }
+ glEnd();
glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a);
return true;
@@ -229,33 +274,6 @@ void OpenGLGraphics::setColor(const gcn::Color& color)
mColorAlpha = (color.a != 255);
}
-void OpenGLGraphics::drawImage(const gcn::Image* image,
- int srcX, int srcY,
- int dstX, int dstY,
- int width, int height)
-{
- const gcn::OpenGLImage* srcImage =
- dynamic_cast<const gcn::OpenGLImage*>(image);
-
- if (srcImage == NULL)
- {
- throw GCN_EXCEPTION("Trying to draw an image of unknown format, "
- "must be an SDLImage.");
- }
-
- // Find OpenGL texture coordinates
- float texX1 = srcX / (float)srcImage->getTextureWidth();
- float texY1 = srcY / (float)srcImage->getTextureHeight();
- float texX2 = (srcX + width) / (float)srcImage->getTextureWidth();
- float texY2 = (srcY + height) / (float)srcImage->getTextureHeight();
-
- // Please dont look too closely at the next line, it is not pretty.
- // It uses the image data as a pointer to a GLuint
- glBindTexture(GL_TEXTURE_2D, srcImage->getTextureHandle());
-
- drawTexedQuad(dstX, dstY, width, height, texX1, texY1, texX2, texY2);
-}
-
void OpenGLGraphics::drawPoint(int x, int y)
{
setTexturingAndBlending(false);
@@ -297,9 +315,9 @@ void OpenGLGraphics::setTexturingAndBlending(bool enable)
{
if (enable) {
if (!mTexture) {
- glEnable(GL_TEXTURE_2D);
+ glEnable(Image::mTextureType);
mTexture = true;
- };
+ }
if (!mAlpha)
{
@@ -316,7 +334,7 @@ void OpenGLGraphics::setTexturingAndBlending(bool enable)
}
if (mTexture) {
- glDisable(GL_TEXTURE_2D);
+ glDisable(Image::mTextureType);
mTexture = false;
}
}
@@ -336,25 +354,4 @@ void OpenGLGraphics::drawRectangle(const gcn::Rectangle& rect, bool filled)
glEnd();
}
-void OpenGLGraphics::drawTexedQuad(int x, int y, int w, int h,
- float texX1, float texY1, float texX2, float texY2)
-{
- setTexturingAndBlending(true);
-
- // Draw a textured quad
- glBegin(GL_QUADS);
- glTexCoord2f(texX1, texY1);
- glVertex2i(x, y);
-
- glTexCoord2f(texX2, texY1);
- glVertex2i(x + w, y);
-
- glTexCoord2f(texX2, texY2);
- glVertex2i(x + w, y + h);
-
- glTexCoord2f(texX1, texY2);
- glVertex2i(x, y + h);
- glEnd();
-}
-
#endif // USE_OPENGL
diff --git a/src/openglgraphics.h b/src/openglgraphics.h
index c61ae66c..36e6efcd 100644
--- a/src/openglgraphics.h
+++ b/src/openglgraphics.h
@@ -50,11 +50,6 @@ class OpenGLGraphics : public Graphics
void setColor(const gcn::Color &color);
- void drawImage(const gcn::Image* image,
- int srcX, int srcY,
- int dstX, int dstY,
- int width, int height);
-
void drawPoint(int x, int y);
void drawLine(int x1, int y1, int x2, int y2);
@@ -74,8 +69,6 @@ class OpenGLGraphics : public Graphics
protected:
void setTexturingAndBlending(bool enable);
- void drawTexedQuad(int x, int y, int w, int h,
- float texX1, float texY1, float texX2, float texY2);
private:
bool mAlpha, mTexture;
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index ad280eeb..995e34b0 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -29,6 +29,8 @@
#ifdef USE_OPENGL
bool Image::mUseOpenGL = false;
+int Image::mTextureType = 0;
+int Image::mTextureSize = 0;
#endif
Image::Image(const std::string &idPath, SDL_Surface *image):
@@ -89,23 +91,21 @@ Image* Image::load(void *buffer, unsigned int bufferSize,
return NULL;
}
- // Determine 32-bit masks based on byte order
- Uint32 rmask, gmask, bmask, amask;
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- rmask = 0xff000000;
- gmask = 0x00ff0000;
- bmask = 0x0000ff00;
- amask = 0x000000ff;
-#else
- rmask = 0x000000ff;
- gmask = 0x0000ff00;
- bmask = 0x00ff0000;
- amask = 0xff000000;
-#endif
+ Image *image = load(tmpImage, idPath);
+
+ SDL_FreeSurface(tmpImage);
+ return image;
+}
+
+Image *Image::load(SDL_Surface *tmpImage, std::string const &idPath)
+{
#ifdef USE_OPENGL
if (mUseOpenGL)
{
+ // Flush current error flag.
+ glGetError();
+
int width = tmpImage->w;
int height = tmpImage->h;
int realWidth = powerOfTwo(width);
@@ -120,6 +120,20 @@ Image* Image::load(void *buffer, unsigned int bufferSize,
// Make sure the alpha channel is not used, but copied to destination
SDL_SetAlpha(tmpImage, 0, SDL_ALPHA_OPAQUE);
+ // Determine 32-bit masks based on byte order
+ Uint32 rmask, gmask, bmask, amask;
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ rmask = 0xff000000;
+ gmask = 0x00ff0000;
+ bmask = 0x0000ff00;
+ amask = 0x000000ff;
+#else
+ rmask = 0x000000ff;
+ gmask = 0x0000ff00;
+ bmask = 0x00ff0000;
+ amask = 0xff000000;
+#endif
+
SDL_Surface *oldImage = tmpImage;
tmpImage = SDL_CreateRGBSurface(SDL_SWSURFACE, realWidth, realHeight,
32, rmask, gmask, bmask, amask);
@@ -130,25 +144,24 @@ Image* Image::load(void *buffer, unsigned int bufferSize,
}
SDL_BlitSurface(oldImage, NULL, tmpImage, NULL);
- SDL_FreeSurface(oldImage);
GLuint texture;
glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
+ glBindTexture(mTextureType, texture);
if (SDL_MUSTLOCK(tmpImage)) {
SDL_LockSurface(tmpImage);
}
glTexImage2D(
- GL_TEXTURE_2D, 0, 4,
+ mTextureType, 0, 4,
tmpImage->w, tmpImage->h,
0, GL_RGBA, GL_UNSIGNED_BYTE,
tmpImage->pixels);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
if (SDL_MUSTLOCK(tmpImage)) {
SDL_UnlockSurface(tmpImage);
@@ -219,7 +232,6 @@ Image* Image::load(void *buffer, unsigned int bufferSize,
else {
image = SDL_DisplayFormat(tmpImage);
}
- SDL_FreeSurface(tmpImage);
if (!image) {
logger->log("Error: Image convert failed.");
@@ -289,12 +301,20 @@ Image::setLoadAsOpenGL(bool useOpenGL)
int
Image::powerOfTwo(int input)
{
- int value = 1;
- while (value < input && value < 1024)
+ int value;
+ if (mTextureType == GL_TEXTURE_2D)
+ {
+ value = 1;
+ while (value < input && value < mTextureSize)
+ {
+ value <<= 1;
+ }
+ }
+ else
{
- value <<= 1;
+ value = input;
}
- return value;
+ return value >= mTextureSize ? mTextureSize : value;
}
#endif
diff --git a/src/resources/image.h b/src/resources/image.h
index cad21dcd..34515dda 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -71,6 +71,11 @@ class Image : public Resource
load(void* buffer, unsigned int bufferSize, const std::string &idPath);
/**
+ * Loads an image from an SDL surface.
+ */
+ static Image *load(SDL_Surface *, std::string const &idPath);
+
+ /**
* Frees the resources created by SDL.
*/
virtual void
@@ -143,6 +148,8 @@ class Image : public Resource
int mTexWidth, mTexHeight;
static bool mUseOpenGL;
+ static int mTextureType;
+ static int mTextureSize;
#endif
SDL_Surface *mImage;
float mAlpha;
diff --git a/src/resources/imageloader.cpp b/src/resources/imageloader.cpp
new file mode 100644
index 00000000..b2053dcc
--- /dev/null
+++ b/src/resources/imageloader.cpp
@@ -0,0 +1,99 @@
+/*
+ * The Mana World
+ * Copyright 2007 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include <cassert>
+#include <string>
+#include <guichan/color.hpp>
+#include <guichan/sdl/sdlpixel.hpp>
+
+#include "imageloader.h"
+
+#include "image.h"
+#include "resourcemanager.h"
+
+ProxyImage::ProxyImage(SDL_Surface *s):
+ mImage(NULL), mSDLImage(s)
+{
+}
+
+ProxyImage::~ProxyImage()
+{
+ free();
+}
+
+void ProxyImage::free()
+{
+ if (mSDLImage)
+ {
+ SDL_FreeSurface(mSDLImage);
+ mSDLImage = NULL;
+ }
+ else if (mImage)
+ {
+ delete mImage;
+ mImage = NULL;
+ }
+}
+
+int ProxyImage::getWidth() const
+{
+ return mSDLImage ? mSDLImage->w : mImage->getWidth();
+}
+
+int ProxyImage::getHeight() const
+{
+ return mSDLImage ? mSDLImage->h : mImage->getHeight();
+}
+
+gcn::Color ProxyImage::getPixel(int x, int y)
+{
+ assert(mSDLImage);
+ return gcn::SDLgetPixel(mSDLImage, x, y);
+}
+
+void ProxyImage::putPixel(int x, int y, gcn::Color const &color)
+{
+ assert(mSDLImage);
+ gcn::SDLputPixel(mSDLImage, x, y, color);
+}
+
+void ProxyImage::convertToDisplayFormat()
+{
+ assert(mSDLImage);
+ /* The picture is most probably full of the pink pixels Guichan uses for
+ transparency, as this function will only be called when setting an image
+ font. Get rid of them. */
+ SDL_SetColorKey(mSDLImage, SDL_SRCCOLORKEY,
+ SDL_MapRGB(mSDLImage->format, 255, 0, 255));
+ mImage = ::Image::load(mSDLImage, std::string());
+ SDL_FreeSurface(mSDLImage);
+ mSDLImage = NULL;
+}
+
+gcn::Image *ImageLoader::load(std::string const &filename, bool convert)
+{
+ ResourceManager *resman = ResourceManager::getInstance();
+ ProxyImage *i = new ProxyImage(resman->loadSDLSurface(filename));
+ if (convert) i->convertToDisplayFormat();
+ return i;
+}
diff --git a/src/resources/imageloader.h b/src/resources/imageloader.h
new file mode 100644
index 00000000..f41f6472
--- /dev/null
+++ b/src/resources/imageloader.h
@@ -0,0 +1,69 @@
+/*
+ * The Mana World
+ * Copyright 2007 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_IMAGELOADER_H
+#define _TMW_IMAGELOADER_H
+
+#include <string>
+
+#include <guichan/image.hpp>
+#include <guichan/imageloader.hpp>
+
+class Image;
+struct SDL_Surface;
+
+class ProxyImage : public gcn::Image
+{
+ public:
+ ProxyImage(SDL_Surface *);
+ ~ProxyImage();
+ void free();
+ int getWidth() const;
+ int getHeight() const;
+ gcn::Color getPixel(int x, int y);
+ void putPixel(int x, int y, gcn::Color const &color);
+ void convertToDisplayFormat();
+
+ /**
+ * Gets the image handled by this proxy.
+ */
+ ::Image *getImage() const
+ { return mImage; }
+
+ private:
+ ::Image *mImage; /**< The real image. */
+
+ /**
+ * An SDL surface kept around until Guichan is done reading pixels from
+ * an OpenGL texture.
+ */
+ SDL_Surface *mSDLImage;
+};
+
+class ImageLoader : public gcn::ImageLoader
+{
+ public:
+ gcn::Image *load(std::string const &filename, bool convertToDisplayFormat);
+};
+
+#endif
diff --git a/src/resources/openglsdlimageloader.cpp b/src/resources/openglsdlimageloader.cpp
deleted file mode 100644
index 9b6645bd..00000000
--- a/src/resources/openglsdlimageloader.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * The Mana World
- * Copyright 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * The Mana World is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * The Mana World is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with The Mana World; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id$
- */
-
-#include "openglsdlimageloader.h"
-
-#include <string>
-
-#include "resourcemanager.h"
-
-#include "../main.h"
-
-#ifdef USE_OPENGL
-
-SDL_Surface*
-OpenGLSDLImageLoader::loadSDLSurface(const std::string &filename)
-{
- ResourceManager *resman = ResourceManager::getInstance();
- return resman->loadSDLSurface(filename);
-}
-
-#endif
diff --git a/src/resources/openglsdlimageloader.h b/src/resources/openglsdlimageloader.h
deleted file mode 100644
index d776dafe..00000000
--- a/src/resources/openglsdlimageloader.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * The Mana World
- * Copyright 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * The Mana World is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * The Mana World is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with The Mana World; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id$
- */
-
-#ifndef _TMW_OPENGLSDLIMAGELOADER_H
-#define _TMW_OPENGLSDLIMAGELOADER_H
-
-#include <iosfwd>
-
-#include <guichan/opengl/openglsdlimageloader.hpp>
-
-class OpenGLSDLImageLoader : public gcn::OpenGLSDLImageLoader
-{
- protected:
- SDL_Surface*
- loadSDLSurface(const std::string &filename);
-};
-
-#endif
diff --git a/src/resources/sdlimageloader.cpp b/src/resources/sdlimageloader.cpp
deleted file mode 100644
index ae4f4dcb..00000000
--- a/src/resources/sdlimageloader.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * The Mana World
- * Copyright 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * The Mana World is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * The Mana World is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with The Mana World; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id$
- */
-
-#include "sdlimageloader.h"
-
-#include <string>
-
-#include "resourcemanager.h"
-
-SDL_Surface* SDLImageLoader::loadSDLSurface(const std::string& filename)
-{
- ResourceManager *resman = ResourceManager::getInstance();
- return resman->loadSDLSurface(filename);
-}
diff --git a/src/resources/sdlimageloader.h b/src/resources/sdlimageloader.h
deleted file mode 100644
index 50b1d4f1..00000000
--- a/src/resources/sdlimageloader.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * The Mana World
- * Copyright 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * The Mana World is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * The Mana World is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with The Mana World; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id$
- */
-
-#ifndef _TMW_SDLIMAGELOADER_H
-#define _TMW_SDLIMAGELOADER_H
-
-#include <iosfwd>
-
-#include <guichan/sdl/sdlimageloader.hpp>
-
-class SDLImageLoader : public gcn::SDLImageLoader
-{
- protected:
- SDL_Surface* loadSDLSurface(const std::string& filename);
-};
-
-#endif