MainWindow::MainWindow() : QMainWindow() { _scene.reset(); if (!QGLFormat::hasOpenGL()) { QMessageBox::critical(this, "No OpenGL Support", "This system does not appear to support OpenGL.\n\n" "The Tungsten scene editor requires OpenGL " "to work properly. The editor will now terminate.\n\n" "Please install any available updates for your graphics card driver and try again"); std::exit(0); } QGLFormat qglFormat; qglFormat.setVersion(3, 2); qglFormat.setProfile(QGLFormat::CoreProfile); qglFormat.setAlpha(true); qglFormat.setSampleBuffers(true); qglFormat.setSamples(16); _windowSplit = new QSplitter(this); _stackWidget = new QStackedWidget(_windowSplit); _renderWindow = new RenderWindow(_stackWidget, this); _previewWindow = new PreviewWindow(_stackWidget, this, qglFormat); _propertyWindow = new PropertyWindow(_windowSplit, this); _stackWidget->addWidget(_renderWindow); _stackWidget->addWidget(_previewWindow); _windowSplit->addWidget(_stackWidget); _windowSplit->addWidget(_propertyWindow); _windowSplit->setStretchFactor(0, 1); _windowSplit->setStretchFactor(1, 0); setCentralWidget(_windowSplit); _previewWindow->addStatusWidgets(statusBar()); _renderWindow->addStatusWidgets(statusBar()); connect(this, SIGNAL(sceneChanged()), _previewWindow, SLOT(sceneChanged())); connect(this, SIGNAL(sceneChanged()), _renderWindow, SLOT(sceneChanged())); connect(this, SIGNAL(sceneChanged()), _propertyWindow, SLOT(sceneChanged())); connect( _previewWindow, SIGNAL(primitiveListChanged()), _propertyWindow, SLOT(primitiveListChanged())); connect( _previewWindow, SIGNAL(selectionChanged()), _propertyWindow, SLOT(changeSelection())); connect(_propertyWindow, SIGNAL(selectionChanged()), _previewWindow, SLOT(changeSelection())); showPreview(true); QMenu *fileMenu = new QMenu("&File"); fileMenu->addAction("New", this, SLOT(newScene()), QKeySequence("Ctrl+N")); fileMenu->addAction("Open File...", this, SLOT(openScene()), QKeySequence("Ctrl+O")); fileMenu->addAction("Reload File...", this, SLOT(reloadScene()), QKeySequence("Shift+R")); fileMenu->addSeparator(); fileMenu->addAction("Close", this, SLOT(closeScene()), QKeySequence("Ctrl+W")); fileMenu->addSeparator(); fileMenu->addAction("Save", this, SLOT(saveScene()), QKeySequence("Ctrl+S")); fileMenu->addAction("Save as...", this, SLOT(saveSceneAs()), QKeySequence("Ctrl+Shift+S")); fileMenu->addSeparator(); fileMenu->addAction("Exit", this, SLOT(close())); QMenuBar *menuBar = new QMenuBar(); menuBar->addMenu(fileMenu); setMenuBar(menuBar); newScene(); }
void GlobePlugin::run() { if ( mViewerWidget == 0 ) { QSettings settings; #ifdef QGISDEBUG if ( !getenv( "OSGNOTIFYLEVEL" ) ) osgEarth::setNotifyLevel( osg::DEBUG_INFO ); #endif mOsgViewer = new osgViewer::Viewer(); // install the programmable manipulator. osgEarth::Util::EarthManipulator* manip = new osgEarth::Util::EarthManipulator(); mOsgViewer->setCameraManipulator( manip ); mIsGlobeRunning = true; setupProxy(); if ( getenv( "GLOBE_MAPXML" ) ) { char* mapxml = getenv( "GLOBE_MAPXML" ); QgsDebugMsg( mapxml ); osg::Node* node = osgDB::readNodeFile( mapxml ); if ( !node ) { QgsDebugMsg( "Failed to load earth file " ); return; } mMapNode = MapNode::findMapNode( node ); mRootNode = new osg::Group(); mRootNode->addChild( node ); } else { setupMap(); } // Initialize the sky node if required setSkyParameters( settings.value( "/Plugin-Globe/skyEnabled", false ).toBool() , settings.value( "/Plugin-Globe/skyDateTime", QDateTime() ).toDateTime() , settings.value( "/Plugin-Globe/skyAutoAmbient", false ).toBool() ); // create a surface to house the controls #if OSGEARTH_VERSION_GREATER_OR_EQUAL( 2, 1, 1 ) mControlCanvas = ControlCanvas::get( mOsgViewer ); #else mControlCanvas = new ControlCanvas( mOsgViewer ); #endif mRootNode->addChild( mControlCanvas ); mOsgViewer->setSceneData( mRootNode ); mOsgViewer->setThreadingModel( osgViewer::Viewer::SingleThreaded ); mOsgViewer->addEventHandler( new osgViewer::StatsHandler() ); mOsgViewer->addEventHandler( new osgViewer::WindowSizeHandler() ); mOsgViewer->addEventHandler( new osgViewer::ThreadingHandler() ); mOsgViewer->addEventHandler( new osgViewer::LODScaleHandler() ); mOsgViewer->addEventHandler( new osgGA::StateSetManipulator( mOsgViewer->getCamera()->getOrCreateStateSet() ) ); #if OSGEARTH_VERSION_LESS_THAN( 2, 2, 0 ) // add a handler that will automatically calculate good clipping planes mOsgViewer->addEventHandler( new osgEarth::Util::AutoClipPlaneHandler() ); #else mOsgViewer->getCamera()->addCullCallback( new AutoClipPlaneCullCallback( mMapNode ) ); #endif // osgEarth benefits from pre-compilation of GL objects in the pager. In newer versions of // OSG, this activates OSG's IncrementalCompileOpeartion in order to avoid frame breaks. mOsgViewer->getDatabasePager()->setDoPreCompile( true ); #ifdef GLOBE_OSG_STANDALONE_VIEWER mOsgViewer->run(); #endif mViewerWidget = new osgEarth::QtGui::ViewerWidget( mOsgViewer ); mViewerWidget->setGeometry( 100, 100, 1024, 800 ); mViewerWidget->show(); if ( settings.value( "/Plugin-Globe/anti-aliasing", true ).toBool() ) { QGLFormat glf = QGLFormat::defaultFormat(); glf.setSampleBuffers( true ); bool aaLevelIsInt; int aaLevel; QString aaLevelStr = settings.value( "/Plugin-Globe/anti-aliasing-level", "" ).toString(); aaLevel = aaLevelStr.toInt( &aaLevelIsInt ); if ( aaLevelIsInt ) { glf.setSamples( aaLevel ); } mViewerWidget->setFormat( glf ); } // Set a home viewpoint manip->setHomeViewpoint( osgEarth::Util::Viewpoint( osg::Vec3d( -90, 0, 0 ), 0.0, -90.0, 2e7 ), 1.0 ); setupControls(); // add our handlers mOsgViewer->addEventHandler( new FlyToExtentHandler( this ) ); mOsgViewer->addEventHandler( new KeyboardControlHandler( manip ) ); #ifndef HAVE_OSGEARTH_ELEVATION_QUERY mOsgViewer->addEventHandler( new QueryCoordinatesHandler( this, mElevationManager, mMapNode->getMap()->getProfile()->getSRS() ) ); #endif } else { mViewerWidget->show(); } }
void *QGLContext::chooseVisual() { static int bufDepths[] = { 8, 4, 2, 1 }; // Try 16, 12 also? //todo: if pixmap, also make sure that vi->depth == pixmap->depth void* vis = 0; int i = 0; bool fail = FALSE; QGLFormat fmt = format(); bool tryDouble = !fmt.doubleBuffer(); // Some GL impl's only have double bool triedDouble = FALSE; while( !fail && !( vis = tryVisual( fmt, bufDepths[i] ) ) ) { if ( !fmt.rgba() && bufDepths[i] > 1 ) { i++; continue; } if ( tryDouble ) { fmt.setDoubleBuffer( TRUE ); tryDouble = FALSE; triedDouble = TRUE; continue; } else if ( triedDouble ) { fmt.setDoubleBuffer( FALSE ); triedDouble = FALSE; } if ( fmt.stereo() ) { fmt.setStereo( FALSE ); continue; } if ( fmt.accum() ) { fmt.setAccum( FALSE ); continue; } if ( fmt.stencil() ) { fmt.setStencil( FALSE ); continue; } if ( fmt.alpha() ) { fmt.setAlpha( FALSE ); continue; } if ( fmt.depth() ) { fmt.setDepth( FALSE ); continue; } if ( fmt.doubleBuffer() ) { fmt.setDoubleBuffer( FALSE ); continue; } fail = TRUE; } glFormat = fmt; return vis; }
int qttextlabeltest(int argc, char *argv[]) { // Set up the default format for our GL contexts. QGLFormat defaultFormat = QGLFormat::defaultFormat(); defaultFormat.setSampleBuffers(true); QGLFormat::setDefaultFormat(defaultFormat); // Create and show widget QApplication app(argc, argv); GLWidget widget; widget.setGeometry(10, 10, 500, 500); widget.show(); // Create scene GeometryNode *geometry = new GeometryNode; widget.renderer().scene().rootNode().addChild(geometry); // Add a small sphere at the origin for reference: SphereGeometry *spheres = new SphereGeometry; spheres->addSphere(Vector3f::Zero(), Vector3ub(128, 128, 128), 0.1f); geometry->addDrawable(spheres); // Default text property: TextProperties tprop; // Test alignment: TextLabel3D *l3 = NULL; TextLabel2D *l2 = NULL; // 3D: tprop.setColorRgb(255, 0, 0); tprop.setAlign(TextProperties::HLeft, TextProperties::VTop); l3 = new TextLabel3D; l3->setText("Upper Left Anchor"); l3->setAnchor(Vector3f::Zero()); l3->setTextProperties(tprop); geometry->addDrawable(l3); tprop.setColorRgb(0, 255, 0); tprop.setAlign(TextProperties::HLeft, TextProperties::VBottom); l3 = new TextLabel3D; l3->setText("Bottom Left Anchor"); l3->setAnchor(Vector3f::Zero()); l3->setTextProperties(tprop); geometry->addDrawable(l3); tprop.setColorRgb(0, 0, 255); tprop.setAlign(TextProperties::HRight, TextProperties::VTop); l3 = new TextLabel3D; l3->setText("Upper Right Anchor"); l3->setAnchor(Vector3f::Zero()); l3->setTextProperties(tprop); geometry->addDrawable(l3); tprop.setColorRgb(255, 255, 0); tprop.setAlign(TextProperties::HRight, TextProperties::VBottom); l3 = new TextLabel3D; l3->setText("Bottom Right Anchor"); l3->setAnchor(Vector3f::Zero()); l3->setTextProperties(tprop); geometry->addDrawable(l3); tprop.setColorRgba(255, 255, 255, 220); tprop.setRotationDegreesCW(90.f); tprop.setAlign(TextProperties::HCenter, TextProperties::VCenter); l3 = new TextLabel3D; l3->setText("Centered Anchor (3D)"); l3->setAnchor(Vector3f::Zero()); l3->setTextProperties(tprop); l3->setRenderPass(Avogadro::Rendering::TranslucentPass); geometry->addDrawable(l3); tprop.setRotationDegreesCW(0.f); tprop.setAlpha(255); // 2D: tprop.setColorRgb(255, 0, 0); tprop.setAlign(TextProperties::HLeft, TextProperties::VTop); l2 = new TextLabel2D; l2->setText("Upper Left Corner"); l2->setAnchor(Vector2i(0, widget.height())); l2->setTextProperties(tprop); geometry->addDrawable(l2); tprop.setColorRgb(0, 255, 0); tprop.setAlign(TextProperties::HLeft, TextProperties::VBottom); l2 = new TextLabel2D; l2->setText("Bottom Left Corner"); l2->setAnchor(Vector2i(0, 0)); l2->setTextProperties(tprop); geometry->addDrawable(l2); tprop.setColorRgb(0, 0, 255); tprop.setAlign(TextProperties::HRight, TextProperties::VTop); l2 = new TextLabel2D; l2->setText("Upper Right Corner"); l2->setAnchor(Vector2i(widget.width(), widget.height())); l2->setTextProperties(tprop); geometry->addDrawable(l2); tprop.setColorRgb(255, 255, 0); tprop.setAlign(TextProperties::HRight, TextProperties::VBottom); l2 = new TextLabel2D; l2->setText("Bottom Right Corner"); l2->setAnchor(Vector2i(widget.width(), 0)); l2->setTextProperties(tprop); geometry->addDrawable(l2); tprop.setColorRgba(255, 255, 255, 220); tprop.setAlign(TextProperties::HCenter, TextProperties::VCenter); l2 = new TextLabel2D; l2->setText("Centered Anchor (2D)"); l2->setAnchor(Vector2i(widget.width() / 2, widget.height() / 2)); l2->setTextProperties(tprop); geometry->addDrawable(l2); // Test the TextLabel3D's radius feature: spheres->addSphere(Vector3f(0.f, 6.f, 0.f), Vector3ub(255, 255, 255), 1.f); tprop.setColorRgba(255, 128, 64, 255); tprop.setRotationDegreesCW(90.f); l3 = new TextLabel3D; l3->setText("Clipped"); l3->setAnchor(Vector3f(0.f, 6.f, 0.f)); l3->setTextProperties(tprop); geometry->addDrawable(l3); tprop.setColorRgba(64, 128, 255, 255); tprop.setRotationDegreesCW(45.f); l3 = new TextLabel3D; l3->setText("Projected"); l3->setAnchor(Vector3f(0.f, 6.f, 0.f)); l3->setTextProperties(tprop); l3->setRadius(1.f); geometry->addDrawable(l3); // Make sure the widget renders the scene, and store it in a QImage. widget.raise(); widget.repaint(); // Run the application for a while, and then quit so we can save an image. QTimer timer; timer.setSingleShot(true); app.connect(&timer, SIGNAL(timeout()), SLOT(quit())); timer.start(200); app.exec(); // Grab the frame buffer of the GLWidget and save it to a QImage. QImage image = widget.grabFrameBuffer(false); // Set up the image regression test. ImageRegressionTest test(argc, argv); // Do the image threshold test, printing output to the std::cout for ctest. return test.imageThresholdTest(image, std::cout); }
QGLFormat OGLplusExampleGLWidget::getGLFormat(void) { QGLFormat result; result.setVersion(3, 3); return result; }
int main(int argc, char *argv[]) { // int res[8][8]; // for(int base = 0; base < 8; ++base) { // for(int rot = 0; rot < 8; ++rot) { // int x = rotationAdd(base, rot); // int e = rotationSub(x, rot); // // printf("%d + %d = %d -> %d\n", base, rot, x, e); // // res[rot][x] = base; // } // printf("\n"); // } // // // for(int x = 0; x < 8; ++x) { // // for(int rot = 0; rot < 8; ++rot) { // // int e = rotationSub(x, rot); // // printf("%d - %d = %d : %d\n", rot, x, res[x][rot], e); // // } // // printf("\n"); // // } // // return 0; console(); mainQuadObj(); return 0; //PicBucket::buildAllMeshes(); //return 1; QApplication app(argc, argv); QIcon appicon(":/images/HappySolver64f.png"); appicon.addFile(":/images/HappySolver32f.png"); appicon.addFile(":/images/HappySolver16f.png"); app.setWindowIcon(appicon); g_format.setSampleBuffers(true); // TBD - do better PicBucket::createSingleton(); MainWindow window; window.setWindowIcon(appicon); g_main = &window; // do the icon as fast as possible. flushAllEvents(); if (!window.initialize()) return 0; // window could have been closed during initlization. test it. if (window.wasClosed()) return 0; QString filename; for (int i = 1; i < argc; ++i) { cout << "arg " << i << argv[i] << endl; if (argv[i][0] != '-') { filename = argv[i]; break; } } if (!filename.isEmpty()) { cout << "Opening file " << filename.toLatin1().data() << endl; window.loadStartupFile(filename); } return app.exec(); }
static void qt_format_to_attrib_list(const QGLFormat &f, int attribs[]) { int i = 0; attribs[i++] = GLX_RENDER_TYPE; attribs[i++] = GLX_RGBA_BIT; attribs[i++] = GLX_DRAWABLE_TYPE; attribs[i++] = GLX_PBUFFER_BIT; attribs[i++] = GLX_RED_SIZE; attribs[i++] = f.redBufferSize() == -1 ? 1 : f.redBufferSize(); attribs[i++] = GLX_GREEN_SIZE; attribs[i++] = f.greenBufferSize() == -1 ? 1 : f.greenBufferSize(); attribs[i++] = GLX_BLUE_SIZE; attribs[i++] = f.blueBufferSize() == -1 ? 1 : f.blueBufferSize(); if (f.doubleBuffer()) { attribs[i++] = GLX_DOUBLEBUFFER; attribs[i++] = true; } if (f.depth()) { attribs[i++] = GLX_DEPTH_SIZE; attribs[i++] = f.depthBufferSize() == -1 ? 1 : f.depthBufferSize(); } if (f.stereo()) { attribs[i++] = GLX_STEREO; attribs[i++] = true; } if (f.stencil()) { attribs[i++] = GLX_STENCIL_SIZE; attribs[i++] = f.stencilBufferSize() == -1 ? 1 : f.stencilBufferSize(); } if (f.alpha()) { attribs[i++] = GLX_ALPHA_SIZE; attribs[i++] = f.alphaBufferSize() == -1 ? 1 : f.alphaBufferSize(); } if (f.accum()) { attribs[i++] = GLX_ACCUM_RED_SIZE; attribs[i++] = f.accumBufferSize() == -1 ? 1 : f.accumBufferSize(); attribs[i++] = GLX_ACCUM_GREEN_SIZE; attribs[i++] = f.accumBufferSize() == -1 ? 1 : f.accumBufferSize(); attribs[i++] = GLX_ACCUM_BLUE_SIZE; attribs[i++] = f.accumBufferSize() == -1 ? 1 : f.accumBufferSize(); if (f.alpha()) { attribs[i++] = GLX_ACCUM_ALPHA_SIZE; attribs[i++] = f.accumBufferSize() == -1 ? 1 : f.accumBufferSize(); } } if (f.sampleBuffers()) { attribs[i++] = GLX_SAMPLE_BUFFERS_ARB; attribs[i++] = 1; attribs[i++] = GLX_SAMPLES_ARB; attribs[i++] = f.samples() == -1 ? 4 : f.samples(); } attribs[i] = XNone; }
int main(int argc,char* argv[]) { qRegisterMetaType<medDataIndex>("medDataIndex"); // this needs to be done before creating the QApplication object, as per the // Qt doc, otherwise there are some edge cases where the style is not fully applied QApplication::setStyle("plastique"); medApplication application(argc,argv); medSplashScreen splash(QPixmap(":/pixmaps/medInria-splash.png")); setlocale(LC_NUMERIC, "C"); if (dtkApplicationArgumentsContain(&application, "-h") || dtkApplicationArgumentsContain(&application, "--help")) { qDebug() << "Usage: medInria [--fullscreen|--no-fullscreen] [--stereo] " #ifdef ACTIVATE_WALL_OPTION "[--wall] [--tracker=URL] " #endif "[--view] [files]]"; return 1; } // Do not show the splash screen in debug builds because it hogs the // foreground, hiding all other windows. This makes debugging the startup // operations difficult. #if !defined(_DEBUG) bool show_splash = true; #else bool show_splash = false; #endif medSettingsManager* mnger = medSettingsManager::instance(); QStringList posargs; for (int i=1;i<application.argc();++i) { const QString arg = application.argv()[i]; if (arg.startsWith("--")) { bool valid_option = false; const QStringList options = (QStringList() << "--fullscreen" << "--no-fullscreen" << "--wall" << "--tracker" << "--stereo" << "--view"); for (QStringList::const_iterator opt=options.constBegin();opt!=options.constEnd();++opt) if (arg.startsWith(*opt)) valid_option = true; if (!valid_option) { qDebug() << "Ignoring unknown option " << arg; } continue; } posargs.append(arg); } const bool DirectView = dtkApplicationArgumentsContain(&application,"--view") || posargs.size()!=0; int runningMedInria = 0; if (DirectView) { show_splash = false; for (QStringList::const_iterator i=posargs.constBegin();i!=posargs.constEnd();++i) { const QString& message = QString("/open ")+*i; runningMedInria = application.sendMessage(message); } } else { runningMedInria = application.sendMessage(""); } if (runningMedInria) return 0; if (show_splash) { QObject::connect(medDatabaseController::instance().data(), SIGNAL(copyMessage(QString,int,QColor)), &splash,SLOT(showMessage(QString,int, QColor))); application.setMsgColor(Qt::white); application.setMsgAlignment(Qt::AlignLeft|Qt::AlignBottom); QObject::connect(medPluginManager::instance(),SIGNAL(loadError(const QString&)), &application,SLOT(redirectMessageToSplash(const QString&)) ); QObject::connect(medPluginManager::instance(),SIGNAL(loaded(QString)), &application,SLOT(redirectMessageToSplash(QString)) ); QObject::connect(&application,SIGNAL(showMessage(const QString&, int, const QColor&)), &splash,SLOT(showMessage(const QString&, int, const QColor&)) ); splash.show(); splash.showMessage("Loading plugins...",Qt::AlignLeft|Qt::AlignBottom,Qt::white); } // DATABASE INITIALISATION. // First compare the current with the new data location QString currentLocation = medStorage::dataLocation(); // If the user configured a new location for the database in the settings editor, we'll need to move it QString newLocation = mnger->value("medDatabaseSettingsWidget", "new_database_location").toString(); if (!newLocation.isEmpty()) { // If the locations are different we need to move the db to the new location if (currentLocation.compare(newLocation)!=0) { if (!medDatabaseController::instance()->moveDatabase(newLocation)) { qDebug() << "Failed to move the database from " << currentLocation << " to " << newLocation; // The new location is invalid so set it to zero newLocation = ""; } mnger->setValue("medDatabaseSettingsWidget", "actual_database_location",newLocation); // We need to reset the new Location to prevent doing it all the time mnger->setValue("medDatabaseSettingsWidget", "new_database_location",""); } } // END OF DATABASE INITIALISATION medPluginManager::instance()->initialize(); //Use Qt::WA_DeleteOnClose attribute to be sure to always have only one closeEvent. medMainWindow *mainwindow = new medMainWindow; mainwindow->setAttribute(Qt::WA_DeleteOnClose, true); if (DirectView) mainwindow->setStartup(medMainWindow::WorkSpace,posargs); bool fullScreen = medSettingsManager::instance()->value("startup", "fullscreen", false).toBool(); const bool hasFullScreenArg = application.arguments().contains("--fullscreen"); const bool hasNoFullScreenArg = application.arguments().contains("--no-fullscreen"); const bool hasWallArg = application.arguments().contains("--wall"); const int conflict = static_cast<int>(hasFullScreenArg)+static_cast<int>(hasNoFullScreenArg)+ static_cast<int>(hasWallArg); if (conflict>1) dtkWarn() << "Conflicting command line parameters between --fullscreen, --no-fullscreen and -wall. Ignoring."; else { if (hasWallArg) { mainwindow->setWallScreen(true); fullScreen = false; } if (hasFullScreenArg) fullScreen = true; if (hasNoFullScreenArg) fullScreen = false; } mainwindow->setFullScreen(fullScreen); if(application.arguments().contains("--stereo")) { QGLFormat format; format.setAlpha(true); format.setDoubleBuffer(true); format.setStereo(true); format.setDirectRendering(true); QGLFormat::setDefaultFormat(format); } if (show_splash) splash.finish(mainwindow); if (medPluginManager::instance()->plugins().isEmpty()) { QMessageBox::warning(mainwindow, QObject::tr("No plugin loaded"), QObject::tr("Warning : no plugin loaded successfully.")); } application.setActivationWindow(mainwindow); application.setMainWindow(mainwindow); forceShow(*mainwindow); // Start main loop. const int status = application.exec(); medPluginManager::instance()->uninitialize(); return status; }