From aff167beefadc32add4b44626cc2f1cbef800c7b Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 30 Jul 2006 14:33:28 +0000 Subject: Updated TMW to be compatible with Guichan 0.5.0 (merged from guichan-0.5.0 branch). --- src/openglgraphics.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'src/openglgraphics.cpp') diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index dc14b6c6..2a6c931d 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -31,7 +31,9 @@ #include #endif +#include #include +#include #include "log.h" @@ -227,28 +229,24 @@ void OpenGLGraphics::drawImage(const gcn::Image* image, int dstX, int dstY, int width, int height) { - // The following code finds the real width and height of the texture. - // OpenGL only supports texture sizes that are powers of two - int realImageWidth = 1; - int realImageHeight = 1; - while (realImageWidth < image->getWidth()) - { - realImageWidth *= 2; - } - while (realImageHeight < image->getHeight()) + const gcn::OpenGLImage* srcImage = + dynamic_cast(image); + + if (srcImage == NULL) { - realImageHeight *= 2; + throw GCN_EXCEPTION("Trying to draw an image of unknown format, " + "must be an SDLImage."); } // Find OpenGL texture coordinates - float texX1 = srcX / (float)realImageWidth; - float texY1 = srcY / (float)realImageHeight; - float texX2 = (srcX + width) / (float)realImageWidth; - float texY2 = (srcY + height) / (float)realImageHeight; + float texX1 = srcX / (float)srcImage->getTextureWidth(); + float texY1 = srcY / (float)srcImage->getTextureHeight(); + float texX2 = (srcX + width) / (float)srcImage->getTextureWidth(); + float texY2 = (srcY + height) / (float)srcImage->getTextureHeight(); // Please dont look too closely at the next line, it is not pretty. // It uses the image data as a pointer to a GLuint - glBindTexture(GL_TEXTURE_2D, *((GLuint *)(image->_getData()))); + glBindTexture(GL_TEXTURE_2D, srcImage->getTextureHandle()); drawTexedQuad(dstX, dstY, width, height, texX1, texY1, texX2, texY2); } -- cgit v1.2.3-70-g09d2