summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2005-08-14 23:57:06 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2005-08-14 23:57:06 +0000
commitcfaf8b836b21842b5d22ad774f93c2c364d33c0b (patch)
tree00dca4d03b2f9cff3ec0cef4ed8b6b05c4218c2b /src/resources
parente475dc028ca49324f824a7e4d6d16f54781b9bee (diff)
downloadmana-client-cfaf8b836b21842b5d22ad774f93c2c364d33c0b.tar.gz
mana-client-cfaf8b836b21842b5d22ad774f93c2c364d33c0b.tar.bz2
mana-client-cfaf8b836b21842b5d22ad774f93c2c364d33c0b.tar.xz
mana-client-cfaf8b836b21842b5d22ad774f93c2c364d33c0b.zip
Fully removed the useOpenGL global.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/image.cpp96
-rw-r--r--src/resources/image.h10
2 files changed, 69 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();
}
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;