summaryrefslogtreecommitdiff
path: root/src/openglgraphics.cpp
diff options
context:
space:
mode:
authorBertram <bertram@cegetel.net>2009-07-24 22:59:13 +0200
committerBertram <bertram@cegetel.net>2009-07-24 22:59:13 +0200
commit8195e73cb801d56240beb966554a864729d9f20c (patch)
treef2a00036d15eaf70cb9abe4930b4199b1e5eae05 /src/openglgraphics.cpp
parentea6f492198a03cffc3be47df000fa16dfc3b262f (diff)
downloadmana-8195e73cb801d56240beb966554a864729d9f20c.tar.gz
mana-8195e73cb801d56240beb966554a864729d9f20c.tar.bz2
mana-8195e73cb801d56240beb966554a864729d9f20c.tar.xz
mana-8195e73cb801d56240beb966554a864729d9f20c.zip
Made the wallpaper be rescaled when necessary under SDL and OpenGL.
The SDL methods to rescale the wallpaper has been optimized to permit rescaling at load time while OpenGL draws directly rescaled. Does someone know how to smooth the rescaled image under OpenGL?
Diffstat (limited to 'src/openglgraphics.cpp')
-rw-r--r--src/openglgraphics.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index b9d837ad..5c9e2049 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -140,6 +140,42 @@ static inline void drawQuad(Image *image,
}
}
+static inline void drawRescaledQuad(Image *image,
+ int srcX, int srcY, int dstX, int dstY,
+ int width, int height,
+ int desiredWidth, int desiredHeight)
+{
+ if (image->getTextureType() == GL_TEXTURE_2D)
+ {
+ // Find OpenGL normalized texture coordinates.
+ float texX1 = srcX / (float) image->getTextureWidth();
+ float texY1 = srcY / (float) image->getTextureHeight();
+ float texX2 = (srcX + width) / (float) image->getTextureWidth();
+ float texY2 = (srcY + height) / (float) image->getTextureHeight();
+
+ glTexCoord2f(texX1, texY1);
+ glVertex2i(dstX, dstY);
+ glTexCoord2f(texX2, texY1);
+ glVertex2i(dstX + desiredWidth, dstY);
+ glTexCoord2f(texX2, texY2);
+ glVertex2i(dstX + desiredWidth, dstY + desiredHeight);
+ glTexCoord2f(texX1, texY2);
+ glVertex2i(dstX, dstY + desiredHeight);
+ }
+ else
+ {
+ glTexCoord2i(srcX, srcY);
+ glVertex2i(dstX, dstY);
+ glTexCoord2i(srcX + width, srcY);
+ glVertex2i(dstX + desiredWidth, dstY);
+ glTexCoord2i(srcX + width, srcY + height);
+ glVertex2i(dstX + desiredWidth, dstY + desiredHeight);
+ glTexCoord2i(srcX, srcY + height);
+ glVertex2i(dstX, dstY + desiredHeight);
+ }
+}
+
+
bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY,
int dstX, int dstY,
int width, int height, bool useColor)
@@ -168,6 +204,37 @@ bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY,
return true;
}
+bool OpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY,
+ int dstX, int dstY,
+ int width, int height,
+ int desiredWidth, int desiredHeight,
+ bool useColor)
+{
+ if (!image)
+ return false;
+
+ srcX += image->mBounds.x;
+ srcY += image->mBounds.y;
+
+ if (!useColor)
+ glColor4f(1.0f, 1.0f, 1.0f, image->mAlpha);
+
+ glBindTexture(Image::mTextureType, image->mGLImage);
+
+ setTexturingAndBlending(true);
+
+ // Draw a textured quad.
+ glBegin(GL_QUADS);
+ drawRescaledQuad(image, srcX, srcY, dstX, dstY, width, height,
+ desiredWidth, desiredHeight);
+ glEnd();
+
+ if (!useColor)
+ glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a);
+
+ return true;
+}
+
/* Optimising the functions that Graphics::drawImagePattern would call,
* so that glBegin...glEnd are outside the main loop. */
void OpenGLGraphics::drawImagePattern(Image *image, int x, int y, int w, int h)