/*************************************************************************** * Copyright (C) 2003 by Rick L. Vinyard, Jr. * * rvinyard@cs.nmsu.edu * * * * This file is part of the osgGtk library. * * * * The osgGtk library is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * version 3 as published by the Free Software Foundation. * * * * The osgGtk library is distributed in the hope that it will be * * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this software. If not see <http://www.gnu.org/licenses/>. * ***************************************************************************/ // Of course, we need the gtkmm headers #include <gtkmm.h> // We'll need this to load the command line argument #include <osgDB/ReadFile> // And we'll need this for the Gtkmm OSG viewer #include <osgGtkmm/ViewerGtkmm.h> int main( int argc, char** argv ) { // We'll set a basic size of 800x600, but the user can resize larger if desired // (but not smaller) int width=800, height=600; // This is some gtkmm housekeeping... we need the main loop and we also need to // initialize the OpenGL system Gtk::Main gtkmm_main( argc, argv ); Gtk::GL::init( argc, argv ); // Now, let's create our viewer using ViewerGtkmm so we can use the gtkmm // convenience method later // // We'll also set desired frame rate of 60 fps and load the first command line // argument as the scene osgViewer::ViewerGtkmm viewer; viewer.set_fps(60); if ( argc >= 2 ) { osg::ref_ptr<osg::Node> model = osgDB::readNodeFile(argv[1]); if ( model.valid() ) viewer.setSceneData(model.get()); } // Now we'll setup the viewer in a gtkmm window using the setup_viewer_in_gtkmm_window() // convenience method // // The return type is a Gtkmm widget (subclassed from Gtk::DrawingArea) that we can // use anywhere we want osgViewer::GraphicsWindowGtkmm* gw = viewer.setup_viewer_in_gtkmm_window(width, height); // All Gtk apps need a toplevel window // // We'll also set the title, add our widget created by the viewer and make sure // it's visible Gtk::Window window(Gtk::WINDOW_TOPLEVEL); window.set_title("osgviewerGtkmm"); window.add( *gw ); window.show_all(); // Now, we'll call run on the viewer AFTER we have the graphics window inside a // top-level window viewer.run(); // This is boilerplate for all gtkmm apps... start the gtkmm main loop Gtk::Main::run(window); // If we got here, gtkmm exited it's main loop, so we'll exit cleanly return 0; }