#ifdef _WIN32 #include <Windows.h> #endif // _WIN32 #include <osg/Group> #include <osg/Camera> #include <osgDB/ReadFile> #include <osg/Node> #include <osg/Geometry> #include <osg/Image> #include <osg/ShapeDrawable> #include <osg/Texture2D> #include <osg/MatrixTransform> #include <osg/AnimationPath> #include <osgViewer/Viewer> #include <osgViewer/ViewerEventHandlers> #include <osgGA/DriveManipulator> #include <osgGA/GUIEventHandler> #include <osgGA/GUIEventAdapter> #include <osgGA/GUIActionAdapter> #include <osgGA/AnimationPathManipulator> #include <osgGA/KeySwitchMatrixManipulator> #include <osgUtil/LineSegmentIntersector> #include <iostream> using namespace std; //顶点着色器 static const char* vertShader = { "varying vec4 color; " "void main(void) " "{ " "color = gl_Vertex; " "gl_Position=gl_ModelViewProjectionMatrix*gl_Vertex; " "} " }; //片元着色器 static const char* fragShader = { "varying vec4 color; " "void main(void) " "{ " " gl_FragColor = clamp(color,0.1,0.8); " "} " }; int main() { osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer; osg::ref_ptr<osg::Group> group1 = new osg::Group; osg::ref_ptr<osg::Program> program1 = new osg::Program; //osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("D:\参考手册\BIM\osg\四合院2019.osgb"); osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("D:\参考手册\BIM\obj\person1.obj"); osg::ref_ptr<osg::StateSet> stateset1 = node1->getOrCreateStateSet(); program1->addShader(new osg::Shader(osg::Shader::VERTEX, vertShader)); program1->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragShader)); stateset1->setAttributeAndModes(program1, osg::StateAttribute::ON); group1->addChild(node1.get()); viewer1->setSceneData(group1); viewer1->setUpViewInWindow(200, 200, 800, 600, 0); return viewer1->run(); }