summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/image.cpp174
-rw-r--r--src/resources/image.h21
-rw-r--r--src/resources/imageloader.cpp98
-rw-r--r--src/resources/imageloader.h69
-rw-r--r--src/resources/theme.cpp1
-rw-r--r--src/resources/theme.h1
6 files changed, 102 insertions, 262 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 975bd647..7e592198 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -36,6 +36,7 @@
#ifdef USE_OPENGL
bool Image::mUseOpenGL = false;
+bool Image::mPowerOfTwoTextures = true;
int Image::mTextureType = 0;
int Image::mTextureSize = 0;
#endif
@@ -437,103 +438,113 @@ Image *Image::_SDLload(SDL_Surface *tmpImage)
}
#ifdef USE_OPENGL
-Image *Image::_GLload(SDL_Surface *tmpImage)
+Image *Image::_GLload(SDL_Surface *image)
{
- // Flush current error flag.
- glGetError();
+ // Flush current error flag.
+ glGetError();
- int width = tmpImage->w;
- int height = tmpImage->h;
- int realWidth = powerOfTwo(width);
- int realHeight = powerOfTwo(height);
+ int width = image->w;
+ int height = image->h;
+ int realWidth = powerOfTwo(width);
+ int realHeight = powerOfTwo(height);
- if (realWidth < width || realHeight < height)
- {
- logger->log("Warning: image too large, cropping to %dx%d texture!",
- tmpImage->w, tmpImage->h);
- }
-
- // Make sure the alpha channel is not used, but copied to destination
- SDL_SetAlpha(tmpImage, 0, SDL_ALPHA_OPAQUE);
+ if (realWidth < width || realHeight < height)
+ {
+ logger->log("Warning: image too large, cropping to %dx%d texture!",
+ realWidth, realHeight);
+ }
- // Determine 32-bit masks based on byte order
- Uint32 rmask, gmask, bmask, amask;
+ // 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;
+ rmask = 0xff000000;
+ gmask = 0x00ff0000;
+ bmask = 0x0000ff00;
+ amask = 0x000000ff;
#else
- rmask = 0x000000ff;
- gmask = 0x0000ff00;
- bmask = 0x00ff0000;
- amask = 0xff000000;
+ 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);
+ bool needsConversion = !(realWidth == width &&
+ realHeight == height &&
+ image->format->BytesPerPixel == 4 &&
+ image->format->Rmask == rmask &&
+ image->format->Gmask == gmask &&
+ image->format->Bmask == bmask &&
+ image->format->Amask == amask);
+
+ if (needsConversion)
+ {
+ SDL_Surface *oldImage = image;
+ image = SDL_CreateRGBSurface(SDL_SWSURFACE, realWidth, realHeight,
+ 32, rmask, gmask, bmask, amask);
- if (!tmpImage)
+ if (!image)
{
logger->log("Error, image convert failed: out of memory");
return NULL;
}
- SDL_BlitSurface(oldImage, NULL, tmpImage, NULL);
+ // Make sure the alpha channel is not used, but copied to destination
+ SDL_SetAlpha(oldImage, 0, SDL_ALPHA_OPAQUE);
+ SDL_BlitSurface(oldImage, NULL, image, NULL);
+ }
- GLuint texture;
- glGenTextures(1, &texture);
- OpenGLGraphics::bindTexture(mTextureType, texture);
+ GLuint texture;
+ glGenTextures(1, &texture);
+ OpenGLGraphics::bindTexture(mTextureType, texture);
- if (SDL_MUSTLOCK(tmpImage))
- SDL_LockSurface(tmpImage);
+ if (SDL_MUSTLOCK(image))
+ SDL_LockSurface(image);
- glTexImage2D(
- mTextureType, 0, 4,
- tmpImage->w, tmpImage->h,
- 0, GL_RGBA, GL_UNSIGNED_BYTE,
- tmpImage->pixels);
+ glTexImage2D(mTextureType, 0, GL_RGBA8,
+ image->w, image->h,
+ 0, GL_RGBA, GL_UNSIGNED_BYTE,
+ image->pixels);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- if (SDL_MUSTLOCK(tmpImage))
- SDL_UnlockSurface(tmpImage);
+ if (SDL_MUSTLOCK(image))
+ SDL_UnlockSurface(image);
- SDL_FreeSurface(tmpImage);
+ if (needsConversion)
+ SDL_FreeSurface(image);
- GLenum error = glGetError();
- if (error)
+ GLenum error = glGetError();
+ if (error)
+ {
+ std::string errmsg = "Unknown error";
+ switch (error)
{
- std::string errmsg = "Unknown error";
- switch (error)
- {
- case GL_INVALID_ENUM:
- errmsg = "GL_INVALID_ENUM";
- break;
- case GL_INVALID_VALUE:
- errmsg = "GL_INVALID_VALUE";
- break;
- case GL_INVALID_OPERATION:
- errmsg = "GL_INVALID_OPERATION";
- break;
- case GL_STACK_OVERFLOW:
- errmsg = "GL_STACK_OVERFLOW";
- break;
- case GL_STACK_UNDERFLOW:
- errmsg = "GL_STACK_UNDERFLOW";
- break;
- case GL_OUT_OF_MEMORY:
- errmsg = "GL_OUT_OF_MEMORY";
- break;
- }
- logger->log("Error: Image GL import failed: %s", errmsg.c_str());
- return NULL;
+ case GL_INVALID_ENUM:
+ errmsg = "GL_INVALID_ENUM";
+ break;
+ case GL_INVALID_VALUE:
+ errmsg = "GL_INVALID_VALUE";
+ break;
+ case GL_INVALID_OPERATION:
+ errmsg = "GL_INVALID_OPERATION";
+ break;
+ case GL_STACK_OVERFLOW:
+ errmsg = "GL_STACK_OVERFLOW";
+ break;
+ case GL_STACK_UNDERFLOW:
+ errmsg = "GL_STACK_UNDERFLOW";
+ break;
+ case GL_OUT_OF_MEMORY:
+ errmsg = "GL_OUT_OF_MEMORY";
+ break;
}
+ logger->log("Error: Image GL import failed: %s", errmsg.c_str());
+ return NULL;
+ }
- return new Image(texture, width, height, realWidth, realHeight);
+ return new Image(texture, width, height, realWidth, realHeight);
}
void Image::setLoadAsOpenGL(bool useOpenGL)
@@ -544,7 +555,7 @@ void Image::setLoadAsOpenGL(bool useOpenGL)
int Image::powerOfTwo(int input)
{
int value;
- if (mTextureType == GL_TEXTURE_2D)
+ if (mPowerOfTwoTextures)
{
value = 1;
while (value < input && value < mTextureSize)
@@ -565,11 +576,17 @@ Image *Image::getSubImage(int x, int y, int width, int height)
// Create a new clipped sub-image
#ifdef USE_OPENGL
if (mUseOpenGL)
- return new SubImage(this, mGLImage, x, y, width, height,
+ return new SubImage(this, mGLImage,
+ mBounds.x + x,
+ mBounds.y + y,
+ width, height,
mTexWidth, mTexHeight);
#endif
- return new SubImage(this, mSDLSurface, x, y, width, height);
+ return new SubImage(this, mSDLSurface,
+ mBounds.x + x,
+ mBounds.y + y,
+ width, height);
}
void Image::SDLterminateAlphaCache()
@@ -636,8 +653,3 @@ SubImage::~SubImage()
#endif
mParent->decRef();
}
-
-Image *SubImage::getSubImage(int x, int y, int w, int h)
-{
- return mParent->getSubImage(mBounds.x + x, mBounds.y + y, w, h);
-}
diff --git a/src/resources/image.h b/src/resources/image.h
index 7df74c3f..b762bf2a 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -84,7 +84,7 @@ class Image : public Resource
/**
* Frees the resources created by SDL.
*/
- virtual void unload();
+ void unload();
/**
* Tells is the image is loaded
@@ -95,13 +95,13 @@ class Image : public Resource
/**
* Returns the width of the image.
*/
- virtual int getWidth() const
+ int getWidth() const
{ return mBounds.w; }
/**
* Returns the height of the image.
*/
- virtual int getHeight() const
+ int getHeight() const
{ return mBounds.h; }
/**
@@ -113,7 +113,7 @@ class Image : public Resource
/**
* Sets the alpha value of this image.
*/
- virtual void setAlpha(float alpha);
+ void setAlpha(float alpha);
/**
* Returns the alpha value of this image.
@@ -127,7 +127,7 @@ class Image : public Resource
* @return <code>NULL</code> if creation failed and a valid
* object otherwise.
*/
- virtual Image *getSubImage(int x, int y, int width, int height);
+ Image *getSubImage(int x, int y, int width, int height);
/**
* Tells if the image has got an alpha channel
@@ -243,12 +243,13 @@ class Image : public Resource
*/
static int powerOfTwo(int input);
- static Image *_GLload(SDL_Surface *tmpImage);
+ static Image *_GLload(SDL_Surface *image);
GLuint mGLImage;
int mTexWidth, mTexHeight;
static bool mUseOpenGL;
+ static bool mPowerOfTwoTextures;
static int mTextureType;
static int mTextureSize;
#endif
@@ -269,14 +270,6 @@ class SubImage : public Image
~SubImage();
- /**
- * Creates a new image with the desired clipping rectangle.
- *
- * @return <code>NULL</code> if creation failed and a valid
- * image otherwise.
- */
- Image *getSubImage(int x, int y, int width, int height);
-
private:
Image *mParent;
};
diff --git a/src/resources/imageloader.cpp b/src/resources/imageloader.cpp
deleted file mode 100644
index 262ec98c..00000000
--- a/src/resources/imageloader.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * The Mana Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2012 The Mana Developers
- *
- * This file is part of The Mana Client.
- *
- * This program 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.
- *
- * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "resources/imageloader.h"
-
-#include "resources/image.h"
-#include "resources/resourcemanager.h"
-
-#include <guichan/color.hpp>
-
-#include <guichan/sdl/sdlpixel.hpp>
-
-#include <cassert>
-
-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);
- SDL_FreeSurface(mSDLImage);
- mSDLImage = NULL;
-}
-
-gcn::Image *ImageLoader::load(const std::string &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
deleted file mode 100644
index 10592142..00000000
--- a/src/resources/imageloader.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * The Mana Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2012 The Mana Developers
- *
- * This file is part of The Mana Client.
- *
- * This program 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.
- *
- * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef IMAGELOADER_H
-#define IMAGELOADER_H
-
-#include <guichan/image.hpp>
-#include <guichan/imageloader.hpp>
-
-#include <string>
-
-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(const std::string &filename,
- bool convertToDisplayFormat);
-};
-
-#endif
diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp
index e95a1fa9..4b46b003 100644
--- a/src/resources/theme.cpp
+++ b/src/resources/theme.cpp
@@ -396,6 +396,7 @@ static int readColorType(const std::string &type)
{
static std::string colors[] = {
"TEXT",
+ "NPC_DIALOG_TEXT",
"SHADOW",
"OUTLINE",
"PROGRESS_BAR",
diff --git a/src/resources/theme.h b/src/resources/theme.h
index b2dd10de..9c1ec293 100644
--- a/src/resources/theme.h
+++ b/src/resources/theme.h
@@ -121,6 +121,7 @@ class Theme : public Palette, public EventListener
enum ThemePalette {
TEXT,
+ NPC_DIALOG_TEXT,
SHADOW,
OUTLINE,
PROGRESS_BAR,