diff --git a/Make/dependencies b/Make/dependencies index 2174aa9fb..8fa023c5a 100644 --- a/Make/dependencies +++ b/Make/dependencies @@ -21,6 +21,8 @@ FREETYPE_INSTALLED ?= yes XINE_INSTALLED ?= no +QT3_INSTALLED ?= no + ifeq ($(OS),Darwin) DARWIN_QUICKTIME ?= yes endif diff --git a/Make/makedirdefs b/Make/makedirdefs index d8b9e2b88..f1756c5fc 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -288,3 +288,9 @@ ifeq ($(GLUT_INSTALLED),yes) EXAMPLE_DIRS += osgGLUTkeyboardmouse endif + +ifeq ($(QT3_INSTALLED),yes) + + EXAMPLE_DIRS += osgsimpleviewerQT3 + +endif diff --git a/examples/osgsimpleviewerQT3/GNUmakefile b/examples/osgsimpleviewerQT3/GNUmakefile new file mode 100644 index 000000000..17e83a9b5 --- /dev/null +++ b/examples/osgsimpleviewerQT3/GNUmakefile @@ -0,0 +1,23 @@ +TOPDIR = ../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osgsimpleviewerQT3.cpp\ + +LIBS += -losgGA -losgDB -losgUtil -losg -lqt-mt $(GL_LIBS) $(OTHER_LIBS) + +INSTFILES = \ + $(CXXFILES)\ + GNUmakefile.inst=GNUmakefile + +EXEC = osgsimpleviewerQT3 + +INC += -I/usr/lib/qt3/include + +ifeq ($(ARCH),64) + LDFLAGS += -L/usr/lib/qt3/lib64 +else + LDFLAGS += -L/usr/lib/qt3/lib +endif + +include $(TOPDIR)/Make/makerules diff --git a/examples/osgsimpleviewerQT3/GNUmakefile.inst b/examples/osgsimpleviewerQT3/GNUmakefile.inst new file mode 100644 index 000000000..15c151db4 --- /dev/null +++ b/examples/osgsimpleviewerQT3/GNUmakefile.inst @@ -0,0 +1,19 @@ +TOPDIR = ../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osgsimpleviewerQT3.cpp\ + +LIBS += -losgDB -losgUtil -losg -lglut $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +EXEC = osgsimpleviewerQT3 + +INC += -I/usr/lib/qt3/include + +ifeq ($(ARCH),64) + LDFLAGS += -L/usr/lib/qt3/lib64 +else + LDFLAGS += -L/usr/lib/qt3/lib +endif + +include $(TOPDIR)/Make/makerules diff --git a/examples/osgsimpleviewerQT3/osgsimpleviewerQT3.cpp b/examples/osgsimpleviewerQT3/osgsimpleviewerQT3.cpp new file mode 100644 index 000000000..43d165a94 --- /dev/null +++ b/examples/osgsimpleviewerQT3/osgsimpleviewerQT3.cpp @@ -0,0 +1,134 @@ +// C++ source file - (C) 2003 Robert Osfield, released under the OSGPL. +// (C) 2005 Mike Weiblen http://mew.cx/ released under the OSGPL. +// Simple example using GLUT to create an OpenGL window and OSG for rendering. +// Derived from osgGLUTsimple.cpp and osgkeyboardmouse.cpp + +#include +#include +#include + +class QWidget; +#include +#include +#include + +#include + +class OSGWidget : public QGLWidget, public osgGA::SimpleViewer +{ +public: + + OSGWidget( QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WFlags f = 0 ); + virtual ~OSGWidget() {} + +protected: + + virtual void initializeGL(); + virtual void paintGL(); + + virtual void resizeGL( int width, int height ); + virtual void keyPressEvent( QKeyEvent* event ); + virtual void keyReleaseEvent( QKeyEvent* event ); + virtual void mousePressEvent( QMouseEvent* event ); + virtual void mouseReleaseEvent( QMouseEvent* event ); + virtual void mouseMoveEvent( QMouseEvent* event ); + + QTimer _timer; +}; + +OSGWidget::OSGWidget( QWidget * parent, const char * name, const QGLWidget * shareWidget, WFlags f): + QGLWidget(parent, name, shareWidget, f) +{ + connect(&_timer, SIGNAL(timeout()), this, SLOT(updateGL())); + _timer.start(10); +} + +void OSGWidget::initializeGL() +{ + QGLWidget::initializeGL(); +} + +void OSGWidget::paintGL() +{ + frame(); +} + +void OSGWidget::resizeGL( int width, int height ) +{ + getEventQueue()->windowResize(0, 0, width, height ); +} + +void OSGWidget::keyPressEvent( QKeyEvent* event ) +{ + getEventQueue()->keyPress( (osgGA::GUIEventAdapter::KeySymbol) event->ascii() ); +} + +void OSGWidget::keyReleaseEvent( QKeyEvent* event ) +{ + getEventQueue()->keyRelease( (osgGA::GUIEventAdapter::KeySymbol) event->ascii() ); +} + +void OSGWidget::mousePressEvent( QMouseEvent* event ) +{ + int button = 0; + switch(event->button()) + { + case(Qt::LeftButton): button = 1; break; + case(Qt::MidButton): button = 2; break; + case(Qt::RightButton): button = 3; break; + case(Qt::NoButton): button = 0; break; + default: button = 0; break; + } + getEventQueue()->mouseButtonPress(event->x(), event->y(), button); +} + +void OSGWidget::mouseReleaseEvent( QMouseEvent* event ) +{ + int button = 0; + switch(event->button()) + { + case(Qt::LeftButton): button = 1; break; + case(Qt::MidButton): button = 2; break; + case(Qt::RightButton): button = 3; break; + case(Qt::NoButton): button = 0; break; + default: button = 0; break; + } + getEventQueue()->mouseButtonRelease(event->x(), event->y(), button); +} + +void OSGWidget::mouseMoveEvent( QMouseEvent* event ) +{ + getEventQueue()->mouseMotion(event->x(), event->y()); +} + +int main( int argc, char **argv ) +{ + QApplication a( argc, argv ); + + if (argc<2) + { + std::cout << argv[0] <<": requires filename argument." << std::endl; + return 1; + } + + // load the scene. + osg::ref_ptr loadedModel = osgDB::readNodeFile(argv[1]); + if (!loadedModel) + { + std::cout << argv[0] <<": No data loaded." << std::endl; + return 1; + } + + + OSGWidget* viewerWindow = new OSGWidget; + + viewerWindow->setSceneData(loadedModel.get()); + viewerWindow->setCameraManipulator(new osgGA::TrackballManipulator); + + viewerWindow->show(); + a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) ); + + return a.exec(); +} + +/*EOF*/