From b8ddf1f786b2a245ba32b204e08c1c36738f64b0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 25 Sep 2007 15:01:11 +0000 Subject: [PATCH] Removed all dome distortion correction code as this is now part of the core osgViewer. Added viewer mode where movies are made fullscreen. One can use the old interactive camera mode by using --interactive parameter on the command line. --- examples/osgmovie/osgmovie.cpp | 485 ++++++--------------------------- 1 file changed, 90 insertions(+), 395 deletions(-) diff --git a/examples/osgmovie/osgmovie.cpp b/examples/osgmovie/osgmovie.cpp index dbab52029..ed9e3279d 100644 --- a/examples/osgmovie/osgmovie.cpp +++ b/examples/osgmovie/osgmovie.cpp @@ -267,14 +267,14 @@ void MovieEventHandler::getUsage(osg::ApplicationUsage& usage) const } -osg::Geometry* myCreateTexturedQuadGeometry(const osg::Vec3& pos,float width,float height, osg::Image* image, bool useTextureRectangle) +osg::Geometry* myCreateTexturedQuadGeometry(const osg::Vec3& pos,float width,float height, osg::Image* image, bool useTextureRectangle, bool xyPlane) { bool flip = image->getOrigin()==osg::Image::TOP_LEFT; if (useTextureRectangle) { osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(pos, osg::Vec3(width,0.0f,0.0f), - osg::Vec3(0.0f,0.0f,height), + xyPlane ? osg::Vec3(0.0f,height,0.0f) : osg::Vec3(0.0f,0.0f,height), 0.0f, flip ? image->t() : 0.0, image->s(), flip ? 0.0 : image->t()); osg::TextureRectangle* texture = new osg::TextureRectangle(image); @@ -292,7 +292,7 @@ osg::Geometry* myCreateTexturedQuadGeometry(const osg::Vec3& pos,float width,flo { osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(pos, osg::Vec3(width,0.0f,0.0f), - osg::Vec3(0.0f,0.0f,height), + xyPlane ? osg::Vec3(0.0f,height,0.0f) : osg::Vec3(0.0f,0.0f,height), 0.0f, flip ? 1.0f : 0.0f , 1.0f, flip ? 0.0f : 1.0f); osg::Texture2D* texture = new osg::Texture2D(image); @@ -309,324 +309,6 @@ osg::Geometry* myCreateTexturedQuadGeometry(const osg::Vec3& pos,float width,flo } } -class DomeModel -{ -public: - - DomeModel(osg::ArgumentParser& arguments): - sphere_radius(1.0), - collar_radius(0.45), - rotationDegrees(180.0), - distance(0.0), - flip(false), - texcoord_flip(false) - { - if (arguments.read("--radius", sphere_radius)) {} - if (arguments.read("--collar", collar_radius)) {} - if (arguments.read("--rotation", rotationDegrees)) {} - - distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius); - if (arguments.read("--distance", distance)) {} - - if (arguments.read("--flip")) { flip = true; } - } - - double sphere_radius; - double collar_radius; - double rotationDegrees; - double distance; - bool flip; - bool texcoord_flip; - -}; - - -osg::Geometry* createDomeDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, DomeModel& domeModel) -{ - osg::Vec3d center(0.0,0.0,0.0); - osg::Vec3d eye(0.0,0.0,0.0); - - bool centerProjection = false; - - osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, domeModel.distance); - - - osg::notify(osg::NOTICE)<<"Projector position = "<getScreenResolution(osg::GraphicsContext::ScreenIdentifier(screenNum), width, height); - - while (arguments.read("--width",width)) {} - while (arguments.read("--height",height)) {} - - DomeModel domeModel(arguments); - - osg::ref_ptr traits = new osg::GraphicsContext::Traits; - traits->screenNum = screenNum; - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - if (!gc) - { - osg::notify(osg::NOTICE)<<"GraphicsWindow has not been created successfully."<(image); - if (imagestream) imagestream->play(); - - if (image) - { - domeModel.texcoord_flip = image->getOrigin()==osg::Image::TOP_LEFT; - -#if 1 - texture = new osg::TextureRectangle(image); -#else - texture = new osg::Texture2D(image); -#endif - } - } - } - - if (!texture) - { - return; - } - - // distortion correction set up. - { - osg::Geode* geode = new osg::Geode(); - geode->addDrawable( createDomeDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), domeModel) ); - - // new we need to add the texture to the mesh, we do so by creating a - // StateSet to contain the Texture StateAttribute. - osg::StateSet* stateset = geode->getOrCreateStateSet(); - stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); - texture->setMaxAnisotropy(16.0f); - stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); -#if 1 - osg::TexMat* texmat = new osg::TexMat; - texmat->setScaleByTextureRectangleSize(true); - stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON); -#endif - osg::ref_ptr camera = new osg::Camera; - camera->setGraphicsContext(gc.get()); - camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); - camera->setClearColor( osg::Vec4(0.1,0.1,1.0,1.0) ); - camera->setViewport(new osg::Viewport(0, 0, width, height)); - GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); - camera->setAllowEventFocus(false); - //camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); - //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); - - camera->setProjectionMatrixAsOrtho2D(0,width,0,height); - camera->setViewMatrix(osg::Matrix::identity()); - - // add subgraph to render - // camera->addChild(geode); - - camera->setName("DistortionCorrectionCamera"); - - viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), true); - - viewer.setSceneData(geode); - } - - - viewer.getCamera()->setNearFarRatio(0.0001f); -} - int main(int argc, char** argv) { // use an ArgumentParser object to manage the program arguments. @@ -640,6 +322,7 @@ int main(int argc, char** argv) arguments.getApplicationUsage()->addCommandLineOption("--texture2D","Use Texture2D rather than TextureRectangle."); arguments.getApplicationUsage()->addCommandLineOption("--shader","Use shaders to post process the video."); arguments.getApplicationUsage()->addCommandLineOption("--dome","Use full dome distortion correction."); + arguments.getApplicationUsage()->addCommandLineOption("--interactive","Use camera manipulator to allow movement around movie.."); bool useTextureRectangle = true; bool useShader = false; @@ -663,89 +346,89 @@ int main(int argc, char** argv) return 1; } + bool fullscreen = !arguments.read("--interactive"); - if (arguments.read("--dome") || arguments.read("--puffer") ) - { - setDomeCorrection(viewer, arguments); - } - else + osg::ref_ptr geode = new osg::Geode; + + osg::StateSet* stateset = geode->getOrCreateStateSet(); + stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); + + if (useShader) { - osg::ref_ptr geode = new osg::Geode; - osg::Vec3 pos(0.0f,0.0f,0.0f); + //useTextureRectangle = false; - osg::StateSet* stateset = geode->getOrCreateStateSet(); - stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); + static const char *shaderSourceTextureRec = { + "uniform vec4 cutoff_color;\n" + "uniform samplerRect movie_texture;\n" + "void main(void)\n" + "{\n" + " vec4 texture_color = textureRect(movie_texture, gl_TexCoord[0]); \n" + " if (all(lessThanEqual(texture_color,cutoff_color))) discard; \n" + " gl_FragColor = texture_color;\n" + "}\n" + }; - if (useShader) + static const char *shaderSourceTexture2D = { + "uniform vec4 cutoff_color;\n" + "uniform sampler2D movie_texture;\n" + "void main(void)\n" + "{\n" + " vec4 texture_color = texture2D(movie_texture, gl_TexCoord[0]); \n" + " if (all(lessThanEqual(texture_color,cutoff_color))) discard; \n" + " gl_FragColor = texture_color;\n" + "}\n" + }; + + osg::Program* program = new osg::Program; + + program->addShader(new osg::Shader(osg::Shader::FRAGMENT, + useTextureRectangle ? shaderSourceTextureRec : shaderSourceTexture2D)); + + stateset->addUniform(new osg::Uniform("cutoff_color",osg::Vec4(0.1f,0.1f,0.1f,1.0f))); + stateset->addUniform(new osg::Uniform("movie_texture",0)); + + stateset->setAttribute(program); + + } + + osg::Vec3 pos(0.0f,0.0f,0.0f); + osg::Vec3 topleft = pos; + osg::Vec3 bottomright = pos; + + bool xyPlane = fullscreen; + + for(int i=1;i(image); + if (imagestream) imagestream->play(); - static const char *shaderSourceTextureRec = { - "uniform vec4 cutoff_color;\n" - "uniform samplerRect movie_texture;\n" - "void main(void)\n" - "{\n" - " vec4 texture_color = textureRect(movie_texture, gl_TexCoord[0]); \n" - " if (all(lessThanEqual(texture_color,cutoff_color))) discard; \n" - " gl_FragColor = texture_color;\n" - "}\n" - }; - - static const char *shaderSourceTexture2D = { - "uniform vec4 cutoff_color;\n" - "uniform sampler2D movie_texture;\n" - "void main(void)\n" - "{\n" - " vec4 texture_color = texture2D(movie_texture, gl_TexCoord[0]); \n" - " if (all(lessThanEqual(texture_color,cutoff_color))) discard; \n" - " gl_FragColor = texture_color;\n" - "}\n" - }; - - osg::Program* program = new osg::Program; - - program->addShader(new osg::Shader(osg::Shader::FRAGMENT, - useTextureRectangle ? shaderSourceTextureRec : shaderSourceTexture2D)); - - stateset->addUniform(new osg::Uniform("cutoff_color",osg::Vec4(0.1f,0.1f,0.1f,1.0f))); - stateset->addUniform(new osg::Uniform("movie_texture",0)); - - stateset->setAttribute(program); - - } - - for(int i=1;i(image); - if (imagestream) imagestream->play(); + geode->addDrawable(myCreateTexturedQuadGeometry(pos,image->s(),image->t(),image, useTextureRectangle, xyPlane)); + + bottomright = pos + osg::Vec3(static_cast(image->s()),static_cast(image->t()),0.0f); - if (image) - { - geode->addDrawable(myCreateTexturedQuadGeometry(pos,image->s(),image->t(),image, useTextureRectangle)); - - pos.z() += image->t()*1.5f; - } - else - { - std::cout<<"Unable to read file "<t()*1.5f; } - } - - // set the scene to render - viewer.setSceneData(geode.get()); - - if (viewer.getSceneData()==0) - { - arguments.getApplicationUsage()->write(std::cout); - return 1; + else + { + std::cout<<"Unable to read file "<write(std::cout); + return 1; + } // pass the model to the MovieEventHandler so it can pick out ImageStream's to manipulate. MovieEventHandler* meh = new MovieEventHandler(); @@ -762,10 +445,22 @@ int main(int argc, char** argv) return 1; } + if (fullscreen) + { + viewer.realize(); + viewer.getCamera()->setViewMatrix(osg::Matrix::identity()); + viewer.getCamera()->setProjectionMatrixAsOrtho2D(topleft.x(),bottomright.x(),topleft.y(),bottomright.y()); - // create the windows and run the threads. - return viewer.run(); - - + while(!viewer.done()) + { + viewer.frame(); + } + return 0; + } + else + { + // create the windows and run the threads. + return viewer.run(); + } }