| 152 | | osgProducer::Viewer viewer(arguments); |
| 153 | | |
| 154 | | // set up the value with sensible default event handlers. |
| 155 | | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
| 156 | | |
| 157 | | // get details on keyboard and mouse bindings used by the viewer. |
| 158 | | viewer.getUsage(*arguments.getApplicationUsage()); |
| 159 | | |
| 160 | | // if user request help write it out to cout. |
| 161 | | if (arguments.read("-h") || arguments.read("--help")) |
| 162 | | { |
| 163 | | arguments.getApplicationUsage()->write(std::cout); |
| 164 | | return 1; |
| 165 | | } |
| 166 | | |
| 167 | | // any option left unread are converted into errors to write out later. |
| 168 | | arguments.reportRemainingOptionsAsUnrecognized(); |
| 169 | | |
| 170 | | // report any errors if they have occured when parsing the program aguments. |
| 171 | | if (arguments.errors()) |
| 172 | | { |
| 173 | | arguments.writeErrorMessages(std::cout); |
| 174 | | return 1; |
| 175 | | } |
| 176 | | |
| 177 | | if (arguments.argc()<=1) |
| 178 | | { |
| 179 | | arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); |
| 180 | | return 1; |
| 181 | | } |
| | 148 | osgViewer::Viewer viewer; |
| 187 | | if (loadedModel) |
| 188 | | { |
| 189 | | |
| 190 | | osg::StateSet* stateset = create1DTextureStateToDecorate(loadedModel); |
| 191 | | if (!stateset) |
| 192 | | { |
| 193 | | std::cout<<"Error: failed to create 1D texture state."<<std::endl; |
| 194 | | return 1; |
| 195 | | } |
| 196 | | |
| 197 | | |
| 198 | | loadedModel->setStateSet(stateset); |
| 199 | | loadedModel->setUpdateCallback(new AnimateStateCallback()); |
| 200 | | |
| 201 | | // add model to viewer. |
| 202 | | viewer.setSceneData( loadedModel ); |
| 203 | | |
| 204 | | // create the windows and run the threads. |
| 205 | | viewer.realize(); |
| 206 | | |
| 207 | | while( !viewer.done() ) |
| 208 | | { |
| 209 | | // wait for all cull and draw threads to complete. |
| 210 | | viewer.sync(); |
| 211 | | |
| 212 | | // update the scene by traversing it with the the update visitor which will |
| 213 | | // call all node update callbacks and animations. |
| 214 | | viewer.update(); |
| 215 | | |
| 216 | | // fire off the cull and draw traversals of the scene. |
| 217 | | viewer.frame(); |
| 218 | | |
| 219 | | } |
| 220 | | |
| 221 | | // wait for all cull and draw threads to complete. |
| 222 | | viewer.sync(); |
| 223 | | |
| 224 | | // run a clean up frame to delete all OpenGL objects. |
| 225 | | viewer.cleanup_frame(); |
| 226 | | |
| 227 | | // wait for all the clean up frame to complete. |
| 228 | | viewer.sync(); |
| 229 | | } |
| 230 | | else |
| | 153 | if (!loadedModel) |