diff options
Diffstat (limited to 'src/openglgraphics.cpp')
-rw-r--r-- | src/openglgraphics.cpp | 94 |
1 files changed, 36 insertions, 58 deletions
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 7a1d259e..b9d837ad 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -106,33 +106,17 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) return true; } -bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY, - int dstX, int dstY, int width, int height, bool useColor) +static inline void drawQuad(Image *image, + int srcX, int srcY, int dstX, int dstY, + int width, int height) { - 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); - - if (Image::mTextureType == GL_TEXTURE_2D) + if (image->getTextureType() == GL_TEXTURE_2D) { // Find OpenGL normalized texture coordinates. - float texX1 = srcX / (float)image->mTexWidth; - float texY1 = srcY / (float)image->mTexHeight; - float texX2 = (srcX + width) / (float)image->mTexWidth; - float texY2 = (srcY + height) / (float)image->mTexHeight; + 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); @@ -154,7 +138,28 @@ bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY, glTexCoord2i(srcX, srcY + height); glVertex2i(dstX, dstY + height); } +} +bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY, + int dstX, int dstY, + int width, int height, 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); + drawQuad(image, srcX, srcY, dstX, dstY, width, height); glEnd(); if (!useColor) @@ -167,16 +172,14 @@ bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY, * so that glBegin...glEnd are outside the main loop. */ void OpenGLGraphics::drawImagePattern(Image *image, int x, int y, int w, int h) { - if (!image) return; + if (!image) + return; const int srcX = image->mBounds.x; const int srcY = image->mBounds.y; - const float texX1 = srcX / (float)image->mTexWidth; - const float texY1 = srcY / (float)image->mTexHeight; - - int iw = image->getWidth(); - int ih = image->getHeight(); + const int iw = image->getWidth(); + const int ih = image->getHeight(); if (iw == 0 || ih == 0) return; @@ -191,39 +194,14 @@ void OpenGLGraphics::drawImagePattern(Image *image, int x, int y, int w, int h) for (int py = 0; py < h; py += ih) { - int height = (py + ih >= h) ? h - py : ih; - int dstY = y + py; + 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; - if (Image::mTextureType == GL_TEXTURE_2D) - { - // Find OpenGL normalized texture coordinates. - float texX2 = (srcX + width) / (float) image->mTexWidth; - float texY2 = (srcY + height) / (float) image->mTexHeight; - - glTexCoord2f(texX1, texY1); - glVertex2i(dstX, dstY); - glTexCoord2f(texX2, texY1); - glVertex2i(dstX + width, dstY); - glTexCoord2f(texX2, texY2); - glVertex2i(dstX + width, dstY + height); - glTexCoord2f(texX1, texY2); - glVertex2i(dstX, dstY + height); - } - else - { - glTexCoord2i(srcX, srcY); - glVertex2i(dstX, dstY); - glTexCoord2i(srcX + width, srcY); - glVertex2i(dstX + width, dstY); - glTexCoord2i(srcX + width, srcY + height); - glVertex2i(dstX + width, dstY + height); - glTexCoord2i(srcX, srcY + height); - glVertex2i(dstX, dstY + height); - } + drawQuad(image, srcX, srcY, dstX, dstY, width, height); } } |