int main(int argc, char *argv[]) { QGuiApplication a(argc,argv); Window w; QSurfaceFormat f = w.requestedFormat(); f.setMajorVersion(3); f.setMinorVersion(3); w.setFormat(f); w.setWidth(640); w.setHeight(480); w.show(); return a.exec(); }
int main(int argc, char **argv) { QGuiApplication app(argc, argv); // create an OpenGL format specifier QSurfaceFormat format; // set the number of samples for multisampling // will need to enable glEnable(GL_MULTISAMPLE); once we have a context format.setSamples(4); #if defined( __APPLE__) // at present mac osx Mountain Lion only supports GL3.2 // the new mavericks will have GL 4.x so can change format.setMajorVersion(4); format.setMinorVersion(1); #else // with luck we have the latest GL version so set to this format.setMajorVersion(4); format.setMinorVersion(5); #endif // now we are going to set to CoreProfile OpenGL so we can't use and old Immediate mode GL format.setProfile(QSurfaceFormat::CoreProfile); // now set the depth buffer to 24 bits format.setDepthBufferSize(24); // set this as the default format for all windows QSurfaceFormat::setDefaultFormat(format); // now we are going to create our scene window NGLScene window; // we can now query the version to see if it worked std::cout<<"Profile is "<<format.majorVersion()<<" "<<format.minorVersion()<<"\n"; // set the window size window.resize(1024, 720); // and finally show window.show(); return app.exec(); }
yage::GLWindow::GLWindow(QScreen *screen) : QWindow(screen) , m_context(0) { // Tell Qt we will use OpenGL for this window setSurfaceType( OpenGLSurface ); QSurfaceFormat format; format.setDepthBufferSize( 24 ); format.setMajorVersion( 3 ); format.setMinorVersion( 2 ); format.setSamples( 4 ); format.setProfile( QSurfaceFormat::CoreProfile ); setFormat( format ); }
int main(int argc, char *argv[]) { QSurfaceFormat format; format.setMajorVersion( 4 ); format.setMinorVersion( 1 ); format.setProfile( QSurfaceFormat::CoreProfile ); QSurfaceFormat::setDefaultFormat(format); QApplication a(argc, argv); MainWindow m; m.show(); return a.exec(); }
/** * @brief Constructeur paramétré * * Permet d'initialiser la fenêtre et les propriétés de la zone de rendu OpenGL * * @param screen Propriétés de l'écran */ Window::Window(QScreen *screen) : QWindow(screen), m_scene(new MovingColoredTriangle(this)) { // On définit le type de la zone de rendu, dans notre cas il // s'agit d'une zone OpenGL setSurfaceType(QSurface::OpenGLSurface); // Puis on définit les propriétés de la zone de rendu QSurfaceFormat format; format.setDepthBufferSize(24); format.setMajorVersion(4); format.setMinorVersion(3); format.setSamples(4); // Multisampling x4 format.setProfile(QSurfaceFormat::CoreProfile); // Fonctions obsolètes d'OpenGL non disponibles format.setOption(QSurfaceFormat::DebugContext); // On applique le format et on créer la fenêtre setFormat(format); create(); resize(800, 600); setTitle("OpenGLSBExamplesQt - MovingColoredTriangle"); // On créer le contexte OpenGL et on définit son format m_context = new QOpenGLContext; m_context->setFormat(format); m_context->create(); m_context->makeCurrent(this); // On définit le contexte OpenGL de la scène m_scene->setContext(m_context); m_timer.start(); initializeGL(); connect(this, SIGNAL(widthChanged(int)), this, SLOT(resizeGL())); connect(this, SIGNAL(heightChanged(int)), this, SLOT(resizeGL())); resizeGL(); // Création d'un timer permettant la mise à jour de la zone de rendu 60 fois par seconde QTimer* timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(updateScene())); timer->start(16); // f = 1 / 16.10e-3 = 60Hz }
void tst_QSurfaceFormat::versionCheck() { QFETCH( int, formatMajor ); QFETCH( int, formatMinor ); QFETCH( int, compareMajor ); QFETCH( int, compareMinor ); QFETCH( bool, expected ); QSurfaceFormat format; format.setMinorVersion(formatMinor); format.setMajorVersion(formatMajor); QCOMPARE(format.version() >= qMakePair(compareMajor, compareMinor), expected); format.setVersion(formatMajor, formatMinor); QCOMPARE(format.version() >= qMakePair(compareMajor, compareMinor), expected); }
MyWindow::MyWindow() : currentTimeMs(0), currentTimeS(0) { mProgram = 0; setSurfaceType(QWindow::OpenGLSurface); setFlags(Qt::Window | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint); QSurfaceFormat format; format.setDepthBufferSize(24); format.setMajorVersion(4); format.setMinorVersion(3); format.setSamples(4); format.setProfile(QSurfaceFormat::CoreProfile); setFormat(format); create(); resize(800, 600); mContext = new QOpenGLContext(this); mContext->setFormat(format); mContext->create(); mContext->makeCurrent( this ); mFuncs = mContext->versionFunctions<QOpenGLFunctions_4_3_Core>(); if ( !mFuncs ) { qWarning( "Could not obtain OpenGL versions object" ); exit( 1 ); } if (mFuncs->initializeOpenGLFunctions() == GL_FALSE) { qWarning( "Could not initialize core open GL functions" ); exit( 1 ); } initializeOpenGLFunctions(); QTimer *repaintTimer = new QTimer(this); connect(repaintTimer, &QTimer::timeout, this, &MyWindow::render); repaintTimer->start(1000/60); QTimer *elapsedTimer = new QTimer(this); connect(elapsedTimer, &QTimer::timeout, this, &MyWindow::modCurTime); elapsedTimer->start(1); }
int main(int argc, char *argv[]) { OVR::System::Init(); qmlRegisterType<FileIO>("FileIO", 1, 0, "FileIO"); qmlRegisterType<StereoViewport>("StereoViewport", 1, 0, "StereoViewport"); qmlRegisterType<OculusReader>("OculusReader", 1, 0, "OculusReader"); qmlRegisterType<FrameRateCounter>("OculusReader", 1, 0, "FrameRateCounter"); qmlRegisterType<MDStateManager>("MDStateManager", 1, 0, "MDStateManager"); qmlRegisterType<Settings>("Settings", 1, 0, "Settings"); qmlRegisterType<ScreenInfo>("ScreenInfo", 1, 0, "ScreenInfo"); qmlRegisterType<ScreenInfoScreen>("ScreenInfo", 1, 0, "ScreenInfoScreen"); qmlRegisterType<MultiBillboard>("CompPhys.MultiBillboard", 1, 0, "MultiBillboard"); qmlRegisterType<DataSource>("CompPhys.MultiBillboard", 1, 0, "DataSource"); qmlRegisterType<MouseMover>("CompPhys.FlyModeNavigator", 1, 0, "MouseMover"); QGuiApplication app(argc, argv); QSurfaceFormat format; format.setMajorVersion(4); format.setMinorVersion(3); OculusView view; view.setFormat(format); #ifdef Q_OS_MACX view.addImportPath("."); #else view.addImportPath("../libs"); #endif #ifdef Q_OS_LINUX // view.engine()->addImportPath("/home/compphys/sandbox/flymodenavigator-qt3d/build-flymodenavigator-Desktop_Qt_5_2_0_GCC_64bit-Release/src/libs"); #else // view.engine()->addImportPath("/repos/flymodenavigator-qt3d/build-flymodenavigator-Desktop_Qt_5_2_0_clang_64bit-Release/src/libs"); #endif view.setMainQmlFile("../qml/oculus/main.qml"); // view.fullScreenAllMonitors(); view.show(); setlocale (LC_ALL, "en_US.UTF8"); return app.exec(); }
int main( int argc, char* argv[] ) { QGuiApplication a( argc, argv ); // Specify the format we wish to use QSurfaceFormat format; format.setMajorVersion( 4 ); #if !defined(Q_OS_MAC) format.setMinorVersion( 0 ); #else format.setMinorVersion( 0 ); #endif format.setDepthBufferSize( 24 ); format.setSamples( 4 ); format.setProfile( QSurfaceFormat::CoreProfile ); Window w( format ); w.setScene( new TerrainTessellationScene ); w.show(); return a.exec(); }
OpenGLWindow::OpenGLWindow(QWindow *parent) : QWindow(parent) , m_update_pending(false) , m_animating(false) , m_context(0) , m_device(0) , m_frames(0) , m_fps(0) { setSurfaceType(QWindow::OpenGLSurface); QSurfaceFormat format; format.setSamples(4); // multi-sampling format.setRenderableType(QSurfaceFormat::OpenGL); // change to opengles on mobile format.setProfile(QSurfaceFormat::CompatibilityProfile); format.setMajorVersion(3); format.setMinorVersion(2); format.setDepthBufferSize(24); setFormat(format); // Hide the cursor since this is a fullscreen app setCursor(Qt::BlankCursor); }
window::window(init_fn_type const& init_fn, step_fn_type const& step_fn, draw_fn_type const& draw_fn, fini_fn_type const& fini_fn) : m_context(nullptr) , m_gl_logger(nullptr) , m_initialised(false) , m_finished(false) , m_init_fn(init_fn) , m_step_fn(step_fn) , m_draw_fn(draw_fn) , m_fini_fn(fini_fn) { QSurfaceFormat format; // format.setDepthBufferSize(16); format.setDepthBufferSize( 24 ); format.setMajorVersion(4U); format.setMinorVersion(2U); format.setProfile(QSurfaceFormat::CoreProfile); format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); format.setOption(QSurfaceFormat::DebugContext); format.setSwapInterval(0); format.setSamples(0); m_context = new QOpenGLContext(this); m_context->setFormat(format); m_context->create(); setSurfaceType(QWindow::OpenGLSurface); setFlags(Qt::Window | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint); //setGeometry(QRect(10, 10, 640, 480)); setFormat(format); create(); }
/*! Returns a window format for the OpenGL format specified by \a format. */ QSurfaceFormat QGLFormat::toSurfaceFormat(const QGLFormat &format) { QSurfaceFormat retFormat; if (format.alpha()) retFormat.setAlphaBufferSize(format.alphaBufferSize() == -1 ? 1 : format.alphaBufferSize()); if (format.blueBufferSize() >= 0) retFormat.setBlueBufferSize(format.blueBufferSize()); if (format.greenBufferSize() >= 0) retFormat.setGreenBufferSize(format.greenBufferSize()); if (format.redBufferSize() >= 0) retFormat.setRedBufferSize(format.redBufferSize()); if (format.depth()) retFormat.setDepthBufferSize(format.depthBufferSize() == -1 ? 1 : format.depthBufferSize()); retFormat.setSwapBehavior(format.doubleBuffer() ? QSurfaceFormat::DoubleBuffer : QSurfaceFormat::DefaultSwapBehavior); if (format.sampleBuffers()) retFormat.setSamples(format.samples() == -1 ? 4 : format.samples()); if (format.stencil()) retFormat.setStencilBufferSize(format.stencilBufferSize() == -1 ? 1 : format.stencilBufferSize()); retFormat.setStereo(format.stereo()); retFormat.setMajorVersion(format.majorVersion()); retFormat.setMinorVersion(format.minorVersion()); retFormat.setProfile(static_cast<QSurfaceFormat::OpenGLContextProfile>(format.profile())); return retFormat; }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QSurfaceFormat format; format.setMajorVersion(4); format.setMinorVersion(1); format.setProfile(QSurfaceFormat::CoreProfile); format.setRenderableType(QSurfaceFormat::OpenGL); format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); format.setSamples(2); format.setDepthBufferSize(24); format.setRedBufferSize(8); format.setGreenBufferSize(8); format.setBlueBufferSize(8); format.setAlphaBufferSize(0); format.setStencilBufferSize(8); QSurfaceFormat::setDefaultFormat(format); DemoGLWindow window; window.show(); return a.exec(); }
Window::Window() : QQuickView() , m_terrain(nullptr) , m_mouseDown(false) , m_speed(0.01) , m_needsUpdate(true) , m_generate(false) , m_paused(false) , m_curTimeId(0) { updateUi(); rootContext()->setContextProperty("Game", this); setSurfaceType(QWindow::OpenGLSurface); setClearBeforeRendering(false); setPersistentOpenGLContext(true); setResizeMode(QQuickView::SizeRootObjectToView); setSource(QUrl::fromLocalFile(FileFinder::findFile(FileFinder::Type::Qml, "ui.qml"))); QSurfaceFormat format = requestedFormat(); format.setProfile(QSurfaceFormat::CoreProfile); format.setMajorVersion(3); format.setMinorVersion(3); format.setDepthBufferSize(24); format.setOption(QSurfaceFormat::DebugContext); setFormat(format); resize(1024, 768); connect(this, &QQuickWindow::beforeRendering, this, &Window::renderNow, Qt::DirectConnection); connect(this, &QQuickWindow::beforeSynchronizing, this, &Window::sync, Qt::DirectConnection); connect(this, &QQuickWindow::afterRendering, this, &Window::updateUi); connect(this, &QQuickWindow::afterRendering, this, &Window::update); show(); }
int main(int argc, char *argv[]) { try { for (int n = 1; n < argc; n++) { if (strcmp(argv[n], "--licenses") == 0) { QFile licenses(":/misc/licenses.txt"); licenses.open(QIODevice::ReadOnly | QIODevice::Text); QByteArray contents = licenses.readAll(); printf("%.*s\n", (int)contents.size(), contents.data()); return 0; } } int newArgc = argc; char **newArgv = appendCommandLineArguments(&newArgc, argv); // Supress SSL related warnings on OSX // See https://bugreports.qt.io/browse/QTBUG-43173 for more info // #ifdef Q_OS_MAC qputenv("QT_LOGGING_RULES", "qt.network.ssl.warning=false"); // Request OpenGL 4.1 if possible on OSX, otherwise it defaults to 2.0 // This needs to be done before we create the QGuiApplication // QSurfaceFormat format = QSurfaceFormat::defaultFormat(); format.setMajorVersion(3); format.setMinorVersion(2); format.setProfile(QSurfaceFormat::CoreProfile); QSurfaceFormat::setDefaultFormat(format); #endif QGuiApplication app(newArgc, newArgv); initQt(&app); // init breakpad. setupCrashDumper(); UniqueApplication* uniqueApp = new UniqueApplication(); if (!uniqueApp->ensureUnique()) return EXIT_SUCCESS; #ifdef Q_OS_UNIX // install signals handlers for proper app closing. SignalManager signalManager(&app); Q_UNUSED(signalManager); #endif initLogger(); QLOG_INFO() << "Starting Plex Media Player version:" << qPrintable(Version::GetVersionString()) << "build date:" << qPrintable(Version::GetBuildDate()); QLOG_INFO() << qPrintable(QString(" Running on: %1 [%2] arch %3").arg(QSysInfo::prettyProductName()).arg(QSysInfo::kernelVersion()).arg(QSysInfo::currentCpuArchitecture())); QLOG_INFO() << " Qt Version:" << QT_VERSION_STR << qPrintable(QString("[%1]").arg(QSysInfo::buildAbi())); // Quit app and apply update if we find one. if (UpdateManager::CheckForUpdates()) { app.quit(); return 0; } #ifdef Q_OS_WIN32 initD3DDevice(); #endif #ifdef Q_OS_UNIX setlocale(LC_NUMERIC, "C"); #endif // Initialize all the components. This needs to be done // early since most everything else relies on it // ComponentManager::Get().initialize(); // enable remote inspection if we have the correct setting for it. if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "remoteInspector").toBool()) qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "0.0.0.0:9992"); QtWebEngine::initialize(); // Qt and QWebEngineProfile set the locale, which breaks parsing and // formatting float numbers in a few countries. #ifdef Q_OS_UNIX setlocale(LC_NUMERIC, "C"); #endif // start our helper HelperLauncher::Get().connectToHelper(); // load QtWebChannel so that we can register our components with it. QQmlApplicationEngine *engine = KonvergoEngine::Get(); KonvergoWindow::RegisterClass(); engine->rootContext()->setContextProperty("components", &ComponentManager::Get().getQmlPropertyMap()); // This controls how big the web view will zoom using semantic zoom // over a specific number of pixels and we run out of space for on screen // tiles in chromium. This only happens on OSX since on other platforms // we can use the GPU to transfer tiles directly but we set the limit on all platforms // to keep it consistent. // // See more discussion in: https://github.com/plexinc/plex-media-player/issues/10 // The number of pixels here are REAL pixels, the code in webview.qml will compensate // for a higher DevicePixelRatio // engine->rootContext()->setContextProperty("webMaxHeight", 1440); // the only way to detect if QML parsing fails is to hook to this signal and then see // if we get a valid object passed to it. Any error messages will be reported on stderr // but since no normal user should ever see this it should be fine // QObject::connect(engine, &QQmlApplicationEngine::objectCreated, [=](QObject* object, const QUrl& url) { Q_UNUSED(url); if (object == 0) throw FatalException(QObject::tr("Failed to parse application engine script.")); QObject* rootObject = engine->rootObjects().first(); QObject* webChannel = qvariant_cast<QObject*>(rootObject->property("webChannel")); Q_ASSERT(webChannel); ComponentManager::Get().setWebChannel(qobject_cast<QWebChannel*>(webChannel)); KonvergoWindow* window = qobject_cast<KonvergoWindow*>(rootObject); Q_ASSERT(window); QObject::connect(uniqueApp, &UniqueApplication::otherApplicationStarted, window, &KonvergoWindow::otherAppFocus); }); engine->load(QUrl(QStringLiteral("qrc:/ui/webview.qml"))); updateLogLevel(); // run our application int ret = app.exec(); delete KonvergoEngine::Get(); delete uniqueApp; return ret; } catch (FatalException& e) { QLOG_FATAL() << "Unhandled FatalException:" << qPrintable(e.message()); QGuiApplication app(argc, argv); QString text = e.message() + "<br>" + QObject::tr("Please visit Plex support forums for support."); QQmlApplicationEngine* engine = new QQmlApplicationEngine(NULL); engine->rootContext()->setContextProperty("errorTitle", QObject::tr("A critical error occurred.")); engine->rootContext()->setContextProperty("errorText", text); engine->load(QUrl(QStringLiteral("qrc:/ui/errormessage.qml"))); app.exec(); return 1; } }
Qt3DGeometryTab::Qt3DGeometryTab(PropertyWidget *parent) : QWidget(parent) , ui(new Ui::Qt3DGeometryTab) , m_surface(nullptr) , m_aspectEngine(nullptr) , m_camera(nullptr) , m_geometryRenderer(nullptr) , m_geometryTransform(nullptr) , m_cullMode(nullptr) , m_normalsRenderPass(nullptr) , m_bufferModel(new BufferModel(this)) { ui->setupUi(this); auto toolbar = new QToolBar(this); ui->topLayout->insertWidget(0, toolbar); toolbar->addAction(ui->actionViewGeometry); toolbar->addAction(ui->actionViewBuffers); toolbar->addSeparator(); toolbar->addAction(ui->actionResetCam); toolbar->addSeparator(); toolbar->addAction(ui->actionShowNormals); toolbar->addAction(ui->actionShowTangents); toolbar->addAction(ui->actionCullBack); connect(ui->actionResetCam, &QAction::triggered, this, &Qt3DGeometryTab::resetCamera); connect(ui->actionShowNormals, &QAction::toggled, this, [this]() { if (m_normalsRenderPass) m_normalsRenderPass->setEnabled(ui->actionShowNormals->isChecked()); }); connect(ui->actionCullBack, &QAction::toggled, this, [this]() { if (m_cullMode) m_cullMode->setMode(ui->actionCullBack->isChecked() ? Qt3DRender::QCullFace::Back : Qt3DRender::QCullFace::NoCulling); }); auto viewGroup = new QActionGroup(this); viewGroup->setExclusive(true); viewGroup->addAction(ui->actionViewGeometry); viewGroup->addAction(ui->actionViewBuffers); connect(viewGroup, &QActionGroup::triggered, this, [this]() { const auto geoView = ui->actionViewGeometry->isChecked(); ui->stackedWidget->setCurrentWidget(geoView ? ui->geometryPage : ui->bufferPage); ui->actionResetCam->setVisible(geoView); ui->actionShowNormals->setVisible(geoView); ui->actionShowTangents->setVisible(geoView); ui->actionCullBack->setVisible(geoView); }); ui->bufferView->setModel(m_bufferModel); connect(ui->bufferBox, QOverload<int>::of( &QComboBox::currentIndexChanged), m_bufferModel, &BufferModel::setBufferIndex); m_surface = new QWindow; m_surface->setSurfaceType(QSurface::OpenGLSurface); QSurfaceFormat format; format.setDepthBufferSize(24); format.setSamples(4); // ??? format.setStencilBufferSize(8); // ??? format.setMajorVersion(3); format.setMinorVersion(3); format.setProfile(QSurfaceFormat::CoreProfile); m_surface->setFormat(format); QSurfaceFormat::setDefaultFormat(format); m_surface->create(); ui->geometryPage->layout()->addWidget(QWidget::createWindowContainer(m_surface, this)); m_surface->installEventFilter(this); m_interface = ObjectBroker::object<Qt3DGeometryExtensionInterface *>( parent->objectBaseName() + ".qt3dGeometry"); connect(m_interface, &Qt3DGeometryExtensionInterface::geometryDataChanged, this, &Qt3DGeometryTab::updateGeometry); }
int main(int argc, char* argv[]) { // Parse command line arguments std::vector<string> input_paths, seg_paths; string output_path, landmarks_path; string model_3dmm_h5_path, model_3dmm_dat_path; string reg_model_path, reg_deploy_path, reg_mean_path; string seg_model_path, seg_deploy_path; string cfg_path; bool generic, with_expr, with_gpu; unsigned int gpu_device_id, verbose; try { options_description desc("Allowed options"); desc.add_options() ("help,h", "display the help message") ("verbose,v", value<unsigned int>(&verbose)->default_value(0), "output debug information [0, 4]") ("input,i", value<std::vector<string>>(&input_paths)->required(), "image paths [source target]") ("output,o", value<string>(&output_path)->required(), "output path") ("segmentations,s", value<std::vector<string>>(&seg_paths), "segmentation paths [source target]") ("landmarks,l", value<string>(&landmarks_path)->required(), "path to landmarks model file") ("model_3dmm_h5", value<string>(&model_3dmm_h5_path)->required(), "path to 3DMM file (.h5)") ("model_3dmm_dat", value<string>(&model_3dmm_dat_path)->required(), "path to 3DMM file (.dat)") ("reg_model,r", value<string>(®_model_path)->required(), "path to 3DMM regression CNN model file (.caffemodel)") ("reg_deploy,d", value<string>(®_deploy_path)->required(), "path to 3DMM regression CNN deploy file (.prototxt)") ("reg_mean,m", value<string>(®_mean_path)->required(), "path to 3DMM regression CNN mean file (.binaryproto)") ("seg_model", value<string>(&seg_model_path), "path to face segmentation CNN model file (.caffemodel)") ("seg_deploy", value<string>(&seg_deploy_path), "path to face segmentation CNN deploy file (.prototxt)") ("generic,g", value<bool>(&generic)->default_value(false), "use generic model without shape regression") ("expressions,e", value<bool>(&with_expr)->default_value(true), "with expressions") ("gpu", value<bool>(&with_gpu)->default_value(true), "toggle GPU / CPU") ("gpu_id", value<unsigned int>(&gpu_device_id)->default_value(0), "GPU's device id") ("cfg", value<string>(&cfg_path)->default_value("face_swap_image.cfg"), "configuration file (.cfg)") ; variables_map vm; store(command_line_parser(argc, argv).options(desc). positional(positional_options_description().add("input", -1)).run(), vm); if (vm.count("help")) { cout << "Usage: face_swap_image [options]" << endl; cout << desc << endl; exit(0); } // Read config file std::ifstream ifs(vm["cfg"].as<string>()); store(parse_config_file(ifs, desc), vm); notify(vm); if(input_paths.size() != 2) throw error("Both source and target must be specified in input!"); if (!is_regular_file(input_paths[0])) throw error("source input must be a path to an image!"); if (!is_regular_file(input_paths[1])) throw error("target input target must be a path to an image!"); if (seg_paths.size() > 0 && !is_regular_file(seg_paths[0])) throw error("source segmentation must be a path to an image!"); if (seg_paths.size() > 1 && !is_regular_file(seg_paths[1])) throw error("target segmentation must be a path to an image!"); if (!is_regular_file(landmarks_path)) throw error("landmarks must be a path to a file!"); if (!is_regular_file(model_3dmm_h5_path)) throw error("model_3dmm_h5 must be a path to a file!"); if (!is_regular_file(model_3dmm_dat_path)) throw error("model_3dmm_dat must be a path to a file!"); if (!is_regular_file(reg_model_path)) throw error("reg_model must be a path to a file!"); if (!is_regular_file(reg_deploy_path)) throw error("reg_deploy must be a path to a file!"); if (!is_regular_file(reg_mean_path)) throw error("reg_mean must be a path to a file!"); if (!seg_model_path.empty() && !is_regular_file(seg_model_path)) throw error("seg_model must be a path to a file!"); if (!seg_deploy_path.empty() && !is_regular_file(seg_deploy_path)) throw error("seg_deploy must be a path to a file!"); } catch (const error& e) { cerr << "Error while parsing command-line arguments: " << e.what() << endl; cerr << "Use --help to display a list of options." << endl; exit(1); } try { // Intialize OpenGL context QApplication a(argc, argv); QSurfaceFormat surfaceFormat; surfaceFormat.setMajorVersion(1); surfaceFormat.setMinorVersion(5); QOpenGLContext openGLContext; openGLContext.setFormat(surfaceFormat); openGLContext.create(); if (!openGLContext.isValid()) return -1; QOffscreenSurface surface; surface.setFormat(surfaceFormat); surface.create(); if (!surface.isValid()) return -2; openGLContext.makeCurrent(&surface); // Initialize GLEW GLenum err = glewInit(); if (GLEW_OK != err) { // Problem: glewInit failed, something is seriously wrong fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); throw std::runtime_error("Failed to initialize GLEW!"); } // Initialize face swap face_swap::FaceSwap fs(landmarks_path, model_3dmm_h5_path, model_3dmm_dat_path, reg_model_path, reg_deploy_path, reg_mean_path, generic, with_expr, with_gpu, (int)gpu_device_id); // Read source and target images cv::Mat source_img = cv::imread(input_paths[0]); cv::Mat target_img = cv::imread(input_paths[1]); // Read source and target segmentations or initialize segmentation model cv::Mat source_seg, target_seg; if (seg_model_path.empty() || seg_deploy_path.empty()) { if (seg_paths.size() > 0) source_seg = cv::imread(seg_paths[0], cv::IMREAD_GRAYSCALE); if (seg_paths.size() > 1) target_seg = cv::imread(seg_paths[1], cv::IMREAD_GRAYSCALE); } else fs.setSegmentationModel(seg_model_path, seg_deploy_path); // Set source and target if (!fs.setSource(source_img, source_seg)) throw std::runtime_error("Failed to find faces in source image!"); if (!fs.setTarget(target_img, target_seg)) throw std::runtime_error("Failed to find faces in target image!"); // Do face swap cv::Mat rendered_img = fs.swap(); if (rendered_img.empty()) throw std::runtime_error("Face swap failed!"); // Write output to file path out_file_path = output_path; path out_dir_path = output_path; if (is_directory(output_path)) { path outputName = (path(input_paths[0]).stem() += "_") += (path(input_paths[1]).stem() += ".jpg"); out_file_path = path(output_path) /= outputName; } else out_dir_path = path(output_path).parent_path(); cv::imwrite(out_file_path.string(), rendered_img); // Debug if (verbose > 0) { // Write rendered image path debug_render_path = out_dir_path / (out_file_path.stem() += "_render.jpg"); cv::Mat debug_render_img = fs.debugRender(); cv::imwrite(debug_render_path.string(), debug_render_img); } if (verbose > 1) { // Write projected meshes path debug_src_mesh_path = out_dir_path / (out_file_path.stem() += "_src_mesh.jpg"); cv::Mat debug_src_mesh_img = fs.debugSourceMesh(); cv::imwrite(debug_src_mesh_path.string(), debug_src_mesh_img); path debug_tgt_mesh_path = out_dir_path / (out_file_path.stem() += "_tgt_mesh.jpg"); cv::Mat debug_tgt_mesh_img = fs.debugTargetMesh(); cv::imwrite(debug_tgt_mesh_path.string(), debug_tgt_mesh_img); } if (verbose > 2) { // Write landmarks render path debug_src_lms_path = out_dir_path / (out_file_path.stem() += "_src_landmarks.jpg"); cv::Mat debug_src_lms_img = fs.debugSourceLandmarks(); cv::imwrite(debug_src_lms_path.string(), debug_src_lms_img); path debug_tgt_lms_path = out_dir_path / (out_file_path.stem() += "_tgt_landmarks.jpg"); cv::Mat debug_tgt_lms_img = fs.debugTargetLandmarks(); cv::imwrite(debug_tgt_lms_path.string(), debug_tgt_lms_img); } if (verbose > 3) { // Write meshes path debug_src_ply_path = out_dir_path / (out_file_path.stem() += "_src_mesh.ply"); path debug_tgt_ply_path = out_dir_path / (out_file_path.stem() += "_tgt_mesh.ply"); face_swap::Mesh::save_ply(fs.getSourceMesh(), debug_src_ply_path.string()); face_swap::Mesh::save_ply(fs.getTargetMesh(), debug_tgt_ply_path.string()); } } catch (std::exception& e) { cerr << e.what() << endl; return 1; } return 0; }
int main(int argc, char *argv[]) { try { QCommandLineParser parser; parser.setApplicationDescription("Plex Media Player"); parser.addHelpOption(); parser.addVersionOption(); parser.addOptions({{{"l", "licenses"}, "Show license information"}}); char **newArgv = appendCommandLineArguments(argc, argv, g_qtFlags); argc += g_qtFlags.size(); // Suppress SSL related warnings on OSX // See https://bugreports.qt.io/browse/QTBUG-43173 for more info // #ifdef Q_OS_MAC qputenv("QT_LOGGING_RULES", "qt.network.ssl.warning=false"); // Request OpenGL 4.1 if possible on OSX, otherwise it defaults to 2.0 // This needs to be done before we create the QGuiApplication // QSurfaceFormat format = QSurfaceFormat::defaultFormat(); format.setMajorVersion(3); format.setMinorVersion(2); format.setProfile(QSurfaceFormat::CoreProfile); QSurfaceFormat::setDefaultFormat(format); #endif preinitQt(); QGuiApplication app(argc, newArgv); app.setWindowIcon(QIcon(":/images/icon.png")); // Get the arguments from the app, this is the parsed version of newArgc and newArgv QStringList args = app.arguments(); // Remove the qt flags above so that our command line parser doesn't get cranky. for (auto flag : g_qtFlags) args.removeAll(flag); // Now parse the command line. parser.process(args); if (parser.isSet("licenses")) { ShowLicenseInfo(); return EXIT_SUCCESS; } // init breakpad. setupCrashDumper(); UniqueApplication* uniqueApp = new UniqueApplication(); if (!uniqueApp->ensureUnique()) return EXIT_SUCCESS; #ifdef Q_OS_UNIX // install signals handlers for proper app closing. SignalManager signalManager(&app); Q_UNUSED(signalManager); #endif Log::Init(); // Quit app and apply update if we find one. if (UpdateManager::CheckForUpdates()) { app.quit(); return 0; } #ifdef Q_OS_WIN32 initD3DDevice(); #endif #ifdef Q_OS_UNIX setlocale(LC_NUMERIC, "C"); #endif // Initialize all the components. This needs to be done // early since most everything else relies on it // ComponentManager::Get().initialize(); // enable remote inspection if we have the correct setting for it. if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "remoteInspector").toBool()) qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "0.0.0.0:9992"); QtWebEngine::initialize(); // Qt and QWebEngineProfile set the locale, which breaks parsing and // formatting float numbers in a few countries. #ifdef Q_OS_UNIX setlocale(LC_NUMERIC, "C"); #endif // start our helper HelperLauncher::Get().connectToHelper(); // load QtWebChannel so that we can register our components with it. QQmlApplicationEngine *engine = Globals::Engine(); KonvergoWindow::RegisterClass(); Globals::SetContextProperty("components", &ComponentManager::Get().getQmlPropertyMap()); // the only way to detect if QML parsing fails is to hook to this signal and then see // if we get a valid object passed to it. Any error messages will be reported on stderr // but since no normal user should ever see this it should be fine // QObject::connect(engine, &QQmlApplicationEngine::objectCreated, [=](QObject* object, const QUrl& url) { Q_UNUSED(url); if (object == nullptr) throw FatalException(QObject::tr("Failed to parse application engine script.")); KonvergoWindow* window = Globals::MainWindow(); QObject* webChannel = qvariant_cast<QObject*>(window->property("webChannel")); Q_ASSERT(webChannel); ComponentManager::Get().setWebChannel(qobject_cast<QWebChannel*>(webChannel)); QObject::connect(uniqueApp, &UniqueApplication::otherApplicationStarted, window, &KonvergoWindow::otherAppFocus); }); engine->load(QUrl(QStringLiteral("qrc:/ui/webview.qml"))); Log::UpdateLogLevel(); // run our application int ret = app.exec(); delete uniqueApp; Globals::EngineDestroy(); return ret; } catch (FatalException& e) { QLOG_FATAL() << "Unhandled FatalException:" << qPrintable(e.message()); QApplication errApp(argc, argv); auto msg = new ErrorMessage(e.message(), true); msg->show(); errApp.exec(); return 1; } }
int main(int argc, char **argv) //CLOCK/TIMER //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- { //Test if clock is working correctly - pause for x seconds { for (int i = 0; i<10;i++) { std::cout<<i<<"\n"; std::this_thread::sleep_for(std::chrono::seconds(1)); } } //DISTANCE //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- { Distance p1,p2,p3; p1.setCoords(7,8,3); //input coordinates p2.setCoords(1,1,1); p3=p1.minus(p2); std::cout<<"\n Particle 1 Coordinates are: "; p1.disp(); std::cout<<"\n Particle 2 Coordinates are: "; p2.disp(); std::cout<<"\n Distance between particle coordinates: "; p3.disp(); } //CIRCLE //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Circle circleOBJ; // float rad; // std::cout<<"Enter a radius: "<<std::endl; // std::cin>>rad; // circleOBJ.setradius(rad); // circleOBJ.print(); ////return 0; //NGLscene //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- { QGuiApplication app(argc, argv); // create an OpenGL format specifier QSurfaceFormat format; // set the number of samples for multisampling // will need to enable glEnable(GL_MULTISAMPLE); once we have a context format.setSamples(4); #if defined( __APPLE__) // at present mac osx Mountain Lion only supports GL3.2 // the new mavericks will have GL 4.x so can change format.setMajorVersion(4); format.setMinorVersion(1); #else // with luck we have the latest GL version so set to this format.setMajorVersion(4); format.setMinorVersion(3); #endif // now we are going to set to CoreProfile OpenGL so we can't use and old Immediate mode GL format.setProfile(QSurfaceFormat::CoreProfile); // now set the depth buffer to 24 bits format.setDepthBufferSize(24); // now we are going to create our scene window NGLscene window; // and set the OpenGL format window.setFormat(format); // we can now query the version to see if it worked std::cout<<"Profile is "<<format.majorVersion()<<" "<<format.minorVersion()<<"\n"; // set the window size window.resize(1024, 720); // and finally show window.show(); return app.exec(); } }
int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); QSurfaceFormat format; format.setMajorVersion(4); format.setMinorVersion(1); format.setProfile(QSurfaceFormat::CoreProfile); format.setRenderableType(QSurfaceFormat::OpenGL); format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); format.setSamples(2); // Today I learned: the surface itself doesn't need an alpha channel. // When we blend colours in OpenGL, the alpha value passed in with the colour // is only used internally by OpenGL in order to calculate the physical RGB // to write back into the colour buffer. We don't need to set any alpha on the // surface itself, since the RGB values will already have been blended by the // time they're written back to the colour buffer. If we do set the alpha, that // means we'll actually be able to see through the surface and whatever is behind // will be visible. This isn't what we want for the application main window! // If we want to create a frame buffer later on where the actual colour buffer // output should be translucent, override the default alpha buffer size to 8 bits. format.setDepthBufferSize(24); format.setRedBufferSize(8); format.setGreenBufferSize(8); format.setBlueBufferSize(8); format.setAlphaBufferSize(0); format.setStencilBufferSize(8); QSurfaceFormat::setDefaultFormat(format); qDebug() << "Set default OpenGL format:" << format; QApplication a(argc, argv); a.setApplicationName("Calliper"); a.setApplicationDisplayName("Calliper"); a.setOrganizationName("Infra"); a.setOrganizationName("Infra"); // Initialise the resource manager. ResourceManager::initialise(); // Initialise the renderer. OpenGLRenderer::initialise(); // Initialise the over-arching application. Application::initialise(new MainWindow()); // Set up resources. resourceManager()->makeCurrent(); resourceManager()->setUpOpenGLResources(); renderer()->setUpOpenGLResources(); resourceManager()->doneCurrent(); application()->mainWindow()->show(); int ret = a.exec(); // Shut down the application. Application::shutdown(); // Shut down the renderer. OpenGLRenderer::shutdown(); // Shut down the resource manager. ResourceManager::shutdown(); return ret; return a.exec(); }