Example #1
0
int main(int argc, char *argv[])
{
  qInstallMessageHandler(&handleMessageOutput);
  QApplication app(argc, argv);
  std::vector<QSurfaceFormat> formats;

#if !defined(QT_OPENGL_ES)
  {
    QSurfaceFormat glFormat;
    glFormat.setRenderableType(QSurfaceFormat::OpenGL);
    glFormat.setProfile(QSurfaceFormat::CoreProfile);
    glFormat.setVersion(4,3);
    formats.push_back(glFormat);
  }
#endif

#if defined(QT_OPENGL_ES)
  {
    QSurfaceFormat glesFormat;
    glesFormat.setRenderableType(QSurfaceFormat::OpenGLES);
    glesFormat.setProfile(QSurfaceFormat::CoreProfile);
    glesFormat.setVersion(3,0);
    formats.push_back(glesFormat);
  }
#endif

  // Find out which version we support
  QSurfaceFormat *format = getFirstSupported(formats);
  if (format == NULL)
  {
    QMessageBox::critical(0, "Critical Error", "No valid supported version of OpenGL found on device!");
    exit(-1);
  }

#ifdef    GL_DEBUG
  format->setOption(QSurfaceFormat::DebugContext);
#endif // GL_DEBUG
  format->setDepthBufferSize(0);

  // Set the widget up
  MainWidget *widget = new MainWidget;
  widget->setFormat(*format);

  // Set the window up
  MainWindow *window = new MainWindow;
  window->show();

  return app.exec();
}
Example #2
0
void RunTestInOpenGLOffscreenEnvironment(char const * testName, bool apiOpenGLES3,
                                         TestFunction const & fn)
{
  std::vector<char> buf(strlen(testName) + 1);
  strcpy(buf.data(), testName);
  char * raw = buf.data();

  int argc = 1;
  QApplication app(argc, &raw);

  QSurfaceFormat fmt;
  fmt.setAlphaBufferSize(8);
  fmt.setBlueBufferSize(8);
  fmt.setGreenBufferSize(8);
  fmt.setRedBufferSize(8);
  fmt.setStencilBufferSize(0);
  fmt.setSamples(0);
  fmt.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
  fmt.setSwapInterval(1);
  fmt.setDepthBufferSize(16);
  if (apiOpenGLES3)
  {
    fmt.setProfile(QSurfaceFormat::CoreProfile);
    fmt.setVersion(3, 2);
  }
  else
  {
    fmt.setProfile(QSurfaceFormat::CompatibilityProfile);
    fmt.setVersion(2, 1);
  }

  auto surface = std::make_unique<QOffscreenSurface>();
  surface->setFormat(fmt);
  surface->create();

  auto context = std::make_unique<QOpenGLContext>();
  context->setFormat(fmt);
  context->create();
  context->makeCurrent(surface.get());

  if (fn)
    fn(apiOpenGLES3);

  context->doneCurrent();
  surface->destroy();

  QTimer::singleShot(0, &app, SLOT(quit()));
  app.exec();
}
Example #3
0
File: main.cpp Project: JJ/ARehab
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    Q_INIT_RESOURCE(ARehab_vTerapeuta);

    QSurfaceFormat format;
    format.setVersion(4, 3);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setOption(QSurfaceFormat::DebugContext);
    format.setRenderableType(QSurfaceFormat::OpenGL);
    format.setDepthBufferSize(24);
    format.setStencilBufferSize(8);
    format.setSamples(4);
    format.setSwapInterval(0); //Disable VSync
    QSurfaceFormat::setDefaultFormat(format);

    ARehabGUIDesigner::ARehabMainWindow w;

    QFile styleFile(":/styles/main.qss");
    styleFile.open(QFile::ReadOnly);
    app.setStyleSheet(QLatin1String(styleFile.readAll()));
    styleFile.close();

    w.show();
    return (app.exec());
}
Example #4
0
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);
}
OGLViewer::OGLViewer(QWidget *parent)
	: QOpenGLWidget(parent), mTimeCount(0), mFps(30)
	, mSelectMode(OBJECT_SELECT)
	, mViewCamera(new PerspectiveCamera(Point3f(10, 6, 11),
                                     Point3f(0, 0, 0),
                                     Vector3f(0, 1, 0),
                                     width() / float(height())))
	, box_mesh(new TriangleMesh("../../scene/obj/cube_large.obj"))
	, model_mesh(new TriangleMesh("../../scene/obj/monkey.obj"))
{
	// Set surface format for current widget
	QSurfaceFormat format;
	format.setDepthBufferSize(32);
	format.setStencilBufferSize(8);
	format.setSamples(4);
	format.setVersion(4, 5);
	format.setProfile(QSurfaceFormat::CoreProfile);
	this->setFormat(format);

	// Link timer trigger
	/*process_time.start();
	QTimer *timer = new QTimer(this);
	//timer->setSingleShot(false);
	connect(timer, SIGNAL(timeout()), this, SLOT(update()));
	timer->start(0);*/
}
Example #6
0
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();
}
OGLViewer::OGLViewer(QWidget *parent)
	: QOpenGLWidget(parent), tcount(0), fps(30)
	, simp_lv(1)
	, m_selectMode(OBJECT_SELECT)
{
	// Set surface format for current widget
	QSurfaceFormat format;
	format.setDepthBufferSize(32);
	format.setStencilBufferSize(8);
	format.setVersion(4, 5);
	format.setProfile(QSurfaceFormat::CoreProfile);
	this->setFormat(format);

	// Read obj file
	//box_mesh = new Mesh("../../scene/obj/cube_large.obj");
	//model_mesh = new Mesh("../../scene/obj/monkey.obj");
#ifdef _DEBUG
	hds_box = new HDS_Mesh("../../scene/obj/frog.obj");
#else
	hds_box = new HDS_Mesh("quad_cube.obj");
#endif
	//hds_box->reIndexing();
	//hds_box->validate();
	simp_mesh = new Simplification(simp_lv, hds_box);

	resetCamera();
}
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();
}
Example #9
0
EffectsManager::EffectsManager(QObject *parent) : QObject(parent), QQuickImageProvider(QQuickImageProvider::Image)
{

    if (qgetenv("QT_QUICK_CORE_PROFILE").toInt()) {\
        QSurfaceFormat f = view.format();\
        f.setProfile(QSurfaceFormat::CoreProfile);\
        f.setVersion(4, 4);\
        view.setFormat(f);\
    }\
    //  view.connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit()));
    new QQmlFileSelector(view.engine(), &view);
    view.engine()->rootContext()->setContextProperty("effectsControll", this);
    //view.engine()->addImageProvider("loader", cloneImg);
    view.setSource(QUrl("qrc:/mainEffectWindow.qml")); \
    view.setResizeMode(QQuickView::SizeRootObjectToView);
    //  view.setPersistentOpenGLContext(true);
    view.setColor("transparent");

    //addEffect("first",100,100);
    /* QStringList dataList;
        dataList.append("Item 1");
        QQmlContext *ctxt = view.rootContext();
        ctxt->setContextProperty("myModel", QVariant::fromValue(dataList));*/


    //viewsetFont(QFont("Segoe Script"));
/*
    QSize t_size(300,300);
    view.setMaximumSize(t_size);
    view.setMinimumSize(t_size);
*/
}
Example #10
0
int main(int argc, char** argv) try {
    QApplication app(argc, argv);
    app.setApplicationDisplayName("Interactive OpenBC sim. interface");
    QSurfaceFormat fmt;
    fmt.setDepthBufferSize(24);
    //if (QCoreApplication::arguments().contains(QStringLiteral("--multisample"))) {
        std::cout << "Using multisample" << std::endl;;
        fmt.setSamples(4);
    //}
    // Hard-coded to use the core profile.
    fmt.setVersion(3, 2);
    fmt.setProfile(QSurfaceFormat::CoreProfile);
    QSurfaceFormat::setDefaultFormat(fmt);
    
    MainWindow mainWindow;
    mainWindow.resize(mainWindow.sizeHint());
    int desktopArea = QApplication::desktop()->width()*QApplication::desktop()->height();
    int widgetArea = mainWindow.width()*mainWindow.height();
    if (((float)widgetArea / (float)desktopArea) < 0.75f) {
        mainWindow.show();
    } else {
        mainWindow.showMaximized();
    }
    return app.exec();
    
} catch (std::exception& e) {
    std::cout << "Caught exception: " << e.what() << std::endl;
} catch (...) {
    std::cout << "Caught unknown exception.\n";
}
Example #11
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QApplication::setApplicationName("Editor");
    QApplication::setApplicationVersion("1.0");
