Hi to all,

this is my first post in the osg forum. I'm using Openframework  in a creative 
way. I like interactivity and 3d graphics. I would like to make an installation 
in which you can see a big large terrain and other things. My first idea was to 
implement a terrain system with LOD and multipaging. I made a lot of  searching 
,finding many resources, different algorithm implementations, and libraries. 
Then i found and addon a ofxOpenSceneGraph to port osg into Openframework. 
that's great ! because osg has a terrain plugin... I was able to run osgTerrain 
inside Openframework but i have a problem , you can see in the image attached. 
Just a note : i ve used puget sound at the big resolution as explain in the osg 
HOW TO. In osg the same puget,ive works fine intead in Openframework the 
texture is not handled in the best way ( there are no detail but coloured 
square that became smaller with LOD) . wht could be? 
Is it an issue with openframework or i miss something in the code?  
i leave also part of the code (partially of course...)


Code:
#include "testApp.h"

#include <osg/Geode>
#include <osg/ShapeDrawable>
#include <osg/Shape>
#include <osgViewer/View>
#include <osgGA/TrackballManipulator>
#include <osgDB/ReadFile>


#include <osgTerrain/Terrain>
#include <osgTerrain/TerrainTile>
#include <osgTerrain/GeometryTechnique>
#include <osgTerrain/Layer>
#include <iostream>

using namespace std;
using namespace osg;
using namespace osgUtil;

template<class T>
class FindTopMostNodeOfTypeVisitor : public osg::NodeVisitor
{
public:
    FindTopMostNodeOfTypeVisitor():
        osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
        _foundNode(0)
    {}

    void apply(osg::Node& node)
    {
        T* result = dynamic_cast<T*>(&node);
        if (result)
        {
            _foundNode = result;
        }
        else
        {
            traverse(node);
        }
    }

    T* _foundNode;
};


template<class T>
T* findTopMostNodeOfType(osg::Node* node)
{
    if (!node) return 0;

    FindTopMostNodeOfTypeVisitor<T> fnotv;
    node->accept(fnotv);

    return fnotv._foundNode;
}

//--------------------------------------------------------------
void testApp::setup(){
    std::cout << "setup" << std::endl;
    //ofSetColor(120,120,120);
    osg::setNotifyLevel(osg::DEBUG_INFO);


    //osg::ShapeDrawable* drawable = new osg::ShapeDrawable(new 
osg::Box(osg::Vec3(0,0,0), 1.0f));
    //osg::Geode* geode = new osg::Geode();
    //geode->addDrawable(drawable);

    // obtain the vertical scale
    float verticalScale = 1.0f;
    //while(arguments.read("-v",verticalScale)) {}

    // obtain the sample ratio
    float sampleRatio = 1.0f;
    //while(arguments.read("-r",sampleRatio)) {}

    std::string strBlendingPolicy;
    strBlendingPolicy = "ENABLE_BLENDING";

     osgTerrain::TerrainTile::BlendingPolicy blendingPolicy = 
osgTerrain::TerrainTile::ENABLE_BLENDING;
     //osgTerrain::TerrainTile::setDirtyMask(1);// dirtyMask = 
osgTerrain::TerrainTile::IMAGERY_DIRTY;
   //osgTerrain::TerrainTile->setDirty(true) dirty = 
osgTerrain::TerrainTile::true ;
     /*
    std::string strBlendingPolicy;
    while(arguments.read("--blending-policy", strBlendingPolicy))
    {
        if (strBlendingPolicy == "INHERIT") blendingPolicy = 
osgTerrain::TerrainTile::INHERIT;
        else if (strBlendingPolicy == "DO_NOT_SET_BLENDING") blendingPolicy = 
osgTerrain::TerrainTile::DO_NOT_SET_BLENDING;
        else if (strBlendingPolicy == "ENABLE_BLENDING") blendingPolicy = 
osgTerrain::TerrainTile::ENABLE_BLENDING;
        else if (strBlendingPolicy == "ENABLE_BLENDING_WHEN_ALPHA_PRESENT") 
blendingPolicy = osgTerrain::TerrainTile::ENABLE_BLENDING_WHEN_ALPHA_PRESENT;
    }
*/

    // load the nodes from the commandline arguments.
    osg::ref_ptr<osg::Node> rootnode = osgDB::readNodeFile("puget.ive");

    if (!rootnode)
    {
        osg::notify(osg::NOTICE)<<"Warning: no valid data loaded, please 
specify a database on the command line."<<std::endl;
        return ;
    }

      osg::ref_ptr<osgTerrain::Terrain> terrain = 
findTopMostNodeOfType<osgTerrain::Terrain>(rootnode.get());
    if (!terrain)
    {
        // no Terrain node present insert one above the loaded model.
        terrain = new osgTerrain::Terrain;

        // if CoordinateSystemNode is present copy it's contents into the 
Terrain, and discard it.
        osg::CoordinateSystemNode* csn = 
findTopMostNodeOfType<osg::CoordinateSystemNode>(rootnode.get());
        if (csn)
        {
            terrain->set(*csn);
            for(unsigned int i=0; i<csn->getNumChildren();++i)
            {
                terrain->addChild(csn->getChild(i));
            }
        }
        else
        {
            terrain->addChild(rootnode.get());
        }

        rootnode = terrain.get();
    }
    terrain->setSampleRatio(sampleRatio);
    terrain->setVerticalScale(verticalScale);
    terrain->setBlendingPolicy(blendingPolicy);


   glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    getView()->setSceneData(rootnode.get());
    getView()->setCameraManipulator(new osgGA::TrackballManipulator());
   osg::setNotifyLevel(osg::WARN);
}

//--------------------------------------------------------------
void testApp::update(){
     // std::cout << "update" << std::endl;
}

//--------------------------------------------------------------
void testApp::draw(){
     // std::cout << "draw" << std::endl;
    ofDrawBitmapString("ofxOpenSceneGraph Demo", 10, 10);
    ofDrawBitmapString("fps: "+ofToString((ofGetFrameRate())), 10, 25);

    ofDrawBitmapString("'1': set window position\n'2': set window size\n'f': 
disable full screen \n'F': enable full screen\n's': show osg's stats-handler", 
10,50);
}

//--------------------------------------------------------------
void testApp::keyPressed(int key){
    std::cout << "keypressed" << std::endl;
    switch(key) {
        case '1':
            ofSetWindowPosition(100,100);
            break;
        case '2':
            ofSetWindowShape(400, 300);
            break;
        case 'f':
            ofSetFullscreen(false);
            break;
        case 'F':
            ofSetFullscreen(true);
            break;

    }
} 



if someone can enlight on this should be great!




Thank you!

Cheers,
walter :)

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




Attachments: 
http://forum.openscenegraph.org//files/screenshot_3_286.png


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

Reply via email to