From 670c7967ae2cda648172da45288b11c2c5844626 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 13 Mar 2008 16:22:07 +0000 Subject: [PATCH] From Paul Melis, "Here is an updated osgviewerWX example to bring it more in line with the other GUI toolkit examples. It now takes a model file as command-line argument (complaining if there isn't one), and its startup window size is now actually applied (it used to be too small). I tested this with a unicode-build of wxWidgets, as that is the recommended build type on Linux with GTK. I'm pretty sure this version of the example will work for the ANSI build as well, but I have no way of testing." --- examples/osgviewerWX/osgviewerWX.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/examples/osgviewerWX/osgviewerWX.cpp b/examples/osgviewerWX/osgviewerWX.cpp index a2416829c..98f37e26a 100644 --- a/examples/osgviewerWX/osgviewerWX.cpp +++ b/examples/osgviewerWX/osgviewerWX.cpp @@ -21,17 +21,23 @@ // `Main program' equivalent, creating windows and returning main app frame bool wxOsgApp::OnInit() { - // Create the main frame window - MainFrame *frame = new MainFrame(NULL, wxT("wxWidgets OSG Sample"), - wxDefaultPosition, wxDefaultSize); - - // create osg canvas - // - initialize - + if (argc<2) + { + std::cout << wxString(argv[0]).mb_str() <<": requires filename argument." << std::endl; + return false; + } int width = 800; int height = 600; + // Create the main frame window + + MainFrame *frame = new MainFrame(NULL, wxT("wxWidgets OSG Sample"), + wxDefaultPosition, wxSize(width, height)); + + // create osg canvas + // - initialize + int *attributes = new int[6]; attributes[0] = int(WX_GL_DOUBLEBUFFER); attributes[1] = WX_GL_RGBA; @@ -42,7 +48,7 @@ bool wxOsgApp::OnInit() GraphicsWindowWX* gw = new GraphicsWindowWX(frame, wxID_ANY, wxDefaultPosition, wxSize(width, height), wxSUNKEN_BORDER, wxT("osgviewerWX"), attributes); - + osgViewer::Viewer *viewer = new osgViewer::Viewer; viewer->getCamera()->setGraphicsContext(gw); viewer->getCamera()->setViewport(0,0,width,height); @@ -50,9 +56,11 @@ bool wxOsgApp::OnInit() viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded); // load the scene. - osg::ref_ptr loadedModel = osgDB::readNodeFile("cow.osg"); + wxString fname(argv[1]); + osg::ref_ptr loadedModel = osgDB::readNodeFile(std::string(fname.mb_str())); if (!loadedModel) { + std::cout << argv[0] <<": No data loaded." << std::endl; return false; }