Thank your for your reply, Stephan. 

You were right. I changed my code: 

> - (void)applicationDidFinishLaunching:(UIApplication *)application {
>     
>      osg::setNotifyLevel(osg::DEBUG_INFO);
> 
>     _viewer = new osgViewer::Viewer();
>     _root = new osg::Group;   
>     
>     
>     //
>     //Create a Group with Box, Sphere and Cone
>     //
>     osg::ref_ptr<osg::ShapeDrawable> shape1 = new osg::ShapeDrawable;
>     shape1->setShape(new osg::Box(osg::Vec3(-3.0f, 0.0f, 0.0f), 2.0f, 2.0f, 
> 2.0f)); 
>     shape1->setColor(osg::Vec4(1.0f, 0.0f, 0.0f, 0.0f));
>     
>     osg::ref_ptr<osg::ShapeDrawable> shape2 = new osg::ShapeDrawable; 
>     shape2->setShape(new osg::Sphere(osg::Vec3(3.0f, 0.0f, 0.0f), 1.0f)); 
>     shape2->setColor(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f));
>     
>     osg::ref_ptr<osg::ShapeDrawable> shape3 = new osg::ShapeDrawable; 
>     shape3->setShape(new osg::Cone(osg::Vec3(0.0f, 0.0f, 0.0f), 1.0f, 1.0f)); 
>     shape3->setColor(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f));
>     
>     osg::ref_ptr<osg::Geode> geode = new osg::Geode; 
>     geode->addDrawable(shape1.get());
>     geode->addDrawable(shape2.get());
>     geode->addDrawable(shape3.get());
>     
>     // try msaa. available for iOS >= 4.0
>     osg::DisplaySettings* settings = osg::DisplaySettings::instance();
>     settings->setNumMultiSamples(4);
>    
>     OpenSceneGraph_iOSViewController* touch_handler = new 
> OpenSceneGraph_iOSViewController();
>       
>     unsigned int w(640);
>     unsigned int h(480);
>     
>     osg::GraphicsContext::WindowingSystemInterface* wsi = 
> osg::GraphicsContext::getWindowingSystemInterface();
>               
>     if (wsi) 
>     {
>         wsi->getScreenResolution(0, w, h);
>     }
>     
>     //
>     //Camera
>     //
>     //create and attach ortho camera for hud text
>     osg::ref_ptr<osg::Camera> hudCamera = new osg::Camera;
>     
>     // set the projection matrix
>     hudCamera->setProjectionMatrix(osg::Matrix::ortho2D(0,w,0,h));
>               
>     // set the view matrix    
>     hudCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
>     hudCamera->setViewMatrix(osg::Matrix::identity());
>     
>     // only clear the depth buffer
>     hudCamera->setClearMask(GL_DEPTH_BUFFER_BIT);
>               
>     // draw subgraph after main camera view.
>     hudCamera->setRenderOrder(osg::Camera::PRE_RENDER);; 
>         
>     hudCamera->addChild(touch_handler->getDebugNode());
>     
>     
>     //
>     // Texture for Background
>     //
>     osg::Geometry *rectBackground = new osg::Geometry; 
>     osg::Vec3Array* vertices = new osg::Vec3Array(4); 
>     (*vertices)[1].set(0.f, 0.f, 0.f); 
>     (*vertices)[2].set((float)w, 0.f, 0.f); 
>     (*vertices)[3].set((float)w, 0.f, (float)h); 
>     rectBackground->setVertexArray(vertices); 
>      
>     osg::Vec2Array* texcoords = new osg::Vec2Array(4); 
>     (*texcoords)[0].set(0.0f, (float)h); 
>     (*texcoords)[1].set(0.0f, 0.0f); 
>     (*texcoords)[2].set((float)w, 0.0f); 
>     (*texcoords)[3].set((float)w, (float)h); 
>     rectBackground->setTexCoordArray(0,texcoords); 
>     
>     osg::Vec3Array* normals = new osg::Vec3Array(1); 
>     (*normals)[0].set(0.0f,1.0f,0.0f); 
>     rectBackground->setNormalArray(normals); 
>     rectBackground->setNormalBinding(osg::Geometry::BIND_OVERALL); 
>     rectBackground->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); 
>     osg::Geode* Background_geode = new osg::Geode; 
>     Background_geode->addDrawable(rectBackground); 
>      
>     // set up the texture state.    
>     osg::ref_ptr<osg::TextureRectangle> Background_texture = new 
> osg::TextureRectangle; 
>     Background_texture->setDataVariance(osg::Object::DYNAMIC); 
>     
>     // protect from being optimized away as static state. 
>     Background_texture->setImage(osgDB::readImageFile("imagefile.jpg")); 
>     osg::StateSet* stateset = rectBackground->getOrCreateStateSet(); 
>     
> stateset->setTextureAttributeAndModes(0,Background_texture,osg::StateAttribute::ON);
>  
>     
>     
>     //
>     // root
>     //
>     hudCamera->addChild(Background_geode); 
>     
>     osg::Node* one = hudCamera.get(); 
>     osg::Node* two = geode.get(); 
>     
>     one->getOrCreateStateSet()->setRenderBinDetails(1, "RenderBin");
>     two->getOrCreateStateSet()->setRenderBinDetails(2, "RenderBin");
>     
>     _root->addChild(one); 
>     _root->addChild(two); 
>     
>     _root->getOrCreateStateSet()->setMode(GL_DEPTH_BITS, 
> osg::StateAttribute::OFF);
>     two->getOrCreateStateSet()->setMode(GL_DEPTH_BITS, 
> osg::StateAttribute::ON); 
>     
>     //
>     // viewer
>     //
>     _viewer->addEventHandler(touch_handler);
>     _viewer->setSceneData(_root.get());
>     _viewer->setCameraManipulator(new osgGA::MultiTouchTrackballManipulator);
>       _viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
>     
>     
>     //SingleThreaded DrawTheadPerContext
>       _viewer->realize();
>       _viewer->frame();
>       osg::setNotifyLevel(osg::INFO);
>       
>       [NSTimer scheduledTimerWithTimeInterval:1.0/30.0 target:self 
> selector:@selector(updateScene) userInfo:nil repeats:YES]; 
>       
>       //Configure and start accelerometer
>       [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 
> kAccelerometerFrequency)];
>       [[UIAccelerometer sharedAccelerometer] setDelegate:self];
> }


Now a geode with geometry is created and it is added to the group. I don´t 
know,  which step i had to do after this. Can you give some advice. I have 
already used the search function. But i cannot find the right answer.

Additionaly I get this warning: 


> Warning: TextureRectangle::apply(..) failed, texture rectangle is not support 
> by your OpenGL drivers.
> Warning: TextureRectangle::apply(..) failed, texture rectangle is not support 
> by your OpenGL drivers.
> Warning: detected OpenGL error 'invalid enumerant' at after 
> RenderBin::draw(..)

I have Mac OS X 10.6.7.

Can you please give me any advice or link that could help me.  


Cheers,
Büsra

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=41397#41397





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to