Beispiel #1
0
int main(int argc, char** argv)
{
  QApplication application(argc,argv);

  QGLFormat glFormat(QGL::SampleBuffers);
qDebug() << "Starting application";

 glFormat.setVersion( 3, 3 );
 glFormat.setProfile( QGLFormat::CoreProfile ); // Requires >=Qt-4.8.0
 glFormat.setSampleBuffers( true );
qDebug() << "GLFormat set";

  QGLContext context(glFormat);
  context.makeCurrent();
  
qDebug() << "context created";

  Viewer viewer(&context);
  viewer.setWindowTitle("multiSelect");
qDebug() << "about to show window";
  viewer.show();

  qDebug() << QGLFormat::openGLVersionFlags();

  return application.exec();
}
QPaintEngine* QX11GLPixmapData::paintEngine() const
{
    // We need to create the context before beginPaint - do it here:
    if (!ctx) {
        ctx = new QGLContext(glFormat());
        if (ctx->d_func()->eglContext == 0)
            ctx->d_func()->eglContext = new QEglContext();
        ctx->d_func()->eglContext->openDisplay(0); // ;-)
        ctx->d_func()->eglContext->setApi(QEgl::OpenGL);
        ctx->d_func()->eglContext->setContext(hasAlphaChannel() ? qPixmapARGBSharedEglContext
                                                                : qPixmapRGBSharedEglContext);
    }

    if (!qt_gl2_engine_for_pixmaps)
        qt_gl2_engine_for_pixmaps = new QGL2PaintEngineEx();

    // Support multiple painters on multiple pixmaps simultaniously
    if (qt_gl2_engine_for_pixmaps->isActive()) {
        qWarning("Pixmap paint engine already active");
        QPaintEngine* engine = new QGL2PaintEngineEx();
        engine->setAutoDestruct(true);
        return engine;
    }

    return qt_gl2_engine_for_pixmaps;
}
Beispiel #3
0
void View::initGL()
{
	qDebug( "* OpenGL:" );
	setViewportUpdateMode( QGraphicsView::FullViewportUpdate );
	setFrameShape( QFrame::NoFrame );

	QGLFormat glFormat( QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba | QGL::DirectRendering );
	glFormat.setVersion( 2, 1 );
//	glFormat.setSwapInterval( 1 );

	QSettings settings;
	glFormat.setSampleBuffers( settings.value( "sampleBuffers", false ).toBool() );

	mGLWidget = new GLWidget( glFormat, this );
	setViewport( mGLWidget );

	const GLubyte * vendorGL = glGetString( GL_VENDOR );
	qDebug( "\t* %s:\t%s", qPrintable(tr("Vendor")), vendorGL );
	const GLubyte * rendererGL = glGetString( GL_RENDERER );
	qDebug( "\t* %s:\t%s", qPrintable(tr("Renderer")), rendererGL );
	const GLubyte * versionGL = glGetString( GL_VERSION );
	qDebug( "\t* %s:\t%s", qPrintable(tr("Version")), versionGL );
	const GLubyte * glslVersionGL = glGetString( GL_SHADING_LANGUAGE_VERSION );
	qDebug( "\t* %s:\t%s", qPrintable(tr("GLSL version")), glslVersionGL );
//	const GLubyte * extensionsGL = glGetString( GL_EXTENSIONS );
//	qDebug( "\t* %s:\t%s", qPrintable(tr("Supported extensions")), extensionsGL );
}
QGLWidget* DTIDEGLWidgets::requestWidget(QString title, int width, int height)
{
    QGLFormat glFormat(QGL::SampleBuffers);
    glFormat.setSwapInterval(0);
    QGLWidget* res = new QGLWidget(glFormat);
    
    res->resize(width, height);
    res->setWindowTitle(title);
    res->show();
    activeWidgets.append(res);

    res->makeCurrent();
    return res;
}
Image Texture2D::getImage(int level) const {
   Image::Format format;
   switch (channels) {
      case 1:
         format = Image::GRAY;
         break;
      case 2:
         format = Image::GA;
         break;
      case 3:
         format = Image::BGR;
         break;
      case 4:
      default:
         format = Image::BGRA;
         break;
   }

   Image image(format, getSize(level));
   if (created) {
      glGetTexImage(target, level, glFormat(image.channelCount()), GL_UNSIGNED_BYTE, image.rawData());
   }
   return image;
}
void Texture2D::setSubImage(Point2i const & offset, Image const & image, int level) const {
   glTexSubImage2D(target, level, offset[0], offset[1],
                   image.getWidth(), image.getHeight(),
                   glFormat(image.channelCount()), GL_UNSIGNED_BYTE,
                   image.rawData());
}
StelMainGraphicsView::StelMainGraphicsView(QWidget* parent)
	: QGraphicsView(parent), backItem(NULL), gui(NULL),
