Hi Randall

All color attachments must have same size, format, and channels count.

Cheers.

14.09.2012, 08:29, "Randall Hand" <[email protected]>:
> I'm trying to write a simple app to render a scene and drop out 3
> buffers : Depth, Color (RGB), and Alpha.  I've pasted the code below,
> and there's an important DEFINE at the top: SHOW_ALPHA.  If you set
> SHOW_ALPHA to 0, that disables the COLOR_BUFFER1 (a GL_ALPHA texture
> attachment to the main camera) and everything works perfectly.  I set
> that to 1, and then my visuals get all scrambled and I get the following
> error messages:
>
> RenderStage::runCameraSetUp(), FBO setup failed, FBO status= 0x8cdd
> Warning: RenderStage::runCameraSetUp(State&) Pbuffer does not support
> multiple color outputs.
> Warning: RenderStage::runCameraSetUp(State&) Pbuffer does not support
> multiple color outputs.
> RenderStage::runCameraSetUp(), FBO setup failed, FBO status= 0x8cdd
> Warning: RenderStage::runCameraSetUp(State&) Pbuffer does not support
> multiple color outputs.
> Warning: RenderStage::runCameraSetUp(State&) Pbuffer does not support
> multiple color outputs.
>
> Now, I think I can accomplish what I want using a single RGBA texture
> and a fragment shader to pull out the A.  Am I doing something wrong, or
> is the fragment-shader route the "right" way to go?
>
> Code below:
>
> #include <osgViewer/Viewer>
>
> #include <osg/BlendFunc>
> #include <osg/Geode>
> #include <osg/TexGen>
> #include <osg/Texture2D>
> #include <osg/MatrixTransform>
> #include <osg/LightModel>
> #include <osg/Material>
> #include <osgGA/NodeTrackerManipulator>
> #include <osgDB/ReadFile>
> #include <osgViewer/Viewer>
>
> #define SHOW_ALPHA 0
> #define SHOW_DEPTH 1
> #define HEIGHT_OFFSET 24
>
> int main(void) {
>
>     int width=512, height=256;
>     osg::ref_ptr<osg::Geode> screenQuad = new osg::Geode;
>
>     osg::ref_ptr<osg::Texture2D> __depthTexture = new osg::Texture2D();
>     osg::ref_ptr<osg::Texture2D> __maskTexture = new osg::Texture2D();
>     osg::ref_ptr<osg::Texture2D> __colorTexture = new osg::Texture2D();
>     osg::ref_ptr<osg::Node> model =
> osgDB::readNodeFile("/Users/rhand/Documents/MagicLeap/data/MLOS-Logo.obj");
>     osgViewer::Viewer V;
>     osg::ref_ptr<osg::Group> group = new osg::Group();
>
>     //model->getOrCreateStateSet()->setMode(GL_,osg::StateAttribute::OFF);
>
> model->getOrCreateStateSet()->setMode(GL_BLEND,osg::StateAttribute::ON);
>
> model->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::ON);
>
>     V.getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
>     V.getCamera()->setClearDepth(1.0);
>     V.getCamera()->setClearColor(osg::Vec4(0,0,0,0));
>     group->addChild(model.get());
>     V.setSceneData(group.get());
>
>     // Establish the "base" Graphics Context
>     osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
> osg::GraphicsContext::Traits;
>     traits->x = 0;
>     traits->y = HEIGHT_OFFSET;
>     traits->width = width;
>     traits->height = height;
>     traits->windowDecoration = true;
>     traits->doubleBuffer = true;
>     traits->sharedContext = 0; // Doesn't inherit from anything
>     traits->vsync = true;       // Disable VSync (for now)
>     traits->supportsResize = false;
>     traits->windowName = "Color";
>     osg::ref_ptr<osg::GraphicsContext> gc =
> osg::GraphicsContext::createGraphicsContext(traits.get());
>
>     {
>         __depthTexture->setTextureSize(width,height);
>         __depthTexture->setInternalFormat(GL_DEPTH_COMPONENT);
>
> __depthTexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST);
>
> __depthTexture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST);
>
>         __depthTexture->setDataVariance( osg::Object::DYNAMIC );
>         __depthTexture->setResizeNonPowerOfTwoHint( false );
>
>         __maskTexture->setTextureSize(width,height);
>         __maskTexture->setInternalFormat(GL_ALPHA);
>
> __maskTexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST);
>
> __maskTexture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST);
>
>         __maskTexture->setDataVariance( osg::Object::DYNAMIC );
>         __maskTexture->setResizeNonPowerOfTwoHint( false );
>
>         __colorTexture->setTextureSize(width,height);
>         __colorTexture->setInternalFormat(GL_RGB);
>
> __colorTexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST);
>
> __colorTexture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST);
>
>         __colorTexture->setDataVariance( osg::Object::DYNAMIC );
>         __colorTexture->setResizeNonPowerOfTwoHint( false );
>
>         osg::ref_ptr<osg::Camera> __camera = new osg::Camera();
>         __camera->setGraphicsContext(gc.get());
>         __camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
>         __camera->setViewport(new osg::Viewport(0,0, traits->width,
> traits->height));
>
> __camera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
>         __camera->setProjectionMatrixAsPerspective(70,(height/width),
> 1,200);
>         __camera->setClearDepth(1.0);
>         __camera->setViewMatrixAsLookAt( osg::Vec3(0,0,0),
> osg::Vec3(0,100,0), osg::Vec3(0,0,1) );
>         __camera->setRenderOrder(osg::Camera::PRE_RENDER);
>
> __camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
>         __camera->attach(osg::Camera::COLOR_BUFFER0, __colorTexture);
> #if SHOW_DEPTH
>         __camera->attach(osg::Camera::DEPTH_BUFFER, __depthTexture);
> #endif
> #if SHOW_ALPHA
>         __camera->attach(osg::Camera::COLOR_BUFFER1, __maskTexture);
> #endif
>         V.addSlave(__camera.get(), osg::Matrixd(), osg::Matrixd());
>     }
>     {  // Make the re-usable Quad for displaying the textures
>         // Make the quad with a little 10px border around the edges, for
> debugging
>
>         osg::ref_ptr<osg::Drawable> quad = osg::createTexturedQuadGeometry(
>                     osg::Vec3(10,10.0,0),
> osg::Vec3(width-20,0,0),osg::Vec3(0,height-20,0),
>                     0, 0, 1, 1);
>         quad->setDataVariance( osg::Object::STATIC ); // This is
> _always_ a screen-aligned quad
>         quad->setUseDisplayList( true );
>         osg::StateSet* ss = quad->getOrCreateStateSet();
>         ss->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);
>         ss->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
>         ss->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
>         ss->setMode(GL_BLEND, osg::StateAttribute::ON);
>         ss->setAttribute(new osg::BlendFunc(GL_SRC_ALPHA,
> GL_ONE_MINUS_SRC_ALPHA), osg::StateAttribute::ON);
>         // Put the quad in a Geometry Node (Geode) and configure it for
> Texture coordinates
>         //osg::ref_ptr<osg::Geode> *geode = new osg::Geode;
>         screenQuad->addDrawable( quad.get() );
>     }
>
> #if SHOW_DEPTH
>     { // Display the Depth MAsk
>         osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
> osg::GraphicsContext::Traits;
>         traits->x = 0;
>         traits->y = height + (HEIGHT_OFFSET*3);
>         traits->width = width;
>         traits->height = height;
>         traits->windowDecoration = true;
>         traits->doubleBuffer = true;
>         traits->sharedContext = gc.get();
>         traits->vsync = true;       // Disable VSync (for now)
>         traits->supportsResize = false;
>         traits->windowName = "Depth";
>         osg::ref_ptr<osg::GraphicsContext> this_gc =
> osg::GraphicsContext::createGraphicsContext(traits.get());
>
>         // now create a camera
>         //  It's an orthographic 2D camera (sized to pixel match)
>         //  Load an identity view matrix, and set the only geometry here
> to be the quad
>         osg::ref_ptr<osg::Camera> __camera = new osg::Camera();
>         __camera->setGraphicsContext(this_gc.get());
>         __camera->setViewport(new osg::Viewport(0,0, width, height));
>         __camera->setClearMask(GL_COLOR_BUFFER_BIT);
>         __camera->setClearDepth(1.0);
>         __camera->setClearColor(osg::Vec4(1,0,0,0)); // Red border
>         __camera->setRenderOrder(osg::Camera::POST_RENDER);
>
> __camera->setProjectionMatrix(osg::Matrix::ortho2D(0,width,0,height));
>         __camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
>         __camera->setViewMatrix(osg::Matrix::identity());
>         __camera->addChild(screenQuad.get());
>         osg::StateSet *ss = __camera->getOrCreateStateSet();
>         ss->setTextureAttributeAndModes(0, __depthTexture,
> osg::StateAttribute::ON);
>
>         V.addSlave(__camera.get(), osg::Matrixd(), osg::Matrixd(), false);
>     }
> #endif
> #if SHOW_ALPHA
>     { // display the Alpha mask
>         osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
> osg::GraphicsContext::Traits;
>         traits->x = 0;
>         traits->y = 2*height+ 4*HEIGHT_OFFSET;
>         traits->width = width;
>         traits->height = height;
>         traits->windowDecoration = true;
>         traits->doubleBuffer = true;
>         traits->sharedContext = gc.get();
>         traits->vsync = true;       // Disable VSync (for now)
>         traits->supportsResize = false;
>         traits->windowName = "alpha";
>         osg::ref_ptr<osg::GraphicsContext> this_gc =
> osg::GraphicsContext::createGraphicsContext(traits.get());
>
>         // now create a camera
>         //  It's an orthographic 2D camera (sized to pixel match)
>         //  Load an identity view matrix, and set the only geometry here
> to be the quad
>         osg::ref_ptr<osg::Camera> __camera = new osg::Camera();
>         __camera->setGraphicsContext(this_gc.get());
>         __camera->setViewport(new osg::Viewport(0,0, width, height));
>         __camera->setClearMask(GL_COLOR_BUFFER_BIT);
>         __camera->setClearDepth(1.0);
>         __camera->setClearColor(osg::Vec4(0,0,0,0));
>         __camera->setRenderOrder(osg::Camera::POST_RENDER);
>
> __camera->setProjectionMatrix(osg::Matrix::ortho2D(0,width,0,height));
>         __camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
>         __camera->setViewMatrix(osg::Matrix::identity());
>         __camera->addChild(screenQuad.get());
>         osg::StateSet *ss = __camera->getOrCreateStateSet();
>         ss->setTextureAttributeAndModes(0, __maskTexture,
> osg::StateAttribute::ON);
>
>         V.addSlave(__camera.get(), osg::Matrixd(), osg::Matrixd(), false);
>     }
> #endif
>     { // display the Color mask
>         // now create a camera
>         //  It's an orthographic 2D camera (sized to pixel match)
>         //  Load an identity view matrix, and set the only geometry here
> to be the quad
>         osg::ref_ptr<osg::Camera> __camera = new osg::Camera();
>         __camera->setGraphicsContext(gc.get());
>         __camera->setViewport(new osg::Viewport(0,0, width, height));
>         __camera->setClearMask(GL_COLOR_BUFFER_BIT);
>         __camera->setClearDepth(1.0);
>         __camera->setClearColor(osg::Vec4(0,0,0,0));
>         __camera->setRenderOrder(osg::Camera::POST_RENDER);
>
> __camera->setProjectionMatrix(osg::Matrix::ortho2D(0,width,0,height));
>         __camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
>         __camera->setViewMatrix(osg::Matrix::identity());
>         __camera->addChild(screenQuad.get());
>         osg::StateSet *ss = __camera->getOrCreateStateSet();
>         ss->setTextureAttributeAndModes(0, __colorTexture,
> osg::StateAttribute::ON);
>
>         V.addSlave(__camera.get(), osg::Matrixd(), osg::Matrixd(), false);
>     }
>
>     V.run();
> }
>
> --
> Randall Hand
> http://www.yeraze.com
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to