int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); QGuiApplication app(argc, argv); Q_UNUSED(app); QSurfaceFormat format; format.setMajorVersion(3); format.setMinorVersion(0); QOpenGLContext context; context.setFormat(format); context.create(); if (!context.isValid()) return 1; qDebug() << QString::fromLatin1("Context created."); QOffscreenSurface surface; surface.setFormat(format); surface.create(); if(!surface.isValid()) return 2; qDebug() << QString::fromLatin1("Surface created."); context.makeCurrent(&surface); return RUN_ALL_TESTS(); }
int main( int argc, char* argv[] ) { QGuiApplication a( argc, argv ); QStringList args = a.arguments(); if ( args.size() != 2 ) { qDebug() << "Please specify an obj file to load"; exit( 1 ); } const QString fileName = args.last(); // Specify the format we wish to use QSurfaceFormat format; format.setMajorVersion( 3 ); #if !defined(Q_OS_MAC) format.setMinorVersion( 3 ); #else format.setMinorVersion( 2 ); #endif format.setDepthBufferSize( 24 ); format.setSamples( 4 ); format.setProfile( QSurfaceFormat::CoreProfile ); OpenGLWindow w( format ); w.setScene( new MultipleLightsScene( fileName ) ); w.show(); return a.exec(); }
QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *) : d(new QGLTemporaryContextPrivate) { d->oldContext = const_cast<QGLContext *>(QGLContext::currentContext()); d->window = new QWindow; d->window->setSurfaceType(QWindow::OpenGLSurface); d->window->setGeometry(QRect(0, 0, 3, 3)); d->window->create(); d->context = new QOpenGLContext; #if !defined(QT_OPENGL_ES) // On desktop, request latest released version QSurfaceFormat format; #if defined(Q_OS_MAC) // OS X is limited to OpenGL 3.2 Core Profile at present // so set that here. If we use compatibility profile it // only reports 2.x contexts. format.setMajorVersion(3); format.setMinorVersion(2); format.setProfile(QSurfaceFormat::CoreProfile); #else format.setMajorVersion(4); format.setMinorVersion(3); #endif d->context->setFormat(format); #endif d->context->create(); d->context->makeCurrent(d->window); }
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(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 // and finally show window.show(); window.resize(1024, 720); return app.exec(); }
int main(int argc, char **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( DARWIN) // 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(2); #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); // this will set the format for all widgets QSurfaceFormat::setDefaultFormat(format); // make an instance of the QApplication CebApplication a(argc, argv); // Create a new MainWindow MainWindow w; // show main window w.show(); // show start dialog w.showStartDialog(); // hand control over to Qt framework return a.exec(); }
GLWindow::GLWindow(QScreen *screen) : QWindow(screen) { QSurfaceFormat cformat; cformat.setDepthBufferSize(24); cformat.setMajorVersion(4); cformat.setMinorVersion(2); cformat.setProfile(QSurfaceFormat::CoreProfile); resize(800,600); setSurfaceType(OpenGLSurface); create(); _context = new QOpenGLContext; _context->setFormat(cformat); _context->create(); connect(this,SIGNAL(widthChanged(int)), this, SLOT(resizeGL())); connect(this,SIGNAL(heightChanged(int)), this, SLOT(resizeGL())); initializeGL(); resizeGL(); /*QTimer* timer = new QTimer(this); connect( timer, SIGNAL(timeout()), this, SLOT(update())); timer->start();*/ }
const QSurfaceFormat& getDefaultOpenGLSurfaceFormat() { static QSurfaceFormat format; static std::once_flag once; std::call_once(once, [] { #if defined(USE_GLES) format.setRenderableType(QSurfaceFormat::OpenGLES); format.setRedBufferSize(8); format.setGreenBufferSize(8); format.setBlueBufferSize(8); format.setAlphaBufferSize(8); #else format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); #endif if (gl::Context::enableDebugLogger()) { format.setOption(QSurfaceFormat::DebugContext); } // Qt Quick may need a depth and stencil buffer. Always make sure these are available. format.setDepthBufferSize(DEFAULT_GL_DEPTH_BUFFER_BITS); format.setStencilBufferSize(DEFAULT_GL_STENCIL_BUFFER_BITS); int major, minor; ::gl::getTargetVersion(major, minor); format.setMajorVersion(major); format.setMinorVersion(minor); }); return format; }
Window::Window(QScreen *screen) : QWindow (screen), scene_ (new BasicUsageScene) { setSurfaceType(OpenGLSurface); QSurfaceFormat format; format.setDepthBufferSize(24); format.setMajorVersion(3); format.setMinorVersion(3); format.setSamples(4); format.setProfile(QSurfaceFormat::CoreProfile); resize(800, 600); setFormat(format); create(); context_ = new QOpenGLContext(); context_->setFormat(format); context_->create(); scene_->setContext(context_); initializeGl(); connect(this, SIGNAL(widthChanged(int)), this, SLOT(resizeGl())); connect(this, SIGNAL(heightChanged(int)), this, SLOT(resizeGl())); resizeGl(); QTimer* timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(updateScene())); timer->start(16); }
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); format.setMajorVersion(3); format.setMinorVersion(2); // now we are going to set to Compat Profile OpenGL so we can use and old Immediate mode GL format.setProfile(QSurfaceFormat::CompatibilityProfile); // now set the depth buffer to 24 bits format.setDepthBufferSize(24); QSurfaceFormat::setDefaultFormat(format); // now we are going to create our scene window OpenGLWindow 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(); }
RenderWidget::RenderWidget(QWidget *parent) : QOpenGLWidget(parent), renderFunctions(nullptr), render(nullptr), quad(nullptr), quadShader(nullptr), openglDebugLogger(nullptr), captureMouse(false), onlyShowTexture(false), textureDisplayed(color) { // Widget config setUpdateBehavior(QOpenGLWidget::NoPartialUpdate); setFocusPolicy(Qt::ClickFocus); // Update Timer config connect(&updateTimer, SIGNAL(timeout()), this, SLOT(update())); startUpdateLoop(); // Open GL Context config QSurfaceFormat f; f.setRenderableType(QSurfaceFormat::OpenGL); f.setMajorVersion(4); f.setMinorVersion(5); f.setProfile(QSurfaceFormat::CoreProfile); f.setOptions(QSurfaceFormat::DebugContext | f.options()); setFormat(f); }
ContextPoolContext::ContextPoolContext(QOpenGLContext* share_context, bool reserved) : reserved(reserved), count(0), surface(NULL), context(NULL) { QSurfaceFormat format; format.setMajorVersion(3); format.setMinorVersion(2); format.setSwapInterval(0); format.setSwapBehavior(QSurfaceFormat::SingleBuffer); format.setRenderableType(QSurfaceFormat::OpenGL); format.setProfile(QSurfaceFormat::CoreProfile); format.setOption(QSurfaceFormat::DebugContext); surface = new QOffscreenSurface(); surface->setFormat(format); surface->create(); if (!surface->isValid()) { throw; } context = new QOpenGLContext(); context->setShareContext(share_context); context->setFormat(surface->requestedFormat()); if (!context->create()) { throw; } context->makeCurrent(surface); gl = context->versionFunctions<QOpenGLFunctions_3_2_Core>(); if (gl == nullptr || !gl->initializeOpenGLFunctions()) { throw; } indirect = new QOpenGLExtension_ARB_multi_draw_indirect(); if (!indirect->initializeOpenGLFunctions()) { throw; } vab = new QOpenGLExtension_ARB_vertex_attrib_binding(); if (!vab->initializeOpenGLFunctions()) { throw; } sso = new QOpenGLExtension_ARB_separate_shader_objects(); if (!sso->initializeOpenGLFunctions()) { throw; } tex = new QOpenGLExtension_ARB_texture_buffer_object(); if (!tex->initializeOpenGLFunctions()) { throw; } buffer = (QOpenGLExtension_ARB_buffer_storage)context->getProcAddress("glBufferStorage"); debug = new QOpenGLExtension_ARB_debug_output(); if (!debug->initializeOpenGLFunctions()) { throw; } debug->glDebugMessageCallbackARB(debug_callback, nullptr); debug->glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, 0, GL_FALSE); debug->glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0, 0, GL_TRUE); context->doneCurrent(); context->moveToThread(nullptr); }
void HsQMLContextControl::controlContext() { // Do nothing if no window if (!mWindow) { return; } // Do nothing if changes are being deferred if (mDefer || !mWhen) { mPending = true; return; } mPending = false; QSurfaceFormat fmt = mOriginal; if (mMajorVersion >= 0) { fmt.setMajorVersion(mMajorVersion); } if (mMinorVersion >= 0) { fmt.setMinorVersion(mMinorVersion); } if (mContextType >= 0) { fmt.setRenderableType(static_cast<QSurfaceFormat::RenderableType>( mContextType)); } if (mContextProfile >= 0) { fmt.setProfile(static_cast<QSurfaceFormat::OpenGLContextProfile>( mContextProfile)); } if (mDeprecatedFunctionsSet) { #if QT_VERSION >= 0x050300 fmt.setOption(QSurfaceFormat::DeprecatedFunctions, mDeprecatedFunctions); #else if (mDeprecatedFunctions) { fmt.setOption(QSurfaceFormat::DeprecatedFunctions); } #endif } fmt.setDepthBufferSize(qMax(fmt.depthBufferSize(), mDepthBufferSize)); fmt.setStencilBufferSize(qMax(fmt.stencilBufferSize(), mStencilBufferSize)); if (fmt == mWindow->requestedFormat()) { return; } mWindow->setFormat(fmt); // Recreate OpenGL context mWindow->setPersistentOpenGLContext(false); mWindow->setPersistentSceneGraph(false); bool visible = mWindow->isVisible(); mWindow->destroy(); mWindow->releaseResources(); mWindow->setVisible(visible); mWindow->setPersistentOpenGLContext(true); mWindow->setPersistentSceneGraph(true); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- bool COpenVROverlayController::Init() { bool bSuccess = true; m_strName = "Alerts"; QSurfaceFormat format; format.setMajorVersion( 4 ); format.setMinorVersion( 1 ); format.setProfile( QSurfaceFormat::CompatibilityProfile ); m_pOpenGLContext = new QOpenGLContext(); m_pOpenGLContext->setFormat( format ); bSuccess = m_pOpenGLContext->create(); if( !bSuccess ) return false; // create an offscreen surface to attach the context and FBO to m_pOffscreenSurface = new QOffscreenSurface(); m_pOffscreenSurface->create(); m_pOpenGLContext->makeCurrent( m_pOffscreenSurface ); m_pScene = new QGraphicsScene(); connect( m_pScene, SIGNAL(changed(const QList<QRectF>&)), this, SLOT( OnSceneChanged(const QList<QRectF>&)) ); // Loading the OpenVR Runtime bSuccess = ConnectToVRRuntime(); bSuccess = bSuccess && vr::VRCompositor() != NULL; if( vr::VROverlay() ) { std::string sKey = "texasgamer.openvr-notifications.overlay.Alerts"; vr::VROverlayError overlayError = vr::VROverlay()->CreateDashboardOverlay(sKey.c_str(), "Alerts", &m_ulOverlayHandle, &m_ulOverlayThumbnailHandle); QString name = qApp->applicationDirPath() + "/resources/overlay-icon.png"; vr::VROverlay()->SetOverlayFromFile(m_ulOverlayThumbnailHandle, name.toUtf8().constData()); bSuccess = bSuccess && overlayError == vr::VROverlayError_None; } if( bSuccess ) { vr::VROverlay()->SetOverlayWidthInMeters( m_ulOverlayHandle, 1.5f ); vr::VROverlay()->SetOverlayInputMethod( m_ulOverlayHandle, vr::VROverlayInputMethod_Mouse ); m_pPumpEventsTimer = new QTimer( this ); connect(m_pPumpEventsTimer, SIGNAL( timeout() ), this, SLOT( OnTimeoutPumpEvents() ) ); m_pPumpEventsTimer->setInterval( 20 ); m_pPumpEventsTimer->start(); qInfo() << "Connected with OpenVR."; } else { qInfo() << "Unable to start openvr-notifications. Unable to connect with OpenVR."; } return true; }
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 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(); }
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 }
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); }
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); }
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(); }
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(); }
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(); }
/*! 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; }
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[]) { // 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[]) { 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(); }
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(); } }