| 286 | | |
| | 286 | osg::Node* createSimpleTestModel() |
| | 287 | { |
| | 288 | osg::Group* group = new osg::Group; |
| | 289 | |
| | 290 | osg::Geode* geode = new osg::Geode; |
| | 291 | group->addChild(geode); |
| | 292 | |
| | 293 | osg::Geometry* geometry = new osg::Geometry; |
| | 294 | geode->addDrawable(geometry); |
| | 295 | |
| | 296 | osg::Vec3Array* vertices = new osg::Vec3Array; |
| | 297 | vertices->push_back(osg::Vec3(0.0,0.0,0.0)); |
| | 298 | vertices->push_back(osg::Vec3(0.0,0.0,1.0)); |
| | 299 | vertices->push_back(osg::Vec3(1.0,0.0,0.0)); |
| | 300 | vertices->push_back(osg::Vec3(1.0,0.0,1.0)); |
| | 301 | geometry->setVertexArray(vertices); |
| | 302 | |
| | 303 | geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, 4)); |
| | 304 | |
| | 305 | char vertexShaderSource[] = |
| | 306 | "void main(void)\n" |
| | 307 | "{\n" |
| | 308 | " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" |
| | 309 | "}\n"; |
| | 310 | |
| | 311 | char fragmentShaderSource[] = |
| | 312 | "void main(void)\n" |
| | 313 | "{\n" |
| | 314 | " gl_FragColor = vec4(1.0,1.0,0.0,1.0); \n" |
| | 315 | "}\n"; |
| | 316 | |
| | 317 | osg::Program* program = new osg::Program; |
| | 318 | program->addShader(new osg::Shader(osg::Shader::VERTEX, vertexShaderSource)); |
| | 319 | program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource)); |
| | 320 | |
| | 321 | geometry->getOrCreateStateSet()->setAttribute(program); |
| | 322 | |
| | 323 | return group; |
| | 324 | } |
| 316 | | // convert fixed function pipeline to shaders |
| 317 | | osgUtil::ShaderGenVisitor sgv; |
| 318 | | loadedModel->accept(sgv); |
| | 346 | bool runShaderGen = true; |
| | 347 | while (arguments.read("--shader-gen")) { runShaderGen = true; } |
| | 348 | while (arguments.read("--no-shader-gen")) { runShaderGen = false; } |
| | 349 | |
| | 350 | while (arguments.read("--vertex-attrib")) { runConvertToVertexAttributes = true; } |
| | 351 | while (arguments.read("--no-vertex-attrib")) { runConvertToVertexAttributes = false; } |
| | 352 | |
| | 353 | loadedModel = osgDB::readNodeFiles(arguments); |
| | 354 | if (!loadedModel.get()) |
| | 355 | { |
| | 356 | osg::notify(osg::NOTICE)<<"No model loaded, please specify a model filename."<<std::endl; |
| | 357 | return 1; |
| | 358 | } |
| | 359 | |
| | 360 | if (runShaderGen) |
| | 361 | { |
| | 362 | // convert fixed function pipeline to shaders |
| | 363 | osgUtil::ShaderGenVisitor sgv; |
| | 364 | loadedModel->accept(sgv); |
| | 365 | } |
| | 366 | |
| | 367 | if (runConvertToVertexAttributes) |
| | 368 | { |
| | 369 | // find any conventional vertex, colour, normal and tex coords arrays and convert to vertex attributes |
| | 370 | ConvertToVertexAttibArrays ctvaa; |
| | 371 | loadedModel->accept(ctvaa); |
| | 372 | } |