diff options
author | Bertram <bertram@cegetel.net> | 2009-07-27 01:02:27 +0200 |
---|---|---|
committer | Bertram <bertram@cegetel.net> | 2009-07-27 01:02:27 +0200 |
commit | fa1a3ab995f037ddf33817a1b2ce143130a457f8 (patch) | |
tree | 4cfc52364c271a9a318a2fee4b611514d7941476 /src/openglgraphics.cpp | |
parent | 7bc30f545784b26594803b559f1d76d5434027ea (diff) | |
download | mana-fa1a3ab995f037ddf33817a1b2ce143130a457f8.tar.gz mana-fa1a3ab995f037ddf33817a1b2ce143130a457f8.tar.bz2 mana-fa1a3ab995f037ddf33817a1b2ce143130a457f8.tar.xz mana-fa1a3ab995f037ddf33817a1b2ce143130a457f8.zip |
Added the ability to ask a ambient layer to keep its ratio when the resolution isn't the default.
You'll have to add this in map properties, for instance if you're want to keep ratio on overlay 0:
<map version="1.0" orientation="orthogonal" width="128" height="128" tilewidth="32" tileheight="32">
<properties>
...
<property name="overlay0keepratio" value="true"/>
...
</properties>
</map>
Diffstat (limited to 'src/openglgraphics.cpp')
-rw-r--r-- | src/openglgraphics.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 5c9e2049..4d66a919 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -277,6 +277,49 @@ void OpenGLGraphics::drawImagePattern(Image *image, int x, int y, int w, int h) glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a); } +void OpenGLGraphics::drawRescaledImagePattern(Image *image, int x, int y, + int w, int h, + int scaledWidth, int scaledHeight) +{ + if (!image) + return; + + const int srcX = image->mBounds.x; + const int srcY = image->mBounds.y; + + const int iw = scaledWidth; + const int ih = scaledHeight; + if (iw == 0 || ih == 0) + return; + + glColor4f(1.0f, 1.0f, 1.0f, image->mAlpha); + + glBindTexture(Image::mTextureType, image->mGLImage); + + setTexturingAndBlending(true); + + // Draw a set of textured rectangles + glBegin(GL_QUADS); + + for (int py = 0; py < h; py += ih) + { + const int height = (py + ih >= h) ? h - py : ih; + const int dstY = y + py; + for (int px = 0; px < w; px += iw) + { + int width = (px + iw >= w) ? w - px : iw; + int dstX = x + px; + + drawRescaledQuad(image, srcX, srcY, dstX, dstY, + width, height, scaledWidth, scaledHeight); + } + } + + glEnd(); + + glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a); +} + void OpenGLGraphics::updateScreen() { glFlush(); |