// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { printf("Usage: testCGShader <filename.vp> <filename.fp>\n"); if( argc < 3 ) return 0; // OSG init OSG::osgInit(argc,argv); // GLUT init int winid = setupGLUT(&argc, argv); // the connection between GLUT and OpenSG OSG::GLUTWindowUnrecPtr gwin= OSG::GLUTWindow::create(); gwin->setGlutId(winid); gwin->setSize( 800, 800 ); gwin->init(); // Create the shader material OSG::ChunkMaterialUnrecPtr cmat = OSG::ChunkMaterial::create(); OSG::MaterialChunkUnrecPtr matc = OSG::MaterialChunk::create(); matc->setAmbient(OSG::Color4f(0.1, 0.1, 0.1, 1.0)); matc->setDiffuse(OSG::Color4f(0.3, 0.3, 0.3, 1.0)); matc->setSpecular(OSG::Color4f(0.8, 0.8, 0.8, 1.0)); matc->setShininess(100); matc->setLit(true); OSG::SHLChunkUnrecPtr shl = OSG::SHLChunk::create(); shl->readVertexProgram(argv[1]); shl->readFragmentProgram(argv[2]); cmat->addChunk(shl); // create root node _scene = OSG::Node::create(); // create torus OSG::GeometryUnrecPtr geo = OSG::makeTorusGeo(.8, 1.8, 128, 128); geo->setMaterial(cmat); OSG::NodeUnrecPtr torus = OSG::Node::create(); torus->setCore(geo); // add torus to scene OSG::GroupUnrecPtr group = OSG::Group::create(); _scene->setCore(group); _scene->addChild(torus); // create the SimpleSceneManager helper _mgr = OSG::SimpleSceneManager::create(); // tell the manager what to manage _mgr->setWindow(gwin ); _mgr->setRoot(_scene); /* // create point headlight _mgr->turnHeadlightOff(); NodePtr headlight = _mgr->getHighlight(); PointLightPtr light = PointLight::create(); beginEditCP(light); light->setAmbient (.3, .3, .3, 1); light->setDiffuse ( 1, 1, 1, 1); light->setSpecular ( 1, 1, 1, 1); light->setBeacon (_mgr->getCamera()->getBeacon()); endEditCP(light); beginEditCP(_scene); _scene->setCore(light); endEditCP(_scene); */ // show the whole scene _mgr->showAll(); // GLUT main loop glutMainLoop(); return 0; }