#ifndef DISABLE_SCRIPTING
	scriptAPIProxy(NULL), scriptMgr(NULL),
#endif
	  wasDeinit(false),
	  flagInvertScreenShotColors(false),
	  screenShotPrefix("stellarium-"),
	  screenShotDir(""),
	  cursorTimeout(-1.f), flagCursorTimeout(false), minFpsTimer(NULL), maxfps(10000.f)
{
	StelApp::initStatic();

	// Can't create 2 StelMainGraphicsView instances
	Q_ASSERT(!singleton);
	singleton = this;

	setObjectName("Mainview");

	// Avoid white background at init
	setAttribute(Qt::WA_PaintOnScreen);
	setAttribute(Qt::WA_NoSystemBackground);
	setAttribute(Qt::WA_OpaquePaintEvent);
	setAutoFillBackground(true);
	setBackgroundRole(QPalette::Window);
	QPalette pal;
	pal.setColor(QPalette::Window, Qt::black);
	setPalette(pal);

	// Allows for precise FPS control
	setViewportUpdateMode(QGraphicsView::NoViewportUpdate);
	setFrameShape(QFrame::NoFrame);
	setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	setFocusPolicy(Qt::StrongFocus);
	connect(this, SIGNAL(screenshotRequested()), this, SLOT(doScreenshot()));

	lastEventTimeSec = 0;

	// Create an openGL viewport
	QGLFormat glFormat(QGL::StencilBuffer | QGL::DepthBuffer | QGL::DoubleBuffer);
	glContext = new QGLContext(glFormat);
	glWidget = new StelQGLWidget(glContext, this);
	glWidget->updateGL();
	setViewport(glWidget);

	// This line seems to cause font aliasing troubles on win32
	// setOptimizationFlags(QGraphicsView::DontSavePainterState);

	setScene(new QGraphicsScene(this));
	scene()->setItemIndexMethod(QGraphicsScene::NoIndex);

	backItem = new QGraphicsWidget();
	backItem->setFocusPolicy(Qt::NoFocus);

	// Workaround (see Bug #940638) Although we have already explicitly set
	// LC_NUMERIC to "C" in main.cpp there seems to be a bug in OpenGL where
	// it will silently reset LC_NUMERIC to the value of LC_ALL during OpenGL
	// initialization. This has been observed on Ubuntu 11.10 under certain
	// circumstances, so here we set it again just to be on the safe side.
	setlocale(LC_NUMERIC, "C");
	// End workaround
}
Beispiel #8
0
Texture &Texture::create(int w, int h, Type type, int filter, int wrap, Type dataType, void *data) {
    return create(w, h, 1, glInternalFormat(type), glFormat(type), glType(dataType), filter, wrap, data);
}
Beispiel #9
0
Texture &Texture::create(int w, int h, Type type, int filter, int wrap) {
    return create(w, h, 1, glInternalFormat(type), glFormat(type), glType(type), filter, wrap, nullptr);
}
Beispiel #10
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    qDebug() << "Application dir:" << QApplication::applicationDirPath();
    qDebug() << "Data dir:" << _find_data_dir("");

    // Chossing proper GUI style from config.ini file.
    QSettings settings("config.ini", QSettings::IniFormat);
    // Dude, this default style is really amazing...
    // Seriously?
    // No...
    QString guiStyle = settings.value("gui_style","DefaultAwesomeStyle").toString();
    app.setStyle(QStyleFactory::create( guiStyle ));

    // Customize some elements:
    app.setStyleSheet("QGroupBox { font-weight: bold; } ");

    QFont font;
    font.setFamily(font.defaultFamily());
    font.setPixelSize(10);
    app.setFont(font);

    // removing old log file
    QFile::remove(AB_LOG);


    QGLFormat glFormat(QGL::SampleBuffers);

#ifdef Q_OS_MAC
    glFormat.setProfile( QGLFormat::CoreProfile );
    glFormat.setVersion( 4, 1 );
