diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/browserbox.cpp | 13 | ||||
-rw-r--r-- | src/gui/gui.cpp | 3 | ||||
-rw-r--r-- | src/main.cpp | 12 | ||||
-rw-r--r-- | src/resources/image.cpp | 96 | ||||
-rw-r--r-- | src/resources/image.h | 10 |
5 files changed, 84 insertions, 50 deletions
diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 5cae9fb7..6fc91858 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -21,16 +21,17 @@ * $Id$ */ +#include "browserbox.h" + #include <guichan/imagefont.hpp> -#ifdef USE_OPENGL -#include "../resources/resourcemanager.h" -#endif -#include "browserbox.h" #include "linkhandler.h" #include "gui.h" -extern bool useOpenGL; +#ifdef USE_OPENGL +#include "../configuration.h" +#include "../resources/resourcemanager.h" +#endif int BrowserBox::instances = 0; gcn::ImageFont* BrowserBox::browserFont; @@ -49,7 +50,7 @@ BrowserBox::BrowserBox(unsigned int mode): if (instances == 0) { #ifdef USE_OPENGL - if (useOpenGL) { + if (config.getValue("opengl", 0)) { browserFont = new gcn::ImageFont( ResourceManager::getInstance()->getRealPath( "graphics/gui/browserfont.png"), diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 2eaa9d76..197177cd 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -52,7 +52,6 @@ #include "../resources/resourcemanager.h" extern Being* autoTarget; -extern bool useOpenGL; // Guichan stuff Gui *gui; @@ -72,7 +71,7 @@ Gui::Gui(Graphics *graphics): mCustomCursor(false) { #ifdef USE_OPENGL - if (useOpenGL) { + if (config.getValue("opengl", 0)) { // Set graphics setGraphics((gcn::OpenGLGraphics*)graphics); diff --git a/src/main.cpp b/src/main.cpp index 24f9cb76..5d06cf97 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -76,7 +76,6 @@ short map_port; char map_name[16]; unsigned char state; unsigned char screen_mode; -bool useOpenGL = false; volatile int framesToDraw = 0; Sound sound; @@ -222,10 +221,6 @@ void init_engine() SDL_WM_SetCaption("The Mana World", NULL); SDL_WM_SetIcon(IMG_Load(TMW_DATADIR "data/icons/tmw-icon.png"), NULL); -#ifdef USE_OPENGL - useOpenGL = (config.getValue("opengl", 0) == 1); -#endif - int width, height, bpp; bool fullscreen, hwaccel; @@ -235,6 +230,13 @@ void init_engine() fullscreen = ((int)config.getValue("screen", 0) == 1); hwaccel = ((int)config.getValue("hwaccel", 0) == 1); + bool useOpenGL = (config.getValue("opengl", 0) == 1); + +#ifdef USE_OPENGL + // Setup image loading for the right image format + Image::setLoadAsOpenGL(useOpenGL); +#endif + // Create the graphics context graphics = new Graphics(useOpenGL); diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 4efe12e7..a468bb30 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -27,7 +27,9 @@ #include "../log.h" -extern bool useOpenGL; +#ifdef USE_OPENGL +bool Image::useOpenGL = false; +#endif Image::Image(SDL_Surface *image): image(image) @@ -149,27 +151,9 @@ Image* Image::load(void* buffer, unsigned int bufferSize) SDL_SetAlpha(tmpImage, SDL_SRCALPHA | SDL_RLEACCEL, SDL_ALPHA_OPAQUE); } - if (!useOpenGL) { - // Set color key and alpha blending optins, and convert the surface to the - // current display format - SDL_Surface *prevImage = tmpImage; - if (hasAlpha) { - image = SDL_DisplayFormatAlpha(tmpImage); - } - else { - image = SDL_DisplayFormat(tmpImage); - } - SDL_FreeSurface(prevImage); - - if (image == NULL) { - logger->log("Error: Image convert failed."); - return NULL; - } - - return new Image(image); - } #ifdef USE_OPENGL - else { + if (useOpenGL) + { int width = tmpImage->w; int height = tmpImage->h; int realWidth = 1, realHeight = 1; @@ -252,19 +236,44 @@ Image* Image::load(void* buffer, unsigned int bufferSize) return new Image(texture, width, height, realWidth, realHeight); } -#else - return NULL; #endif + + // Set color key and alpha blending optins, and convert the surface to the + // current display format + SDL_Surface *prevImage = tmpImage; + if (hasAlpha) { + image = SDL_DisplayFormatAlpha(tmpImage); + } + else { + image = SDL_DisplayFormat(tmpImage); + } + SDL_FreeSurface(prevImage); + + if (image == NULL) { + logger->log("Error: Image convert failed."); + return NULL; + } + + return new Image(image); } void Image::unload() { - // Free the image surface. - if (!useOpenGL && (image != NULL)) { - SDL_FreeSurface(image); - image = NULL; - } loaded = false; + +#ifdef USE_OPENGL + if (useOpenGL) { + return; + } +#endif + + if (!image) { + return; + } + + // Free the image surface. + SDL_FreeSurface(image); + image = NULL; } int Image::getWidth() const @@ -280,26 +289,27 @@ int Image::getHeight() const Image *Image::getSubImage(int x, int y, int width, int height) { // Create a new clipped sub-image - if (!useOpenGL) { - return new SubImage(this, image, x, y, width, height); - } #ifdef USE_OPENGL - else { + if (useOpenGL) { return new SubImage(this, glimage, x, y, width, height, texWidth, texHeight); } -#else - return NULL; #endif + + return new SubImage(this, image, x, y, width, height); } void Image::setAlpha(float a) { alpha = a; - if (!useOpenGL) { - // Set the alpha value this image is drawn at - SDL_SetAlpha(image, SDL_SRCALPHA | SDL_RLEACCEL, (int)(255 * alpha)); +#ifdef USE_OPENGL + if (useOpenGL) { + return; } +#endif + + // Set the alpha value this image is drawn at + SDL_SetAlpha(image, SDL_SRCALPHA | SDL_RLEACCEL, (int)(255 * alpha)); } float Image::getAlpha() @@ -307,6 +317,13 @@ float Image::getAlpha() return alpha; } +#ifdef USE_OPENGL +void Image::setLoadAsOpenGL(bool useOpenGL) +{ + Image::useOpenGL = useOpenGL; +} +#endif + //============================================================================ // SubImage Class //============================================================================ @@ -341,9 +358,14 @@ SubImage::SubImage(Image *parent, GLuint image, SubImage::~SubImage() { +#ifdef USE_OPENGL if (!useOpenGL) { image = NULL; } +#else + image = NULL; +#endif + parent->decRef(); } diff --git a/src/resources/image.h b/src/resources/image.h index 85f790ba..b99ad189 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -96,6 +96,14 @@ class Image : public Resource float getAlpha(); +#ifdef USE_OPENGL + /** + * Sets the target image format. Use <code>false</code> for SDL and + * <code>true</code> for OpenGL. + */ + static void setLoadAsOpenGL(bool useOpenGL); +#endif + protected: /** @@ -112,6 +120,8 @@ class Image : public Resource #ifdef USE_OPENGL GLuint glimage; int texWidth, texHeight; + + static bool useOpenGL; #endif SDL_Surface *image; float alpha; |