diff --git a/examples/osgmovie/osgmovie.cpp b/examples/osgmovie/osgmovie.cpp index a7a2d91ad..369cc34a5 100644 --- a/examples/osgmovie/osgmovie.cpp +++ b/examples/osgmovie/osgmovie.cpp @@ -524,14 +524,27 @@ int main(int argc, char** argv) if (image) { - osg::notify(osg::NOTICE)<<"image->s()"<s()<<" image-t()="<t()<s()"<s()<<" image-t()="<t()<<" aspectRatio="<getPixelAspectRatio()<addDrawable(myCreateTexturedQuadGeometry(pos,image->s(),image->t(),image, useTextureRectangle, xyPlane, flip)); + float width = image->s(); + float height = image->t() * image->getPixelAspectRatio(); - bottomright = pos + osg::Vec3(static_cast(image->s()),static_cast(image->t()),0.0f); + osg::ref_ptr drawable = myCreateTexturedQuadGeometry(pos, width, height,image, useTextureRectangle, xyPlane, flip); + + if (image->isImageTranslucent()) + { + osg::notify(osg::NOTICE)<<"Transparent movie, enabling blending."<t()*1.05f; - else pos.z() += image->t()*1.05f; + drawable->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON); + drawable->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); + } + + geode->addDrawable(drawable.get()); + + bottomright = pos + osg::Vec3(width,height,0.0f); + + if (xyPlane) pos.y() += height*1.05f; + else pos.z() += height*1.05f; } else { @@ -572,8 +585,44 @@ int main(int argc, char** argv) if (fullscreen) { viewer.realize(); + + viewer.getCamera()->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); + float screenAspectRatio = 1280.0f/1024.0f; + + osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); + if (wsi) + { + unsigned int width, height; + wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); + + screenAspectRatio = float(width) / float(height); + } + + float modelAspectRatio = (bottomright.x()-topleft.x())/(bottomright.y()-topleft.y()); + viewer.getCamera()->setViewMatrix(osg::Matrix::identity()); + + + osg::Vec3 center = (bottomright + topleft)*0.5f; + osg::Vec3 dx(bottomright.x()-center.x(), 0.0f, 0.0f); + osg::Vec3 dy(0.0f, topleft.y()-center.y(), 0.0f); + + float ratio = modelAspectRatio/screenAspectRatio; + + if (ratio>1.0f) + { + // use model width as the control on model size. + bottomright = center + dx - dy * ratio; + topleft = center - dx + dy * ratio; + } + else + { + // use model height as the control on model size. + bottomright = center + dx / ratio - dy; + topleft = center - dx / ratio + dy; + } + viewer.getCamera()->setProjectionMatrixAsOrtho2D(topleft.x(),bottomright.x(),topleft.y(),bottomright.y()); while(!viewer.done())