#endif

#ifdef USE_OPENGL_330
#ifdef Q_OS_LINUX
    glFormat.setProfile( QGLFormat::CoreProfile );
    glFormat.setVersion( 3, 3 );
#endif
#endif

    QGLFormat::setDefaultFormat(glFormat);


    qInstallMessageHandler(customMessageHandler);
    qDebug() << "Starting application:";

    if(!checkOpenGL()){

        AllAboutDialog msgBox;
        msgBox.setPixmap(":/resources/icon-off.png");
        msgBox.setText("Fatal Error!");

#ifdef USE_OPENGL_330
        msgBox.setInformativeText("Sorry but it seems that your graphics card does not support openGL 3.3.\n"
                                  "Program will not run :(\n"
                                  "See " AB_LOG " file for more info.");
#else
        msgBox.setInformativeText("Sorry but it seems that your graphics card does not support openGL 4.0.\n"
                                  "Program will not run :(\n"
                                  "See " AB_LOG " file for more info.");
#endif


        msgBox.show();

        return app.exec();
    }else{

        MainWindow window;
        window.setWindowTitle(AWESOME_BUMP_VERSION);
        window.resize(window.sizeHint());
        int desktopArea = QApplication::desktop()->width() *
                         QApplication::desktop()->height();
        int widgetArea = window.width() * window.height();
        if (((float)widgetArea / (float)desktopArea) < 0.75f)
            window.show();
        else
            window.showMaximized();

        return app.exec();

    }



}
Beispiel #11
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    qDebug() << "Application dir:" << QApplication::applicationDirPath();
    qDebug() << "Data dir:" << _find_data_dir("");

    // Chossing proper GUI style from config.ini file.
    QSettings settings("config.ini", QSettings::IniFormat);
    // Dude, this default style is really amazing...
    // Seriously?
    // No...
    QString guiStyle = settings.value("gui_style","DefaultAwesomeStyle").toString();
    app.setStyle(QStyleFactory::create( guiStyle ));

    // Customize some elements:
    app.setStyleSheet("QGroupBox { font-weight: bold; } ");

    QFont font;
    font.setFamily(font.defaultFamily());
    font.setPixelSize(10);
    app.setFont(font);

    // removing old log file
    QFile::remove(AB_LOG);


    QGLFormat glFormat(QGL::SampleBuffers);

#if defined(Q_OS_LINUX) || defined(Q_OS_MAC)
     /*
     * Commenting out the next line because it causes rendering to fail.  QGLFormat::CoreProfile
     * disables all OpenGL functions that are depreciated as of OpenGL 3.0.  This fix is a workaround.
     * The full solution is to replace all depreciated OpenGL functions with their current implements.
    */
# if defined(Q_OS_MAC)
	glFormat.setProfile( QGLFormat::CoreProfile );
# endif
    glFormat.setVersion( GL_MAJOR, GL_MINOR );
