Hi,
i met trouble on iphone again!
i loaded an IVE model in my viewer. This viewer has a texture2D image
background which is rendered to the whole size of view. But I can not see any
model except for the texture background.
After i uncomment the code about rendering background, the model is loading
successfully. My code is below:
Code:
-(osg::Node *) create2DBGTexture
{
unsigned int w = 480;
unsigned int h = 320;
float vx = (float)w;
float vy = (float)h;
osg::ref_ptr<osg::Geometry> rectBG_geom = new osg::Geometry;
osg::Vec3Array * vertices = new osg::Vec3Array;
vertices->push_back(osg::Vec3(0.0, 0.0, -1.0));
vertices->push_back(osg::Vec3(0.0, vy, -1.0));
vertices->push_back(osg::Vec3(vx, vy, -1.0));
vertices->push_back(osg::Vec3(vx, 0.0, -1.0));
rectBG_geom->setVertexArray(vertices);
osg::Vec2Array * texcoords = new osg::Vec2Array;
texcoords->push_back(osg::Vec2(0.0, 0.0625));
texcoords->push_back(osg::Vec2(0.0, 0.9375));
texcoords->push_back(osg::Vec2(1.0, 0.9375));
texcoords->push_back(osg::Vec2(1.0, 0.0625));
rectBG_geom->setTexCoordArray(0,texcoords);
osg::Vec3Array * normals = new osg::Vec3Array;
normals->push_back(osg::Vec3(0.0f,0.0f,1.0f));
rectBG_geom->setNormalArray(normals);
rectBG_geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
rectBG_geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
BG_image = new osg::Image;
BG_image->setImage(AVWidth, AVHeight, 1, GL_RGBA, GL_BGRA,
GL_UNSIGNED_BYTE, pAVImage, osg::Image::NO_DELETE);
BG_texture = new osg::Texture2D;
BG_texture->setDataVariance(osg::Object::DYNAMIC);
BG_texture->setImage(BG_image);
BG_texture->setResizeNonPowerOfTwoHint(false);
BG_texture->setFilter(osg::Texture2D::MIN_FILTER,
osg::Texture2D::NEAREST);
BG_texture->setFilter(osg::Texture2D::MAG_FILTER,
osg::Texture2D::NEAREST);
osg::StateSet* stateset = rectBG_geom->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(0,BG_texture,osg::StateAttribute::ON);
osg::Geode * BG_geode = new osg::Geode;
BG_geode->addDrawable(rectBG_geom);
return BG_geode;
}
-(int) initOsgTree
{
int dwError = 0;
osg::setNotifyLevel(osg::DEBUG_INFO);
// camera
unsigned int w = 480;
unsigned int h = 320;
//create and attach ortho camera for hud text
osg::ref_ptr<osg::Camera> hudCamera = new osg::Camera;
hudCamera->setProjectionMatrix(osg::Matrix::ortho2D(0,w,0,h));
hudCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
hudCamera->setViewMatrix(osg::Matrix::identity());
hudCamera->setClearMask(GL_DEPTH_BUFFER_BIT);
hudCamera->setRenderOrder(osg::Camera::POST_RENDER);
ModelMatrix = new osg::MatrixTransform();
osg::ref_ptr<osg::Node> model = (osgDB::readNodeFile("myModel.IVE"));
ModelMatrix->addChild(model);
osg::Matrix m;
m.makeTranslate(osg::Vec3(0.0, 0.0, 10.0));
ModelMatrix->setMatrix(m);
osg::ref_ptr<osg::Group> MARRoot = new osg::Group;
MARRoot->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
hudCamera->addChild([self create2DBGTexture]);
MARRoot->addChild(hudCamera.get());
MARRoot->addChild(ModelMatrix.get());
// viewer
MARViewer = new osgViewer::Viewer();
MARViewer->setSceneData(MARRoot.get());
[b]MARViewer->setCameraManipulator(new
osgGA::MultiTouchTrackballManipulator);[/b]
MARViewer->realize();
MARViewer->frame();
return dwError;
}
My question:
1. How can i display both the model and view background?
The viewer is X-Y plane. The model's Z position is 10, and the background's
Z position is -1, so i think i should see the model. :<
2. API "setCameraManipulator" is necessary?? When i deleted this sentence, the
model would not be showed. But i ever watched some other examples, they loaded
models correctly without this API...
Thank you very much!
Cheers,
Tang
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=37280#37280
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org