diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-07-30 14:33:28 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-07-30 14:33:28 +0000 |
commit | aff167beefadc32add4b44626cc2f1cbef800c7b (patch) | |
tree | 43796105cc107ec55742e88562e064d8031d3b23 /src/openglgraphics.cpp | |
parent | 18b73fdadd715d356416a95c31a25b3293fa2596 (diff) | |
download | mana-aff167beefadc32add4b44626cc2f1cbef800c7b.tar.gz mana-aff167beefadc32add4b44626cc2f1cbef800c7b.tar.bz2 mana-aff167beefadc32add4b44626cc2f1cbef800c7b.tar.xz mana-aff167beefadc32add4b44626cc2f1cbef800c7b.zip |
Updated TMW to be compatible with Guichan 0.5.0 (merged from guichan-0.5.0
branch).
Diffstat (limited to 'src/openglgraphics.cpp')
-rw-r--r-- | src/openglgraphics.cpp | 28 |
1 files changed, 13 insertions, 15 deletions
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 <OpenGL/OpenGL.h> #endif +#include <guichan/exception.hpp> #include <guichan/image.hpp> +#include <guichan/opengl/openglimage.hpp> #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<const gcn::OpenGLImage*>(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); } |