| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #include <iostream> |
|---|
| 20 | |
|---|
| 21 | #include <osg/Notify> |
|---|
| 22 | #include <osg/io_utils> |
|---|
| 23 | |
|---|
| 24 | #include <osg/ArgumentParser> |
|---|
| 25 | #include <osgDB/WriteFile> |
|---|
| 26 | #include <osgGA/TrackballManipulator> |
|---|
| 27 | #include <osgGA/StateSetManipulator> |
|---|
| 28 | #include <osgViewer/Viewer> |
|---|
| 29 | #include <osgViewer/ViewerEventHandlers> |
|---|
| 30 | #include <osgWidget/Browser> |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | #include <QtWebKit/QWebSettings> |
|---|
| 34 | #include <QtWebKit/QtWebKit> |
|---|
| 35 | #include <QtGui/QGraphicsScene> |
|---|
| 36 | #include <QtGui/QGraphicsView> |
|---|
| 37 | #include <QtGui/QApplication> |
|---|
| 38 | #include <QtGui/QPainter> |
|---|
| 39 | #include <QtGui/QtEvents> |
|---|
| 40 | |
|---|
| 41 | #include <osgQt/QGraphicsViewAdapter> |
|---|
| 42 | #include <osgQt/QWebViewImage> |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | class ViewerFrameThread : public OpenThreads::Thread |
|---|
| 47 | { |
|---|
| 48 | public: |
|---|
| 49 | |
|---|
| 50 | ViewerFrameThread(osgViewer::ViewerBase* viewerBase, bool doQApplicationExit): |
|---|
| 51 | _viewerBase(viewerBase), |
|---|
| 52 | _doQApplicationExit(doQApplicationExit) {} |
|---|
| 53 | |
|---|
| 54 | ~ViewerFrameThread() |
|---|
| 55 | { |
|---|
| 56 | cancel(); |
|---|
| 57 | while(isRunning()) |
|---|
| 58 | { |
|---|
| 59 | OpenThreads::Thread::YieldCurrentThread(); |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | int cancel() |
|---|
| 64 | { |
|---|
| 65 | _viewerBase->setDone(true); |
|---|
| 66 | return 0; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | void run() |
|---|
| 70 | { |
|---|
| 71 | int result = _viewerBase->run(); |
|---|
| 72 | |
|---|
| 73 | if (_doQApplicationExit) QApplication::exit(result); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | osg::ref_ptr<osgViewer::ViewerBase> _viewerBase; |
|---|
| 77 | bool _doQApplicationExit; |
|---|
| 78 | }; |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | int main(int argc, char **argv) |
|---|
| 82 | { |
|---|
| 83 | |
|---|
| 84 | QApplication app(argc, argv); |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 88 | |
|---|
| 89 | bool useFrameLoopThread = true; |
|---|
| 90 | if (arguments.read("--no-frame-thread")) useFrameLoopThread = false; |
|---|
| 91 | |
|---|
| 92 | osg::ref_ptr<osgQt::QWebViewImage> image = new osgQt::QWebViewImage; |
|---|
| 93 | |
|---|
| 94 | if (arguments.argc()>1) image->navigateTo((arguments[1])); |
|---|
| 95 | else image->navigateTo("http://www.youtube.com/"); |
|---|
| 96 | |
|---|
| 97 | osgWidget::GeometryHints hints(osg::Vec3(0.0f,0.0f,0.0f), |
|---|
| 98 | osg::Vec3(1.0f,0.0f,0.0f), |
|---|
| 99 | osg::Vec3(0.0f,0.0f,1.0f), |
|---|
| 100 | osg::Vec4(1.0f,1.0f,1.0f,1.0f), |
|---|
| 101 | osgWidget::GeometryHints::RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO); |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | osg::ref_ptr<osgWidget::Browser> browser = new osgWidget::Browser; |
|---|
| 105 | browser->assign(image.get(), hints); |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer(arguments); |
|---|
| 110 | viewer->setSceneData(browser.get()); |
|---|
| 111 | viewer->setCameraManipulator(new osgGA::TrackballManipulator()); |
|---|
| 112 | viewer->addEventHandler(new osgViewer::StatsHandler); |
|---|
| 113 | viewer->addEventHandler(new osgViewer::WindowSizeHandler); |
|---|
| 114 | |
|---|
| 115 | if (useFrameLoopThread) |
|---|
| 116 | { |
|---|
| 117 | |
|---|
| 118 | ViewerFrameThread viewerThread(viewer.get(), true); |
|---|
| 119 | viewerThread.startThread(); |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | return QApplication::exec(); |
|---|
| 123 | |
|---|
| 124 | } |
|---|
| 125 | else |
|---|
| 126 | { |
|---|
| 127 | |
|---|
| 128 | while(!viewer->done()) |
|---|
| 129 | { |
|---|
| 130 | |
|---|
| 131 | QCoreApplication::processEvents(QEventLoop::AllEvents, 100); |
|---|
| 132 | |
|---|
| 133 | viewer->frame(); |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | return 0; |
|---|
| 137 | } |
|---|
| 138 | } |
|---|