diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-08-14 23:57:06 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-08-14 23:57:06 +0000 |
commit | cfaf8b836b21842b5d22ad774f93c2c364d33c0b (patch) | |
tree | 00dca4d03b2f9cff3ec0cef4ed8b6b05c4218c2b /src/resources/image.cpp | |
parent | e475dc028ca49324f824a7e4d6d16f54781b9bee (diff) | |
download | mana-cfaf8b836b21842b5d22ad774f93c2c364d33c0b.tar.gz mana-cfaf8b836b21842b5d22ad774f93c2c364d33c0b.tar.bz2 mana-cfaf8b836b21842b5d22ad774f93c2c364d33c0b.tar.xz mana-cfaf8b836b21842b5d22ad774f93c2c364d33c0b.zip |
Fully removed the useOpenGL global.
Diffstat (limited to 'src/resources/image.cpp')
-rw-r--r-- | src/resources/image.cpp | 96 |
1 files changed, 59 insertions, 37 deletions
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(); } |