#if C3_OS == C3_OS_WINDOWS_NT
	//Windows native theme looks so ugly
	app.setStyle("fusion");
#endif

    QCommandLineParser parser;
    parser.setApplicationDescription("The Editor");
    parser.addHelpOption();
    parser.addVersionOption();
    QCommandLineOption dataDirOption("root",
                                     "Root directory location.\nThis will override ENGINE_ROOT.",
                                     "path");
    parser.addOption(dataDirOption);
    parser.process(app);

    QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    QString absPath;
    if(!parser.value(dataDirOption).isEmpty())
    {
        absPath = parser.value(dataDirOption);
    }
    else if(env.contains("ENGINE_ROOT"))
        absPath = env.value("ENGINE_ROOT");
    else
        absPath = ".";
    QFileInfo dirInfo(absPath);
    if(!dirInfo.exists() || !dirInfo.isDir() || !QFileInfo::exists(absPath + "/Data"))
    {
        const char* msg = "Invalid root directory!";
        QMessageBox::critical(nullptr, app.applicationName(), msg);
        throw msg;
    }
    absPath = dirInfo.canonicalFilePath();
    EngineLoader.SetRootDirectory(absPath.toUtf8().constData());

    c3::RC.Loader = &EngineLoader;
    c3::RC.Loader->InitEngine();

    c3::FEditor EditorController;
    c3::RC.Editor = &EditorController;

    QSurfaceFormat format;
    format.setVersion(4, 5);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setDepthBufferSize(24);
    format.setStencilBufferSize(8);
    QSurfaceFormat::setDefaultFormat(format);

    MainWindow mainWindow;
	c3::FLogDisplay* LogDisplay = static_cast<c3::FLogDisplay*>(EditorController.GetLogDisplay());
    QObject::connect(LogDisplay, &c3::FLogDisplay::LogRefreshed,
                     &mainWindow, &MainWindow::OnLogChanged);
	mainWindow.showMaximized();
    app.exec();
}
Example #12
0
OpenGLWidget::OpenGLWidget(MainWindow* mainWindow)
    : QOpenGLWidget{mainWindow}
    , m_axisLegendScene{mainWindow->app()}
    , m_width{0}
    , m_height{0}
    , m_currentLocation{}
    , m_previousLocation{}
{
    this->setFocusPolicy(Qt::StrongFocus);

    m_contextMenu = new QMenu(this);

    QMenu* createMenu = m_contextMenu->addMenu("Create");
    createMenu->addAction(tr("Box"), this, SLOT(createBox()));
    createMenu->addAction(tr("Cylinder"), this, SLOT(createCylinder()));
    createMenu->addAction(tr("Cone"), this, SLOT(createCone()));
    createMenu->addAction(tr("Sphere"), this, SLOT(createSphere()));

    m_contextMenu->addAction(tr("Import Mesh"), this, SLOT(importMesh()));

    QSurfaceFormat format = this->format();
    format.setVersion(kOpenGLMajorVersion, kOpenGLMinorVersion);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setDepthBufferSize(32);
    format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);

    LOG(INFO) << fmt::format("Setting format with OpenGL version {}.{}", kOpenGLMajorVersion, kOpenGLMinorVersion);
    this->setFormat(format);
}
Example #13
0
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();
}
Example #14
0
MainWindow::MainWindow
(
    QWidget * parent
):
    QMainWindow(parent),
    m_ui(new Ui::MainWindow)
{
    m_ui->setupUi(this);

  // Setup OpenGL context format
    QSurfaceFormat format;
#ifdef __APPLE__
    // Get OpenGL 3.2/4.1 core context
    format.setVersion(3, 2);
    format.setProfile(QSurfaceFormat::CoreProfile);
#else
    // Get newest available compatibility context
#endif
    format.setDepthBufferSize(16);

    // Create OpenGL context and window
    m_canvas.reset(new gloperate_qt::QtOpenGLWindowBase(format));

    // Create widget container
    setCentralWidget(QWidget::createWindowContainer(m_canvas.get()));
    centralWidget()->setFocusPolicy(Qt::StrongFocus);
}
Example #15
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QSurfaceFormat fmt;
    fmt.setDepthBufferSize(24);
    if (QCoreApplication::arguments().contains(QStringLiteral("--multisample")))
        fmt.setSamples(4);
    if (QCoreApplication::arguments().contains(QStringLiteral("--coreprofile"))) {
        fmt.setVersion(3, 2);
        fmt.setProfile(QSurfaceFormat::CoreProfile);
    }
    QSurfaceFormat::setDefaultFormat(fmt);

    MainWindow mainWindow;
    mainWindow.resize(mainWindow.sizeHint());
    int desktopArea = QApplication::desktop()->width() *
                     QApplication::desktop()->height();
    int widgetArea = mainWindow.width() * mainWindow.height();
    if (((float)widgetArea / (float)desktopArea) < 0.75f)
        mainWindow.show();
    else
        mainWindow.showMaximized();
    return app.exec();
}
Example #16
0
Window::Window()
{
  QVBoxLayout *mainLayout = new QVBoxLayout;

  view  = new QGraphicsView(this);
  scene = new QGraphicsScene(view);

  view->setRenderHints(QPainter::Antialiasing);
  scene->setBackgroundBrush(Qt::blue);

  myGLWidget = new GLWidget(this);
  QOpenGLWidget *oglw = qobject_cast<QOpenGLWidget *>(myGLWidget);

  QSurfaceFormat format;
  format.setSamples(4);
  format.setDepthBufferSize(24);
  //format.setMajorVersion(3);
  //format.setMinorVersion(0);
  //format.setVersion(3,1);
  format.setProfile(QSurfaceFormat::CompatibilityProfile);
  oglw->setFormat(format);

  view->setViewport(myGLWidget);
  view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);

  view->setScene(scene);

  mainLayout->addWidget(view);
  setLayout(mainLayout);

  setWindowTitle(tr("GraphicsView + OpenGL Test Unit"));
}
Example #17
0
int main(int argc, char *argv[])
{
    qputenv("PATH", qgetenv("PATH") + ":/usr/local/bin:/usr/bin");

    QApplication a(argc, argv);

    QSplashScreen s(QPixmap(":/application/splash"), Qt::WindowStaysOnTopHint);
    s.show();

    QApplication::setOrganizationName("Regulomics");
    QApplication::setApplicationName("QChromosome 4D Studio");
    QApplication::setWindowIcon(QIcon(":/application/icon"));

    QSurfaceFormat format;
    format.setDepthBufferSize(24);
    format.setVersion(4, 1);
    format.setProfile(QSurfaceFormat::CoreProfile);
    QSurfaceFormat::setDefaultFormat(format);

    QFontDatabase::addApplicationFont(":/fonts/Roboto-Regular");
    QFontDatabase::addApplicationFont(":/fonts/Roboto-Bold");
    QFontDatabase::addApplicationFont(":/fonts/RobotoMono-Regular");

    MainWindow w(a.arguments().mid(1));

    a.installEventFilter(&w);

    w.showMaximized();

    s.finish(&w);

    return a.exec();
}
Example #18
0
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);
}
Example #19
0
void KisOpenGL::initialize()
{
#ifdef HAVE_OPENGL
    dbgUI << "OpenGL: initializing";

    KisConfig cfg;

    QSurfaceFormat format;
    format.setProfile(QSurfaceFormat::CompatibilityProfile);
    format.setOptions(QSurfaceFormat::DeprecatedFunctions);
    format.setDepthBufferSize(24);
    format.setStencilBufferSize(8);
    format.setVersion(3, 2);
    // if (cfg.disableDoubleBuffering()) {
    if (false) {
        format.setSwapBehavior(QSurfaceFormat::SingleBuffer);
    }
    else {
        format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
    }
    format.setSwapInterval(0); // Disable vertical refresh syncing
    QSurfaceFormat::setDefaultFormat(format);

#endif
}
Example #20
0
int main(int argc, char* argv[])
{
    QApplication app(argc, argv);
    QVRManager manager(argc, argv);

    /* Load the model file */
    if (argc != 2) {
        std::cerr << argv[0] << ": requires model filename argument." << std::endl;
        return 1;
    }
    osg::ref_ptr<osgDB::ReaderWriter::Options> options = new osgDB::ReaderWriter::Options();
    options->setOptionString("noRotation");
    osg::ref_ptr<osg::Node> model = osgDB::readNodeFile(argv[1], options);
    if (!model) {
        std::cerr << argv[0] << ": no data loaded." << std::endl;
        return 1;
    }

    /* First set the default surface format that all windows will use */
    QSurfaceFormat format;
    format.setProfile(QSurfaceFormat::CompatibilityProfile); // OSG cannot handle core profiles
    format.setVersion(3, 3);
    QSurfaceFormat::setDefaultFormat(format);

    /* Then start QVR with your app */
    QVROSGViewer qvrapp(model);
    if (!manager.init(&qvrapp)) {
        std::cerr << "Cannot initialize QVR manager" << std::endl;
        return 1;
    }

    /* Enter the standard Qt loop */
    return app.exec();
}
Example #21
0
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);
}
Example #22
0
int main(int argc, char* argv[])
{
   QGuiApplication app(argc,argv);
   qmlRegisterType<Connector>("Connector", 1, 0, "Connector");
   app.setOrganizationName("QtProject");\
   app.setOrganizationDomain("qt-project.org");\
   app.setApplicationName(QFileInfo(app.applicationFilePath()).baseName());\
   QQuickView view;\
   if (qgetenv("QT_QUICK_CORE_PROFILE").toInt()) {\
       QSurfaceFormat f = view.format();\
       f.setProfile(QSurfaceFormat::CoreProfile);\
       f.setVersion(4, 4);\
       view.setFormat(f);\
   }\
   view.connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit()));\
   new QQmlFileSelector(view.engine(), &view);\
   view.setSource(QUrl("qrc:///demos/tweetsearch/tweetsearch.qml")); \
   view.setResizeMode(QQuickView::SizeRootObjectToView);\
   if (QGuiApplication::platformName() == QLatin1String("qnx") || \
         QGuiApplication::platformName() == QLatin1String("eglfs")) {\
       view.showFullScreen();\
   } else {\
       view.show();\
   }\
   return app.exec();\
}
Example #23
0
void ccApplication::init()
{
	//See http://doc.qt.io/qt-5/qopenglwidget.html#opengl-function-calls-headers-and-qopenglfunctions
	/** Calling QSurfaceFormat::setDefaultFormat() before constructing the QApplication instance is mandatory
		on some platforms (for example, OS X) when an OpenGL core profile context is requested. This is to
		ensure that resource sharing between contexts stays functional as all internal contexts are created
		using the correct version and profile.
	**/
	{
		QSurfaceFormat format = QSurfaceFormat::defaultFormat();
		
		format.setSwapBehavior( QSurfaceFormat::DoubleBuffer );
		format.setStencilBufferSize( 0 );
		
#ifdef CC_GL_WINDOW_USE_QWINDOW
		format.setStereo( true );
#endif
		
#ifdef Q_OS_MAC
		format.setVersion( 2, 1 );	// must be 2.1 - see ccGLWindow::functions()
		format.setProfile( QSurfaceFormat::CoreProfile );
#endif
		
#ifdef QT_DEBUG
		format.setOption( QSurfaceFormat::DebugContext, true );
#endif
		
		QSurfaceFormat::setDefaultFormat( format );
	}
	
	// The 'AA_ShareOpenGLContexts' attribute must be defined BEFORE the creation of the Q(Gui)Application
	// DGM: this is mandatory to enable exclusive full screen for ccGLWidget (at least on Windows)
	QCoreApplication::setAttribute( Qt::AA_ShareOpenGLContexts );
}
Example #24
0
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();
}
Example #25
0
void GLViewer::setup()
{
    QSurfaceFormat format;

    format.setVersion(3, 2);
    format.setProfile(QSurfaceFormat::CoreProfile);

    format.setDepthBufferSize(16);

    m_canvas = new Canvas(format);
    m_canvas->setContinuousRepaint(true, 0);
    m_canvas->setSwapInterval(Canvas::VerticalSyncronization);

    m_canvas->setPainter(m_painter);

    QWidget *widget = QWidget::createWindowContainer(m_canvas);
    widget->setMinimumSize(1, 1);
    widget->setAutoFillBackground(false); // Important for overdraw, not occluding the scene.
    widget->setFocusPolicy(Qt::TabFocus);
    widget->setParent(this);

    QHBoxLayout *layout = new QHBoxLayout;
    layout->setContentsMargins(0, 0, 0, 0);
    layout->addWidget(widget);
    setLayout(layout);

    show();
}
Example #26
0
void Viewer::setupCanvas()
{
    QSurfaceFormat format;

    format.setVersion(3, 2);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setDepthBufferSize(16);

    // Create OpenGL context and window
    m_canvas.reset(new gloperate_qt::QtOpenGLWindow(*m_resourceManager, format));

    // Create widget container
    setCentralWidget(QWidget::createWindowContainer(m_canvas.get()));
    centralWidget()->setFocusPolicy(Qt::StrongFocus);

    // Setup event provider to translate Qt messages into gloperate events
    gloperate_qt::QtKeyEventProvider * keyProvider = new gloperate_qt::QtKeyEventProvider();
    keyProvider->setParent(m_canvas.get());
    gloperate_qt::QtMouseEventProvider * mouseProvider = new gloperate_qt::QtMouseEventProvider();
    mouseProvider->setParent(m_canvas.get());
    gloperate_qt::QtWheelEventProvider * wheelProvider = new gloperate_qt::QtWheelEventProvider();
    wheelProvider->setParent(m_canvas.get());

    m_canvas->installEventFilter(keyProvider);
    m_canvas->installEventFilter(mouseProvider);
    m_canvas->installEventFilter(wheelProvider);

    // Create input mapping for gloperate interaction techniques
    m_mapping.reset(new QtViewerMapping(m_canvas.get()));
    m_mapping->addProvider(keyProvider);
    m_mapping->addProvider(mouseProvider);
    m_mapping->addProvider(wheelProvider);
}
Example #27
0
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;
}
Example #28
0
int main(int argc, char *argv[])
{

    QApplication a(argc, argv);

    // Set OpenGL 3.2 and, optionally, 4-sample multisampling
    QSurfaceFormat format;
    format.setVersion(3, 2);
    format.setOption(QSurfaceFormat::DeprecatedFunctions, false);
    format.setProfile(QSurfaceFormat::CoreProfile);
    //format.setSamples(4);  // Uncomment for nice antialiasing. Not always supported.

    /*** AUTOMATIC TESTING: DO NOT MODIFY ***/
    /*** Check whether automatic testing is enabled */
    /***/ if (qgetenv("CIS277_AUTOTESTING") != nullptr) format.setSamples(0);

    QSurfaceFormat::setDefaultFormat(format);
    debugFormatVersion();

    MainWindow w;
    w.show();

    w.sendItems();

    return a.exec();
}
Example #29
0
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();*/
}
OGLViewer::OGLViewer(QWidget *parent)
	: QOpenGLWidget(parent), tcount(0)
	, fps(30), timestep(1.0 / fps), isSim(false)
{
	// Set surface format for current widget
	QSurfaceFormat format;
	format.setDepthBufferSize(32);
	format.setStencilBufferSize(8);
	format.setVersion(4, 5);
	format.setProfile(QSurfaceFormat::CoreProfile);
	this->setFormat(format);

	// Link timer trigger
	process_time.start();
	QTimer *timer = new QTimer(this);
	/*timer->setSingleShot(false);*/
	connect(timer, SIGNAL(timeout()), this, SLOT(update()));
	timer->start(0);

	// Read obj file
#ifdef _DEBUG
	box_mesh = new Mesh("../../scene/obj/cube_huge.obj");
	poly_mesh = new Mesh("../../scene/obj/bunny_simple.obj");
	poly_bound = new Mesh("../../scene/obj/bunny_bound.obj");
#else
	box_mesh = new Mesh("cube_large.obj");
	poly_mesh = new Mesh("bunny_simple.obj");
	poly_bound = new Mesh("bunny_bound.obj");
#endif // _DEBUG
	poly_bound->refine(triangleList);
	mytree = new KdTreeAccel(triangleList);

	texW = sparkTex.getWidth();
	texH = sparkTex.getHeight();
	sparkTex.getPixelsRGBA(tex_pixels);

	// Initialize particle generators
	//Point3D newpos(0.0, 0.0, 0.0), vel(0.3, 1.0, 1.0), vel_var(0.3, 0.3, 0.3);
	ParticleGenerator* pg = new ParticleGenerator(
		3500, 1000, 20, timestep, 3, 0.6,
		2.0, 1.2,
		Point3D(0.0, 5.0, 0.0),
		Vector3D(0, -10, 0), Vector3D(1, 0, 0),
		ParticleGenerator::CONCENTRIC_DISK, 0.5);
	Vector3D* gravity = new Vector3D(0.0, -9.8, 0.0);
	Vector3D* wind = new Vector3D(0, 0.0, 0.0);
	pg->addForce(gravity);
	pg->addForce(wind);
	pgs.push_back(pg);
	pg->exportVBO(ptc_size, ptc_verts, ptc_vels, ptc_life, ptc_alive, true);
	pg->addCollision(mytree);
	

	resetCamera();

	// Initialize transform matrix
	matrix.setIdentity();// setRotation(20, 0, 0);
	matrix.exportVBO(model_mat);
}