summaryrefslogtreecommitdiff
path: root/src/openglgraphics.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-08-13 10:20:19 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-08-13 10:20:19 +0000
commitd3385829ca6f7d52e21706b25b14fe1083cfe984 (patch)
treeaea368b2434a49864b33183f95b6aae36abef3b7 /src/openglgraphics.cpp
parent7d287027babe615e01ddcf20edc1057f7d778c58 (diff)
downloadmana-d3385829ca6f7d52e21706b25b14fe1083cfe984.tar.gz
mana-d3385829ca6f7d52e21706b25b14fe1083cfe984.tar.bz2
mana-d3385829ca6f7d52e21706b25b14fe1083cfe984.tar.xz
mana-d3385829ca6f7d52e21706b25b14fe1083cfe984.zip
Merged Guichan 0.5.0 support from guichan-0.5.0 branch, plus several updates
from the 0.1.0 branch.
Diffstat (limited to 'src/openglgraphics.cpp')
-rw-r--r--src/openglgraphics.cpp28
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);
}