summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-12-27 22:43:59 +0300
committerAndrei Karas <akaras@inbox.ru>2012-12-27 23:15:06 +0300
commitdba24b2e59eb739e73228dbcf707e943905a9e5a (patch)
treebdbcca13bb984a47fd4f1f41d0429244777e10e9
parentef5ba77247a2860a201c4d9177c4f3479d53538a (diff)
downloadManaVerse-dba24b2e59eb739e73228dbcf707e943905a9e5a.tar.gz
ManaVerse-dba24b2e59eb739e73228dbcf707e943905a9e5a.tar.bz2
ManaVerse-dba24b2e59eb739e73228dbcf707e943905a9e5a.tar.xz
ManaVerse-dba24b2e59eb739e73228dbcf707e943905a9e5a.zip
Fix text size if it was not power of two.
-rw-r--r--src/gui/sdlfont.cpp7
-rw-r--r--src/resources/imagehelper.h1
-rw-r--r--src/resources/openglimagehelper.cpp11
-rw-r--r--src/resources/openglimagehelper.h4
-rw-r--r--src/resources/sdlimagehelper.cpp1
-rw-r--r--src/resources/sdlimagehelper.h1
6 files changed, 18 insertions, 7 deletions
diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp
index d195278fa..3ece4b849 100644
--- a/src/gui/sdlfont.cpp
+++ b/src/gui/sdlfont.cpp
@@ -82,6 +82,8 @@ class SDLTextChunk final
SDL_Surface *surface = TTF_RenderUTF8_Blended(
font, strBuf, sdlCol);
+ const int width = surface->w;
+ const int height = surface->h;
if (!surface)
{
@@ -96,7 +98,7 @@ class SDLTextChunk final
SDL_Color sdlCol2;
const SDL_PixelFormat * const format = surface->format;
SDL_Surface *background = imageHelper->create32BitSurface(
- surface->w, surface->h);
+ width, height);
if (!background)
{
img = nullptr;
@@ -138,7 +140,8 @@ class SDLTextChunk final
SDL_FreeSurface(surface2);
surface = background;
}
- img = imageHelper->createTextSurface(surface, alpha);
+ img = imageHelper->createTextSurface(
+ surface, width, height, alpha);
SDL_FreeSurface(surface);
BLOCK_END("SDLTextChunk::generate")
diff --git a/src/resources/imagehelper.h b/src/resources/imagehelper.h
index 83fc3e03c..39e088aa5 100644
--- a/src/resources/imagehelper.h
+++ b/src/resources/imagehelper.h
@@ -67,6 +67,7 @@ class ImageHelper
virtual Image *load(SDL_Surface *) A_WARN_UNUSED = 0;
virtual Image *createTextSurface(SDL_Surface *tmpImage,
+ int width, int height,
float alpha) A_WARN_UNUSED = 0;
virtual int useOpenGL() A_WARN_UNUSED = 0;
diff --git a/src/resources/openglimagehelper.cpp b/src/resources/openglimagehelper.cpp
index badaf0223..5eae5c667 100644
--- a/src/resources/openglimagehelper.cpp
+++ b/src/resources/openglimagehelper.cpp
@@ -132,12 +132,13 @@ Image *OpenGLImageHelper::load(SDL_Surface *const tmpImage)
}
Image *OpenGLImageHelper::createTextSurface(SDL_Surface *const tmpImage,
+ int width, int height,
const float alpha)
{
if (!tmpImage)
return nullptr;
- Image *const img = glLoad(tmpImage);
+ Image *const img = glLoad(tmpImage, width, height);
if (img)
img->setAlpha(alpha);
return img;
@@ -159,7 +160,7 @@ int OpenGLImageHelper::powerOfTwo(int input) const
return value >= mTextureSize ? mTextureSize : value;
}
-Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage)
+Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage, int width, int height)
{
if (!tmpImage)
return nullptr;
@@ -167,8 +168,10 @@ Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage)
// Flush current error flag.
glGetError();
- int width = tmpImage->w;
- int height = tmpImage->h;
+ if (!width)
+ width = tmpImage->w;
+ if (!height)
+ height = tmpImage->h;
int realWidth = powerOfTwo(width);
int realHeight = powerOfTwo(height);
diff --git a/src/resources/openglimagehelper.h b/src/resources/openglimagehelper.h
index 0036bf007..30737dc36 100644
--- a/src/resources/openglimagehelper.h
+++ b/src/resources/openglimagehelper.h
@@ -86,6 +86,7 @@ class OpenGLImageHelper final : public ImageHelper
Image *load(SDL_Surface *const tmpImage) A_WARN_UNUSED;
Image *createTextSurface(SDL_Surface *const tmpImage,
+ int width, int height,
const float alpha) A_WARN_UNUSED;
// OpenGL only public functions
@@ -134,7 +135,8 @@ class OpenGLImageHelper final : public ImageHelper
*/
int powerOfTwo(int input) const A_WARN_UNUSED;
- Image *glLoad(SDL_Surface *tmpImage) A_WARN_UNUSED;
+ Image *glLoad(SDL_Surface *tmpImage,
+ int width = 0, int height = 0) A_WARN_UNUSED;
static int mUseOpenGL;
static int mTextureSize;
diff --git a/src/resources/sdlimagehelper.cpp b/src/resources/sdlimagehelper.cpp
index 82e476b8c..abc9ca068 100644
--- a/src/resources/sdlimagehelper.cpp
+++ b/src/resources/sdlimagehelper.cpp
@@ -129,6 +129,7 @@ Image *SDLImageHelper::load(SDL_Surface *const tmpImage)
}
Image *SDLImageHelper::createTextSurface(SDL_Surface *const tmpImage,
+ int width, int height,
const float alpha)
{
if (!tmpImage)
diff --git a/src/resources/sdlimagehelper.h b/src/resources/sdlimagehelper.h
index a0e19ca39..b37afaf2d 100644
--- a/src/resources/sdlimagehelper.h
+++ b/src/resources/sdlimagehelper.h
@@ -65,6 +65,7 @@ class SDLImageHelper final : public ImageHelper
Image *load(SDL_Surface *const tmpImage) A_WARN_UNUSED;
Image *createTextSurface(SDL_Surface *const tmpImage,
+ int width, int height,
const float alpha) A_WARN_UNUSED;
static void SDLSetEnableAlphaCache(const bool n)