Hi Mike,
You can set the internal texture format via :
texture->setInternalFormat(internalformat);
In you case setInternalFormat(GL_BGRA) might just do the trick.
As for the most efficient way to do what you are doing you'll want to
attach an osg::PixelBufferObject to a single osg::Image, and then do a
setData on this single image. This way the OSG can use the pixel
buffer object extension to stream the data to the texture. You'd also
best do all reading in a background thread as per the xine-lib and
quicktime plugins.
Robert.
On Fri, May 23, 2008 at 1:29 PM, Mike Greene <[EMAIL PROTECTED]> wrote:
> Hi,
> I have the following simple program (modified texture rectangle sample).
> I'm reading a set of large (1920x1080) bitmaps from disk and swapping each
> callback loop. My problem is that the bmps need to be in BGRA instead of
> RGBA format. Can I change the TextureRectangle in OSG to compensate for
> this?
>
> Mike Greene
>
> //code
>
> #include <osg/Notify>
> #include <osg/TextureRectangle>
> #include <osg/Geometry>
> #include <osg/Geode>
> #include <osg/TexMat>
>
> #include <osg/Group>
> #include <osg/Projection>
> #include <osg/MatrixTransform>
> #include <osgText/Text>
>
> #include <osgDB/Registry>
> #include <osgDB/ReadFile>
>
> #include <osgViewer/Viewer>
>
> osg::Image* img = new osg::Image();
> osg::TextureRectangle* texture = new osg::TextureRectangle();
>
> long texturecounter = 0;
>
> class TextureChangeCallback : public osg::NodeCallback
> {
> public:
> TextureChangeCallback(
> double delay = 0.05) :
> _phaseS(35.0f),
> _phaseT(18.0f),
> _phaseScale(5.0f),
> _delay(delay),
> _prevTime(0.0)
> {
> }
>
> virtual void operator()(osg::Node*, osg::NodeVisitor* nv)
> {
> if (texturecounter == 0) img =
> osgDB::readImageFile("c:\\mgreene\\data\\mach00.bmp");
> if (texturecounter == 1) img =
> osgDB::readImageFile("c:\\mgreene\\data\\mach01.bmp");
> if (texturecounter == 2) img =
> osgDB::readImageFile("c:\\mgreene\\data\\mach02.bmp");
> if (texturecounter == 3) img =
> osgDB::readImageFile("c:\\mgreene\\data\\mach03.bmp");
> if (texturecounter == 4) img =
> osgDB::readImageFile("c:\\mgreene\\data\\mach04.bmp");
> if (texturecounter == 5) img =
> osgDB::readImageFile("c:\\mgreene\\data\\mach05.bmp");
>
> texture->setImage(img);
> texturecounter+=1;
> if (texturecounter == 6) texturecounter = 0;
> }
>
> private:
>
> float _phaseS, _phaseT, _phaseScale;
>
> double _delay;
> double _prevTime;
> };
>
> int main(int argc, char** argv)
> {
> // use an ArgumentParser object to manage the program arguments.
> osg::ArgumentParser arguments(&argc,argv);
>
> osg::Group* root = new osg::Group;
> osg::BoundingBox bb(0.0f,0.0f,0.0f,1.0f,1.78f,1.78f);
>
> /////////////////
> osg::Vec3 top_left(bb.xMin(),bb.yMax(),bb.zMax());
> osg::Vec3 bottom_left(bb.xMin(),bb.yMax(),bb.zMin());
> osg::Vec3 bottom_right(bb.xMax(),bb.yMax(),bb.zMin());
> osg::Vec3 top_right(bb.xMax(),bb.yMax(),bb.zMax());
> // create geometry
> osg::Geometry* geom = new osg::Geometry;
>
> osg::Vec3Array* vertices = new osg::Vec3Array(4);
> (*vertices)[0] = top_left;
> (*vertices)[1] = bottom_left;
> (*vertices)[2] = bottom_right;
> (*vertices)[3] = top_right;
> geom->setVertexArray(vertices);
> osg::Vec2Array* texcoords = new osg::Vec2Array(4);
> (*texcoords)[0].set(0.0f, 0.0f);
> (*texcoords)[1].set(1.0f, 0.0f);
> (*texcoords)[2].set(1.0f, 1.0f);
> (*texcoords)[3].set(0.0f, 1.0f);
> geom->setTexCoordArray(0,texcoords);
>
> osg::Vec3Array* normals = new osg::Vec3Array(1);
> (*normals)[0].set(0.0f,-1.0f,0.0f);
> geom->setNormalArray(normals);
> geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
>
> osg::Vec4Array* colors = new osg::Vec4Array(1);
> (*colors)[0].set(1.0f,1.0f,1.0f,1.0f);
> geom->setColorArray(colors);
> geom->setColorBinding(osg::Geometry::BIND_OVERALL);
>
> geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4));
>
> // disable display list so our modified tex coordinates show up
> geom->setUseDisplayList(false);
>
> // load image
> img = osgDB::readImageFile("c:\\mgreene\\data\\mach00.bmp");
>
> // setup texture
> texture->setImage(img);
>
> osg::TexMat* texmat = new osg::TexMat;
> texmat->setScaleByTextureRectangleSize(true);
>
> // setup state
> osg::StateSet* state = geom->getOrCreateStateSet();
> state->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
> state->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON);
>
> // turn off lighting
> state->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
>
> // install 'update' callback
> osg::Geode* geode = new osg::Geode;
> geode->addDrawable(geom);
> geode->setUpdateCallback(new TextureChangeCallback());
>
> //////////////////////
>
> root->addChild(geode);
>
>
> // construct the viewer.
> osgViewer::Viewer viewer;
>
> // create a model from the images.
> osg::Node* rootNode = root;//createModel((arguments.argc() > 1 ?
> arguments[1] : "b:\\test00.jpg"));//"Images/lz.rgb"));
>
> // add model to viewer.
> viewer.setSceneData(rootNode);
>
> viewer.realize();
> while( !viewer.done() )
> {
> viewer.run();
>
> }
> return 0;
>
> // return viewer.run();
> }
>
> _______________________________________________
> 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