summaryrefslogtreecommitdiff
path: root/src/render/modernopenglgraphics.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-06-12 01:41:07 +0300
committerAndrei Karas <akaras@inbox.ru>2014-06-12 01:41:07 +0300
commit1f1e02d2b0143dd1f89720cc204bb0da36b302e9 (patch)
tree341a45d31b3e6ec38f11d664e98a8aaf43af04f0 /src/render/modernopenglgraphics.cpp
parent1d4c97f2f4337614b6d270ddacbfd00e408f4e9a (diff)
downloadmanaplus-1f1e02d2b0143dd1f89720cc204bb0da36b302e9.tar.gz
manaplus-1f1e02d2b0143dd1f89720cc204bb0da36b302e9.tar.bz2
manaplus-1f1e02d2b0143dd1f89720cc204bb0da36b302e9.tar.xz
manaplus-1f1e02d2b0143dd1f89720cc204bb0da36b302e9.zip
In modernopengl add draw rescaled image.
Diffstat (limited to 'src/render/modernopenglgraphics.cpp')
-rw-r--r--src/render/modernopenglgraphics.cpp63
1 files changed, 57 insertions, 6 deletions
diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp
index 6955571eb..91b393ed9 100644
--- a/src/render/modernopenglgraphics.cpp
+++ b/src/render/modernopenglgraphics.cpp
@@ -271,13 +271,40 @@ void ModernOpenGLGraphics::drawQuad(const Image *const image,
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
-static inline void drawRescaledQuad(const Image *const image,
- const int srcX, const int srcY,
- const int dstX, const int dstY,
- const int width, const int height,
- const int desiredWidth,
- const int desiredHeight)
+void ModernOpenGLGraphics::drawRescaledQuad(const Image *const image,
+ const int srcX, const int srcY,
+ const int dstX, const int dstY,
+ const int width, const int height,
+ const int desiredWidth,
+ const int desiredHeight)
{
+ const float tw = static_cast<float>(image->mTexWidth);
+ const float th = static_cast<float>(image->mTexHeight);
+ // Find OpenGL normalized texture coordinates.
+ const float texX1 = static_cast<float>(srcX) / tw;
+ const float texY1 = static_cast<float>(srcY) / th;
+ const float texX2 = static_cast<float>(srcX + width) / tw;
+ const float texY2 = static_cast<float>(srcY + height) / th;
+
+ const float x1 = static_cast<GLfloat>(dstX);
+ const float y1 = static_cast<GLfloat>(dstY);
+ const float x2 = x1 + static_cast<GLfloat>(desiredWidth);
+ const float y2 = y1 + static_cast<GLfloat>(desiredHeight);
+
+ GLfloat vertices[] =
+ {
+ x1, y1, texX1, texY1,
+ x2, y1, texX2, texY1,
+ x1, y2, texX1, texY2,
+ x2, y2, texX2, texY2
+ };
+
+ mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
+ vertices, GL_DYNAMIC_DRAW);
+#ifdef DEBUG_DRAW_CALLS
+ mDrawCalls ++;
+#endif
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
bool ModernOpenGLGraphics::drawImage(const Image *const image,
@@ -329,6 +356,30 @@ bool ModernOpenGLGraphics::drawRescaledImage(const Image *const image,
const int desiredWidth,
const int desiredHeight)
{
+ if (!image)
+ return false;
+
+ const SDL_Rect &imageRect = image->mBounds;
+
+ // Just draw the image normally when no resizing is necessary,
+ if (imageRect.w == desiredWidth && imageRect.h == desiredHeight)
+ return drawImageInline(image, dstX, dstY);
+
+ setColorAlpha(image->mAlpha);
+#ifdef DEBUG_BIND_TEXTURE
+ debugBindTexture(image);
+#endif
+ bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage);
+ setTexturingAndBlending(true);
+
+ const ClipRect &clipArea = mClipStack.top();
+ // Draw a textured quad.
+ drawRescaledQuad(image,
+ imageRect.x, imageRect.y,
+ dstX + clipArea.xOffset, dstY + clipArea.yOffset,
+ imageRect.w, imageRect.h,
+ desiredWidth, desiredHeight);
+
return true;
}