summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--src/gui/viewport.cpp2
-rw-r--r--src/main.cpp2
-rw-r--r--src/resources/image.cpp81
-rw-r--r--src/resources/image.h6
5 files changed, 59 insertions, 42 deletions
diff --git a/ChangeLog b/ChangeLog
index 9d0f106c..771440f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,12 +1,16 @@
-2007-03-20 David Athay <ko2fan@gmail.com>
+2007-03-21 Bjørn Lindeijer <bjorn@lindeijer.nl>
- * src/gui/viewport.cpp, src/gui/viewport.h: Split drawing the
- target cursor and target name into functions.
+ * src/main.cpp, src/gui/viewport.cpp, src/resources/image.h,
+ src/resources/image.cpp: Reduced amount of useless logging, calculate
+ nearest power of two in a function and only do the alpha check in
+ software mode.
2007-03-20 David Athay <ko2fan@gmail.com>
* src/gui/viewport.cpp: Fixed target cursor animation, and changed
which layer it is drawn after.
+ * src/gui/viewport.cpp, src/gui/viewport.h: Split drawing the target
+ cursor and target name into functions.
2007-03-20 Philipp Sehmisch <tmw@crushnet.org>
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 485f8d47..eb5939fd 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -255,7 +255,7 @@ Viewport::logic()
mouseY / 32 + mCameraY);
mWalkTime = player_node->mWalkTime;
}
-
+
mTargetCursorInRange->update(10);
mTargetCursorOutRange->update(10);
}
diff --git a/src/main.cpp b/src/main.cpp
index 40106c5c..d067cfdc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -98,7 +98,7 @@ unsigned char screen_mode;
Sound sound;
Music *bgm;
-Configuration config; /**< Xml file configuration reader */
+Configuration config; /**< XML file configuration reader */
Logger *logger; /**< Log object */
namespace {
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index a7c81574..e2220088 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -80,7 +80,7 @@ Image* Image::load(void *buffer, unsigned int bufferSize,
tmpImage = IMG_Load_RW(rw, 1);
}
- if (tmpImage == NULL) {
+ if (!tmpImage) {
logger->log("Error, image load failed: %s", IMG_GetError());
return NULL;
}
@@ -99,49 +99,28 @@ Image* Image::load(void *buffer, unsigned int bufferSize,
amask = 0xff000000;
#endif
- bool hasAlpha = false;
-
- // Figure out whether the image uses its alpha layer
- for (int i = 0; i < tmpImage->w * tmpImage->h; ++i)
- {
- Uint8 r, g, b, a;
- SDL_GetRGBA(
- ((Uint32*) tmpImage->pixels)[i],
- tmpImage->format,
- &r, &g, &b, &a);
-
- if (a != 255)
- {
- hasAlpha = true;
- break;
- }
- }
-
- if (hasAlpha) {
- SDL_SetAlpha(tmpImage, SDL_SRCALPHA, SDL_ALPHA_OPAQUE);
- }
-
#ifdef USE_OPENGL
if (mUseOpenGL)
{
int width = tmpImage->w;
int height = tmpImage->h;
- int realWidth = 1, realHeight = 1;
+ int realWidth = powerOfTwo(width);
+ int realHeight = powerOfTwo(height);
- while (realWidth < width && realWidth < 1024) {
- realWidth *= 2;
- }
-
- while (realHeight < height && realHeight < 1024) {
- realHeight *= 2;
+ 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);
+
SDL_Surface *oldImage = tmpImage;
- tmpImage = SDL_CreateRGBSurface(SDL_SWSURFACE, realWidth, realHeight, 32,
- rmask, gmask, bmask, amask);
+ tmpImage = SDL_CreateRGBSurface(SDL_SWSURFACE, realWidth, realHeight,
+ 32, rmask, gmask, bmask, amask);
- if (tmpImage == NULL) {
+ if (!tmpImage) {
logger->log("Error, image convert failed: out of memory");
return NULL;
}
@@ -151,8 +130,6 @@ Image* Image::load(void *buffer, unsigned int bufferSize,
GLuint texture;
glGenTextures(1, &texture);
- logger->log("Binding texture %d (%dx%d)",
- texture, tmpImage->w, tmpImage->h);
glBindTexture(GL_TEXTURE_2D, texture);
if (SDL_MUSTLOCK(tmpImage)) {
@@ -208,6 +185,24 @@ Image* Image::load(void *buffer, unsigned int bufferSize,
}
#endif
+ bool hasAlpha = false;
+
+ // Figure out whether the image uses its alpha layer
+ for (int i = 0; i < tmpImage->w * tmpImage->h; ++i)
+ {
+ Uint8 r, g, b, a;
+ SDL_GetRGBA(
+ ((Uint32*) tmpImage->pixels)[i],
+ tmpImage->format,
+ &r, &g, &b, &a);
+
+ if (a != 255)
+ {
+ hasAlpha = true;
+ break;
+ }
+ }
+
SDL_Surface *image;
// Convert the surface to the current display format
@@ -219,7 +214,7 @@ Image* Image::load(void *buffer, unsigned int bufferSize,
}
SDL_FreeSurface(tmpImage);
- if (image == NULL) {
+ if (!image) {
logger->log("Error: Image convert failed.");
return NULL;
}
@@ -278,10 +273,22 @@ float Image::getAlpha()
}
#ifdef USE_OPENGL
-void Image::setLoadAsOpenGL(bool useOpenGL)
+void
+Image::setLoadAsOpenGL(bool useOpenGL)
{
Image::mUseOpenGL = useOpenGL;
}
+
+int
+Image::powerOfTwo(int input)
+{
+ int value = 1;
+ while (value < input && value < 1024)
+ {
+ value <<= 1;
+ }
+ return value;
+}
#endif
//============================================================================
diff --git a/src/resources/image.h b/src/resources/image.h
index c769ecb6..1bdfbf48 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -123,6 +123,12 @@ class Image : public Resource
#ifdef USE_OPENGL
Image(const std::string &idPath, GLuint glimage, int width, int height,
int texWidth, int texHeight);
+
+ /**
+ * Returns the first power of two equal or bigger than the input.
+ */
+ static int
+ powerOfTwo(int input);
#endif
Image(const std::string &idPath, SDL_Surface *image);