#endif

    QGLFormat::setDefaultFormat(glFormat);


    qInstallMessageHandler(customMessageHandler);
    qDebug() << "Starting application:";

    if(!checkOpenGL()){

        AllAboutDialog msgBox;
        msgBox.setPixmap(":/resources/icon-off.png");
        msgBox.setText("Fatal Error!");

        msgBox.setInformativeText(QString("Sorry but it seems that your graphics card does not support openGL %1.%2.\n"
                                          "Program will not run :(\n"
                                          "See " AB_LOG " file for more info.").arg(GL_MAJOR).arg(GL_MINOR));

        msgBox.show();

        return app.exec();
    }else{

        MainWindow window;
        window.setWindowTitle(AWESOME_BUMP_VERSION);
        window.resize(window.sizeHint());
        int desktopArea = QApplication::desktop()->width() *
                         QApplication::desktop()->height();
        int widgetArea = window.width() * window.height();
        if (((float)widgetArea / (float)desktopArea) < 0.75f)
            window.show();
        else
            window.showMaximized();

        return app.exec();

    }



}
Beispiel #12
0
StelMainView::StelMainView(QWidget* parent)
	: QGraphicsView(parent), guiItem(NULL), gui(NULL),
	  flagInvertScreenShotColors(false),
	  flagOverwriteScreenshots(false),
	  screenShotPrefix("stellarium-"),
	  screenShotDir(""),
	  cursorTimeout(-1.f), flagCursorTimeout(false), minFpsTimer(NULL), maxfps(10000.f)
{
	StelApp::initStatic();
	
	// Can't create 2 StelMainView instances
	Q_ASSERT(!singleton);
	singleton = this;

	setWindowIcon(QIcon(":/mainWindow/icon.bmp"));
	initTitleI18n();
	setObjectName("Mainview");

	// Allows for precise FPS control
	setViewportUpdateMode(QGraphicsView::NoViewportUpdate);
	setFrameShape(QFrame::NoFrame);
	setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	setFocusPolicy(Qt::StrongFocus);
	connect(this, SIGNAL(screenshotRequested()), this, SLOT(doScreenshot()));

	lastEventTimeSec = 0;


#if STEL_USE_NEW_OPENGL_WIDGETS
	// Primary test for OpenGL existence
	if (QSurfaceFormat::defaultFormat().majorVersion() < 2)
	{
		qWarning() << "No OpenGL 2 support on this system. Aborting.";
		QMessageBox::critical(0, "Stellarium", q_("No OpenGL 2 found on this system. Please upgrade hardware or use MESA or an older version."), QMessageBox::Abort, QMessageBox::Abort);
		exit(0);
	}

	//QSurfaceFormat format();
	//// TBD: What options shall be default?
	//QSurfaceFormat::setDefaultFormat(format);
	////QOpenGLContext* context=new QOpenGLContext::create();
	glWidget = new StelQOpenGLWidget(this);
	//glWidget->setFormat(format);
#else
	// Primary test for OpenGL existence
	if (QGLFormat::openGLVersionFlags() < QGLFormat::OpenGL_Version_2_1)
	{
		qWarning() << "No OpenGL 2.1 support on this system. Aborting.";
		QMessageBox::critical(0, "Stellarium", q_("No OpenGL 2 found on this system. Please upgrade hardware or use MESA or an older version."), QMessageBox::Abort, QMessageBox::Abort);
		exit(1);
	}

	// Create an openGL viewport
	QGLFormat glFormat(QGL::StencilBuffer | QGL::DepthBuffer | QGL::DoubleBuffer);
	// Even if setting a version here, it is ignored in StelQGLWidget()!
	// TBD: Maybe this must make a differentiation between OpenGL and OpenGL ES!
	// glFormat.setVersion(2, 1);
	QGLContext* context=new QGLContext(glFormat);

	if (context->format() != glFormat)
	{
		qWarning() << "Cannot provide OpenGL context. Apparently insufficient OpenGL resources on this system.";
		QMessageBox::critical(0, "Stellarium", q_("Cannot acquire necessary OpenGL resources."), QMessageBox::Abort, QMessageBox::Abort);
		exit(1);
	}
	glWidget = new StelQGLWidget(context, this);
	// This does not return the version number set previously!
	// qDebug() << "glWidget.context.format.version, result:" << glWidget->context()->format().majorVersion() << "." << glWidget->context()->format().minorVersion();
#endif

	setViewport(glWidget);

	setScene(new QGraphicsScene(this));
	scene()->setItemIndexMethod(QGraphicsScene::NoIndex);
	rootItem = new QGraphicsWidget();
	rootItem->setFocusPolicy(Qt::NoFocus);

	// Workaround (see Bug #940638) Although we have already explicitly set
	// LC_NUMERIC to "C" in main.cpp there seems to be a bug in OpenGL where
	// it will silently reset LC_NUMERIC to the value of LC_ALL during OpenGL
	// initialization. This has been observed on Ubuntu 11.10 under certain
	// circumstances, so here we set it again just to be on the safe side.
	setlocale(LC_NUMERIC, "C");
	// End workaround
}
YigNetworkChannelView::YigNetworkChannelView(QWidget *parent) :
    QGraphicsView(parent)
{

    QGLFormat glFormat( QGL::SampleBuffers );
    //glFormat.setSwapInterval( 1 ); // set VSync
    QGLWidget* viewportGL = new QGLWidget( glFormat );
    setViewportUpdateMode( QGraphicsView::FullViewportUpdate );
    setViewport(viewportGL);
    setRenderHints(QPainter::Antialiasing);
    setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing, true);
    YigGraphicsScene* yigScene = new YigGraphicsScene;
    yigScene->setSceneRect(0, 0, 1920, 1200);
    setScene(yigScene);

    scaleFactor = 1.0;
    selectionRect = new QGraphicsRectItem( QRect( 0, 0, 0, 0 ) );
    selectionRect->setPen( QColor( 0, 0, 0, 200 ) );
    selectionRect->setFlag(QGraphicsItem::ItemIgnoresTransformations);
    //selectionRect->setBrush( QColor( 69, 139, 19, 40 ) );
    QColor rectColor = YigColorKit::accent;
    rectColor.setAlpha(130);
    selectionRect->setBrush(rectColor);
    selectionRect->setZValue( 10000 );
    scene()->addItem( selectionRect );
    selectionRect->hide();

    //glWidget->startRendering();

    mActiveBool = false;
    setActiveView(mActiveBool);
    currentCableBool = false;
    mouseDownBool = false;
    cableCounter = 0;
    srand((unsigned) time(0));
    /*
#ifdef __APPLE__
    verticalScrollBar()->setStyle(new QMacStyle);
    horizontalScrollBar()->setStyle(new QMacStyle);
#else
    verticalScrollBar()->setStyle(new QGtkStyle);
    horizontalScrollBar()->setStyle(new QGtkStyle);
#endif
    */

    QPalette scrollPalette = verticalScrollBar()->palette();
    scrollPalette.setColor(QPalette::Button, YigColorKit::focus2);
    verticalScrollBar()->setPalette(scrollPalette);

    scrollPalette = horizontalScrollBar()->palette();
    scrollPalette.setColor(QPalette::Button, YigColorKit::focus2);
    horizontalScrollBar()->setPalette(scrollPalette);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);

    /*
    QLinearGradient gradient(0, 0, 0, parent->geometry().height());
    gradient.setColorAt(0, YigColorKit::background2);
    gradient.setColorAt(0.005, QColor(255, 255, 255));
    gradient.setColorAt(1, QColor(190, 190, 190));
    gradient.setInterpolationMode(QGradient::ColorInterpolation);
    QBrush backgroundBrush(gradient);
    backgroundBrush.setStyle(Qt::LinearGradientPattern);*/
    //QBrush backgroundBrush(QPixmap(":/images/gui/YigAttractorBackground.png"));
    //scene()->setBackgroundBrush(YigColorKit::background);
    //backgroundPixmap = scene()->addPixmap(YigAttractor::renderAttractor(width(), height()));
    modCableParent = new QGraphicsLineItem();
    modCableParent->setZValue(-20);
    modCableParent->setFlag(QGraphicsItem::ItemHasNoContents, true);
    //modCableParent->setVisible(false);
    scene()->addItem(modCableParent);
    audioCableParent = new QGraphicsLineItem();
    audioCableParent->setZValue(-5);
    //audioCableParent->setVisible(false);
    audioCableParent->setFlag(QGraphicsItem::ItemHasNoContents, true);
    scene()->addItem(audioCableParent);
    /*
    QObject::connect(this, SIGNAL(synthForGLAdded(int,QPointF)),
                     glWidget->getGLThread(), SLOT(addSynth(int,QPointF)), Qt::QueuedConnection);
    QObject::connect(this, SIGNAL(synthForGLRemoved(int)), glWidget->getGLThread(), SLOT(removeSynth(int)), Qt::QueuedConnection);
    QObject::connect(this, SIGNAL(synthForGLMoved(int,QPointF)),
                     glWidget->getGLThread(), SLOT(setSynthPos(int,QPointF)), Qt::QueuedConnection);

    */

    //glWidget.lower();

    //setupViewport(&glWidget);

    //scene()->setBackgroundBrush(Qt::transparent);
    //setAttribute(Qt::WA_TranslucentBackground);
    //setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
    //QPalette p = viewport()->palette();
    //p.setColor(QPalette::Base, Qt::transparent);
    //viewport()->setPalette(p);
    //viewport()->setAutoFillBackground(false);
    //parent->setAttribute(Qt::WA_TranslucentBackground);
    //parent->setAutoFillBackground(false);
    //setStyleSheet("background-color: transparent;");
    //lower();
    //glWidget.raise();
    //glWidget.lower();
    //glWidget.setStyleSheet("background-color: transparent;");
    //glParent = new QWidget(parent);
    //glWidget.setParent(glParent);
    //glParent->lower();
    //glWidget.show();
    setActiveView(true);
    setMouseTracking(true);
    setFrameStyle(0);
    mouseCounter = 0;
    centerOn(0, 0);
    show();
}