Jeremy L. Moles schrieb:
Out of curiosity, is your code public? I'm curious to see how someone
else integrated Cairo and OSG. You can find my implementation (osgCairo)
here:
I'll have a look at your code. I am just experimenting with cairo, and nothing has settled. I am using cairomm as a c++-wrapper around cairo, this simplifies the code a lot :)

For now I am creating an osg::Image the same size as the viewport and use it for cairo-related-drawing:

           osg::Geode* geode = new osg::Geode();

           // create an image in wich cairo can draw.
osg::Image* image = new osg::Image(); image->allocateImage(800, 600, 1, GL_RGBA, GL_UNSIGNED_BYTE);
           image->setPixelFormat(GL_BGRA);

           // create a quad
cefix::Quad2DGeometry* quad = new cefix::Quad2DGeometry(osg::Vec4(0,0, 800, 600));
           quad->setTextureFromImage(image);
           geode->addDrawable(quad);
geode->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);

// create a surface + context cairo::ref_ptr<cairo::ImageSurface> surface = cairo::ImageSurface::create(image->data(), cairo::FORMAT_ARGB32, image->s(), image->t(), image->s()*4); cairo::ref_ptr<cairo::Context> context = cairo::Context::create(surface); // do some fancy drawing
           context->set_line_width(0.1f);
           context->set_source_rgba(0,0,1,0);
           context->paint();
float fac = image->s() / 800.0f;
           for(unsigned int i = 0; i < 800; ++i) {
               osg::Vec4 c = cefix::HSVtoRGB(cefix::randomf(360.0f), 1,1);
               context->set_source_rgba(c[0], c[1], c[2], i / 800.0f);
               context->move_to(i*fac, 0);
context->curve_to( i, 0, image->s() - (i * fac), image->t(), cefix::randomf(image->s()), cefix::randomf(image->t()));
               context->stroke();
           }

           // update the image
           image->dirty();

           //enable premultiplied alpha-blending
geode->getOrCreateStateSet()->setAttributeAndModes(new osg::BlendFunc(osg::BlendFunc::ONE, osg::BlendFunc::ONE_MINUS_SRC_ALPHA));

           // add it to the hud
           get2DLayer()->addChild(geode);

Are you somehow directly using the main OpenGL color buffer as your
surface (is this even possible?) Are you drawing on individual textures
(also Cairo surfaces) similar to me?

For now I am drawing into an osg::Image, which is used as a texture. I don't think that it is possible to draw directly into the color-buffer. With the help of PixeLbufferObjects the performance should be fine for the OpenGL side. Perhaps osgCairo is not that fast to do vector-based animations. I can only draw 20 curves per frame to get stabel 30fps.

cheers,

Stephan

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to