From 40c6d99c1556680211f650d4504c67212675813d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 10 Nov 2010 12:50:06 +0000 Subject: [PATCH] From Mourad Boufarguine, "This is a small fix to osg::createGeodeForImage to adapt Tex coords to image origin. " --- src/osg/Image.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index c3adfe0ac..b79137037 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -1360,6 +1360,9 @@ Geode* osg::createGeodeForImage(osg::Image* image,float s,float t) float y = 1.0; float x = y*(s/t); + float texcoord_y_b = (image->getOrigin() == osg::Image::BOTTOM_LEFT) ? 0.0f : 1.0f; + float texcoord_y_t = (image->getOrigin() == osg::Image::BOTTOM_LEFT) ? 1.0f : 0.0f; + // set up the texture. #if 0 @@ -1368,14 +1371,14 @@ Geode* osg::createGeodeForImage(osg::Image* image,float s,float t) texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); //texture->setResizeNonPowerOfTwoHint(false); float texcoord_x = image->s(); - float texcoord_y = image->t(); + texcoord_y_b *= image->t(); + texcoord_y_t *= image->t(); #else osg::Texture2D* texture = new osg::Texture2D; texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); texture->setResizeNonPowerOfTwoHint(false); float texcoord_x = 1.0f; - float texcoord_y = 1.0f; #endif texture->setImage(image); @@ -1397,10 +1400,10 @@ Geode* osg::createGeodeForImage(osg::Image* image,float s,float t) geom->setVertexArray(coords); Vec2Array* tcoords = new Vec2Array(4); - (*tcoords)[0].set(0.0f*texcoord_x,1.0f*texcoord_y); - (*tcoords)[1].set(0.0f*texcoord_x,0.0f*texcoord_y); - (*tcoords)[2].set(1.0f*texcoord_x,0.0f*texcoord_y); - (*tcoords)[3].set(1.0f*texcoord_x,1.0f*texcoord_y); + (*tcoords)[0].set(0.0f*texcoord_x,texcoord_y_t); + (*tcoords)[1].set(0.0f*texcoord_x,texcoord_y_b); + (*tcoords)[2].set(1.0f*texcoord_x,texcoord_y_b); + (*tcoords)[3].set(1.0f*texcoord_x,texcoord_y_t); geom->setTexCoordArray(0,tcoords); osg::Vec4Array* colours = new osg::Vec4Array(1);