Пример #1
0
void *QGLContext::chooseVisual()
{
    static int bufDepths[] = { 8, 4, 2, 1 };	// Try 16, 12 also?
    //todo: if pixmap, also make sure that vi->depth == pixmap->depth
    void* vis = 0;
    int i = 0;
    bool fail = FALSE;
    QGLFormat fmt = format();
    bool tryDouble = !fmt.doubleBuffer();  // Some GL impl's only have double
    bool triedDouble = FALSE;
    while( !fail && !( vis = tryVisual( fmt, bufDepths[i] ) ) ) {
	if ( !fmt.rgba() && bufDepths[i] > 1 ) {
	    i++;
	    continue;
	}
	if ( tryDouble ) {
	    fmt.setDoubleBuffer( TRUE );
	    tryDouble = FALSE;
	    triedDouble = TRUE;
	    continue;
	}
	else if ( triedDouble ) {
	    fmt.setDoubleBuffer( FALSE );
	    triedDouble = FALSE;
	}
	if ( fmt.stereo() ) {
	    fmt.setStereo( FALSE );
	    continue;
	}
	if ( fmt.accum() ) {
	    fmt.setAccum( FALSE );
	    continue;
	}
	if ( fmt.stencil() ) {
	    fmt.setStencil( FALSE );
	    continue;
	}
	if ( fmt.alpha() ) {
	    fmt.setAlpha( FALSE );
	    continue;
	}
	if ( fmt.depth() ) {
	    fmt.setDepth( FALSE );
	    continue;
	}
	if ( fmt.doubleBuffer() ) {
	    fmt.setDoubleBuffer( FALSE );
	    continue;
	}
	fail = TRUE;
    }
    glFormat = fmt;
    return vis;
}
Пример #2
0
const QGLFormat GLFormat::asQGLFormat() const
{
    QGLFormat format;

    format.setVersion(m_majorVersion, m_minorVersion);
    
    switch(m_profile)
    {
    default:
    case NoProfile:
        format.setProfile(QGLFormat::NoProfile); 
        break;
    case CoreProfile:
        format.setProfile(QGLFormat::CoreProfile); 
        break;
    case CompatibilityProfile:
        format.setProfile(QGLFormat::CompatibilityProfile); 
        break;
    };

    format.setRedBufferSize    (m_redBufferSize);
    format.setGreenBufferSize  (m_greenBufferSize);
    format.setBlueBufferSize   (m_blueBufferSize);
    format.setAlphaBufferSize  (m_alphaBufferSize);

    format.setDepthBufferSize  (m_depthBufferSize);
    format.setStencilBufferSize(m_stencilBufferSize);
    format.setDoubleBuffer     (m_doubleBuffer);
    format.setStereo           (m_stereo);
    format.setSampleBuffers    (m_sampleBuffers);
    format.setSamples          (m_samples);
    format.setSwapInterval     (m_swapInterval);

    return format;
}
Пример #3
0
int main(int argc, char** argv)
{
  char *flnm;

  QApplication application(argc,argv);
  
  QGLFormat glFormat;
  glFormat.setSampleBuffers(true);
  glFormat.setDoubleBuffer(true);
  glFormat.setRgba(true);
  glFormat.setAlpha(true);

//  //-----------------------------
//  // did not work - still getting 8bit buffers
//  glFormat.setAlphaBufferSize(16);
//  glFormat.setRedBufferSize(16);
//  glFormat.setGreenBufferSize(16);
//  glFormat.setBlueBufferSize(16);
//  //-----------------------------

  flnm = argv[1];
  if (QString::compare(argv[1], "-stereo", Qt::CaseInsensitive) == 0)
    {
      flnm = argv[2];
      glFormat.setStereo(true);
    }
  QGLFormat::setDefaultFormat(glFormat);

  MainWindow mainwindow;
  mainwindow.show();
  
  // Run main loop.
  return application.exec();
}
Пример #4
0
QPixmap QGLWidget::renderPixmap( int w, int h, bool useContext )
{
    QPixmap nullPm;
    QSize sz = size();
    if ( (w > 0) && (h > 0) )
	sz = QSize( w, h );
    QPixmap pm( sz );
    glcx->doneCurrent();
    bool success = TRUE;

    if ( useContext && isValid() && renderCxPm( &pm ) )
	return pm;

    QGLFormat fmt = format();
    fmt.setDirectRendering( FALSE );		// No direct rendering
    fmt.setDoubleBuffer( FALSE );		// We don't need dbl buf
    QGLContext* pcx = new QGLContext( fmt, &pm );
    QGLContext* ocx = (QGLContext*)context();
    setContext( pcx, 0, FALSE );
    if ( pcx->isValid() )
	updateGL();
    else
	success = FALSE;
    setContext( ocx );				// Will delete pcx

    if ( success )
	return pm;
    else
	return nullPm;
}
Пример #5
0
//! [0]
GLWidgetShader::GLWidgetShader(QWidget *parent)
    : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
    glEnable(GL_MULTISAMPLE);

    // Important to enable the shaders
    QGLFormat rgbaformat;
    rgbaformat.setRgba(true);
    rgbaformat.setSampleBuffers(true);
    rgbaformat.setDoubleBuffer(true);
    rgbaformat.setSamples(4);
    rgbaformat.setOverlay(0);
    this->setFormat(rgbaformat);
    this->makeCurrent();
    // Very important
    this->setAutoFillBackground(false);

    QTimer *timer = new QTimer(this);
    timer->start(15);
    timer->setInterval(15);
    QObject::connect(timer,SIGNAL(timeout()),this,SLOT(repaint()));

    this->isDrawing=false;
    qglClearColor(Qt::white);
    this->nVertices = 0;
}
Пример #6
0
/*===========================================================================*/
void ScreenBase::create()
{
    KVS_ASSERT( m_id == -1 );

    // Initialize display mode.
    QGLFormat f = QGLFormat::defaultFormat();
    f.setDoubleBuffer( displayFormat().doubleBuffer() );
    f.setRgba( displayFormat().colorBuffer() );
    f.setDepth( displayFormat().depthBuffer() );
    f.setAccum( displayFormat().accumulationBuffer() );
    f.setStencil( displayFormat().stencilBuffer() );
    f.setStereo( displayFormat().stereoBuffer() );
    f.setSampleBuffers( displayFormat().multisampleBuffer() );
    f.setAlpha( displayFormat().alphaChannel() );
    QGLFormat::setDefaultFormat( f );

    // Set screen geometry.
    QWidget::setGeometry( BaseClass::x(), BaseClass::y(), BaseClass::width(), BaseClass::height() );

    QGLWidget::makeCurrent();

    // Initialize GLEW.
    GLenum result = glewInit();
    if ( result != GLEW_OK )
    {
        const GLubyte* message = glewGetErrorString( result );
        kvsMessageError( "GLEW initialization failed: %s.", message );
    }

    // Create window.
    static int counter = 0;
    m_id = counter++;
}
Пример #7
0
QT_BEGIN_NAMESPACE

QGLFormat QGLFormat::fromPlatformWindowFormat(const QPlatformWindowFormat &format)
{
    QGLFormat retFormat;
    retFormat.setAccum(format.accum());
    if (format.accumBufferSize() >= 0)
        retFormat.setAccumBufferSize(format.accumBufferSize());
    retFormat.setAlpha(format.alpha());
    if (format.alphaBufferSize() >= 0)
        retFormat.setAlphaBufferSize(format.alphaBufferSize());
    if (format.blueBufferSize() >= 0)
        retFormat.setBlueBufferSize(format.blueBufferSize());
    retFormat.setDepth(format.depth());
    if (format.depthBufferSize() >= 0)
        retFormat.setDepthBufferSize(format.depthBufferSize());
    retFormat.setDirectRendering(format.directRendering());
    retFormat.setDoubleBuffer(format.doubleBuffer());
    if (format.greenBufferSize() >= 0)
        retFormat.setGreenBufferSize(format.greenBufferSize());
    if (format.redBufferSize() >= 0)
        retFormat.setRedBufferSize(format.redBufferSize());
    retFormat.setRgba(format.rgba());
    retFormat.setSampleBuffers(format.sampleBuffers());
    retFormat.setSamples(format.sampleBuffers());
    retFormat.setStencil(format.stencil());
    if (format.stencilBufferSize() >= 0)
        retFormat.setStencilBufferSize(format.stencilBufferSize());
    retFormat.setStereo(format.stereo());
    retFormat.setSwapInterval(format.swapInterval());
    return retFormat;
}
Пример #8
0
QT_BEGIN_NAMESPACE

/*!
    Returns an OpenGL format for the window format specified by \a format.
*/
QGLFormat QGLFormat::fromSurfaceFormat(const QSurfaceFormat &format)
{
    QGLFormat retFormat;
    if (format.alphaBufferSize() >= 0)
        retFormat.setAlphaBufferSize(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.depthBufferSize() >= 0)
        retFormat.setDepthBufferSize(format.depthBufferSize());
    if (format.samples() > 1) {
        retFormat.setSampleBuffers(format.samples());
        retFormat.setSamples(true);
    }
    if (format.stencilBufferSize() > 0) {
        retFormat.setStencil(true);
        retFormat.setStencilBufferSize(format.stencilBufferSize());
    }
    retFormat.setDoubleBuffer(format.swapBehavior() != QSurfaceFormat::SingleBuffer);
    retFormat.setStereo(format.stereo());
    return retFormat;
}
Пример #9
0
bool wzMainScreenSetup(int antialiasing, bool fullscreen, bool vsync, bool highDPI)
{
	debug(LOG_MAIN, "Qt initialization");
	//QGL::setPreferredPaintEngine(QPaintEngine::OpenGL); // Workaround for incorrect text rendering on many platforms, doesn't exist in Qt5…

	// Register custom WZ app event type
	wzAppQEventType = QEvent::registerEventType();

	// Setting up OpenGL
	QGLFormat format;
	format.setDoubleBuffer(true);
	//format.setAlpha(true);
	int w = pie_GetVideoBufferWidth();
	int h = pie_GetVideoBufferHeight();

	if (antialiasing)
	{
		format.setSampleBuffers(true);
		format.setSamples(antialiasing);
	}
	mainWindowPtr = new WzMainWindow(QSize(w, h), format, wzAppQEventType.load());
	WzMainWindow &mainwindow = *(mainWindowPtr.load());
	mainwindow.setMinimumResolution(QSize(800, 600));
	if (!mainwindow.context()->isValid())
	{
		QMessageBox::critical(nullptr, "Oops!", "Warzone2100 failed to create an OpenGL context. This probably means that your graphics drivers are out of date. Try updating them!");
		return false;
	}

	screenWidth = w;
	screenHeight = h;
	if (fullscreen)
	{
		mainwindow.resize(w, h);
		mainwindow.showFullScreen();
		if (w > mainwindow.width())
		{
			w = mainwindow.width();
		}
		if (h > mainwindow.height())
		{
			h = mainwindow.height();
		}
		pie_SetVideoBufferWidth(w);
		pie_SetVideoBufferHeight(h);
	}
	else
	{
		mainwindow.show();
		mainwindow.setMinimumSize(w, h);
		mainwindow.setMaximumSize(w, h);
	}

	mainwindow.setSwapInterval(vsync);
	mainwindow.setReadyToPaint();

	return true;
}
Пример #10
0
bool wzMain2()
{
	debug(LOG_MAIN, "Qt initialization");
	QGL::setPreferredPaintEngine(QPaintEngine::OpenGL); // Workaround for incorrect text rendering on nany platforms.

	// Setting up OpenGL
	QGLFormat format;
	format.setDoubleBuffer(true);
	format.setAlpha(true);
	int w = pie_GetVideoBufferWidth();
	int h = pie_GetVideoBufferHeight();

	if (war_getFSAA())
	{
		format.setSampleBuffers(true);
		format.setSamples(war_getFSAA());
	}
	mainWindowPtr = new WzMainWindow(QSize(w, h), format);
	WzMainWindow &mainwindow = *mainWindowPtr;
	mainwindow.setMinimumResolution(QSize(800, 600));
	if (!mainwindow.context()->isValid())
	{
		QMessageBox::critical(NULL, "Oops!", "Warzone2100 failed to create an OpenGL context. This probably means that your graphics drivers are out of date. Try updating them!");
		return false;
	}

	screenWidth = w;
	screenHeight = h;
	if (war_getFullscreen())
	{
		mainwindow.resize(w,h);
		mainwindow.showFullScreen();
		if(w>mainwindow.width()) {
			w = mainwindow.width();
		}
		if(h>mainwindow.height()) {
			h = mainwindow.height();
		}
		pie_SetVideoBufferWidth(w);
		pie_SetVideoBufferHeight(h);
	}
	else
	{
		mainwindow.show();
		mainwindow.setMinimumSize(w, h);
		mainwindow.setMaximumSize(w, h);
	}

	mainwindow.setSwapInterval(war_GetVsync());
	war_SetVsync(mainwindow.swapInterval() > 0);

	mainwindow.setReadyToPaint();

	return true;
}
QGLFormat QtCanvas::getQGLFormat(const Buffers buffers) {
    QGLFormat format = QGLFormat();
    format.setAlpha(buffers & GLCanvas::ALPHA_BUFFER);
    format.setDepth(buffers & GLCanvas::DEPTH_BUFFER);
    format.setDoubleBuffer(buffers & GLCanvas::DOUBLE_BUFFER);
    format.setStencil(buffers & GLCanvas::STENCIL_BUFFER);
    format.setAccum(buffers & GLCanvas::ACCUM_BUFFER);
    format.setStereo(buffers & GLCanvas::STEREO_VIEWING);
    format.setSampleBuffers(buffers & GLCanvas::MULTISAMPLING);

    return format;
}
Пример #12
0
OScene::OScene(QWidget *parent, QGLWidget *sharewidget):
    QGLWidget(parent,sharewidget)
{
    QGLFormat fmt;
    fmt.setDoubleBuffer(true);
    this->setFormat(fmt);
    this->setAutoBufferSwap(true);
    qsrand(QTime::currentTime().second());
    generateMap();
    connect(&timer,SIGNAL(timeout()),this,SLOT(lifeperiod()));
    timer.start(2000);
}
	SceneDisplayerWidget::SceneDisplayerWidget(QWidget *parent, const std::string &mapEditorPath) :
			QGLWidget(parent),
			mapEditorPath(mapEditorPath),
			sceneDisplayer(nullptr)
	{
		QGLFormat glFormat;
		glFormat.setVersion(3,3);
		glFormat.setProfile(QGLFormat::CompatibilityProfile);
		glFormat.setSampleBuffers(true);
		glFormat.setDoubleBuffer(true);
		setFormat(glFormat);
	}
Пример #14
0
void XyzWindow::CreateXYZView()
{
	QFrame *XyFrame;
	QFrame *XzFrame;
	QFrame *ZyFrame;
	QWidget *centralWidget;
	
	centralWidget = new QWidget(this);
	QPalette palette;
	palette.setColor(QPalette::Background , QColor(/*200,200,200*/167, 210, 200));
	centralWidget->setAutoFillBackground(true);
	centralWidget->setPalette(palette);
	
	XzFrame = new QFrame(centralWidget);
	XzFrame->setGeometry(QRect(mXorigin1,mYorigin1 , mx+2*FRAM_BORDER , mz+2*FRAM_BORDER));
	XzFrame->setFrameShape(QFrame::StyledPanel);
	XzFrame->setFrameShadow(QFrame::Raised);
	ZyFrame = new QFrame(centralWidget);
	ZyFrame->setGeometry(QRect(mXorigin2 , mYorigin2 , mz+2*FRAM_BORDER ,my+2*FRAM_BORDER));
	ZyFrame->setFrameShape(QFrame::StyledPanel);
	ZyFrame->setFrameShadow(QFrame::Raised);
	XyFrame = new QFrame(centralWidget);
	XyFrame->setGeometry(QRect(mXorigin1 , mYorigin2 , mx+2*FRAM_BORDER  ,my+2*FRAM_BORDER));
	XyFrame->setFrameShape(QFrame::StyledPanel);
	XyFrame->setFrameShadow(QFrame::Raised);
	
	
	palette.setColor(QPalette::Background , QColor(255,0,0));
	XzFrame->setAutoFillBackground(true);
	XzFrame->setPalette(palette);
	ZyFrame->setAutoFillBackground(true);
	ZyFrame->setPalette(palette);
	XyFrame->setAutoFillBackground(true);
	XyFrame->setPalette(palette);
	setCentralWidget(centralWidget);
	
	QGLFormat glFormat;
	glFormat.setRgba(true);
	glFormat.setDoubleBuffer(true);
	glFormat.setDepth(true);
	mXY_GLw = new XyzGL(glFormat , XY_VIEW , XyFrame , this);
	mXY_GLw->setGeometry(FRAM_BORDER , FRAM_BORDER,mx,my);
	mXY_GLw->setAttribute(Qt::WA_DeleteOnClose);
	
	mXZ_GLw = new XyzGL(glFormat , XZ_VIEW , XzFrame , this);
	mXZ_GLw->setGeometry(FRAM_BORDER , FRAM_BORDER , mx ,mz);
	mXZ_GLw->setAttribute(Qt::WA_DeleteOnClose);
	
	mYZ_GLw = new XyzGL(glFormat , ZY_VIEW , ZyFrame , this);
	mYZ_GLw->setGeometry(FRAM_BORDER , FRAM_BORDER ,mz ,my);
	mYZ_GLw->setAttribute(Qt::WA_DeleteOnClose);
}
Пример #15
0
glViewer::glViewer(QWidget *parent, int Width, int Height):QGLWidget(parent)
{
    QGLFormat format;
    format.setDoubleBuffer(true);
    format.setSampleBuffers(true);
    format.setSamples(32);
    format.setDirectRendering(true);
    setFormat(format);
    //glEnable();
    //setAutoFillBackground(true);
    setFixedSize(Width, Height);
    move(0,0);
}
TextureDefinitionEditor::TextureDefinitionEditor(QWidget* parent,const QGLWidget*  shareWidget, Qt::WindowFlags f) : QWidget(parent)
{
    level = NULL;
    texList = NULL;
    texDefsView = new QTableView(this);
    texDefsModel = new TextureDefinitionList(NULL,this);
    texDefsView->setModel(texDefsModel);
    texDefsView->setColumnWidth(0,80);
    texDefsView->setColumnWidth(1,60);
    texDefsView->setColumnWidth(2,50);
    texDefsView->setColumnWidth(3,50);
    texDefsView->setColumnWidth(4,50);
    texDefsView->setColumnWidth(5,50);
    texDefsView->setMaximumWidth(400);
    texDefsView->setContextMenuPolicy(Qt::CustomContextMenu);
    texDefsView->setSelectionMode(QAbstractItemView::SingleSelection);

    selection = -1;

    deleteAction = new QAction(tr("Delete entry"),this);
    insertAction = new QAction(tr("Insert new entry"),this);
    contextmenu = new QMenu(this);
    contextmenu->addAction(deleteAction);
    contextmenu->addAction(insertAction);

    QGLFormat form;
    form.setDoubleBuffer(true);
    overlayedTex = new OverlayedTexture(form,this,shareWidget,f);
    overlayedTex->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);

    QGridLayout* layout = new QGridLayout();
    layout->addWidget(overlayedTex,0,0);
    layout->addWidget(texDefsView,0,1);
    setLayout(layout);

    keyFilter = new KeypressFilter(this);
    filterDelegate = new EventFilterDelegate(this);
    filterDelegate->setEventFilterToApply(keyFilter);
    texDefsView->installEventFilter(keyFilter);
    texDefsView->setItemDelegate(filterDelegate);

    loadSettings();

    connect(deleteAction, SIGNAL(triggered()), this, SLOT(deletePositionEntry()));
    connect(insertAction, SIGNAL(triggered()), this, SLOT(insertPositionEntry()));
    connect(overlayedTex, SIGNAL(overlayRectChanged(int,int,int,int)),this, SLOT(positionChanged(int,int,int,int)));
    connect(texDefsView, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(doViewContext(const QPoint&)));
    connect(texDefsView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),this,SLOT(selectionChanged(const QItemSelection&, const QItemSelection&)));
    connect(texDefsModel,SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)),this,SLOT(updateTexture(const QModelIndex&,const QModelIndex&)));
};
Пример #17
0
void GLShaderDev::initializeContext()
{
    QGLFormat glFormat;

    glFormat.setVersion(4, 2);
    glFormat.setProfile(QGLFormat::CompatibilityProfile);
    glFormat.setSampleBuffers(true); // NOTE this option activates MSAA
    glFormat.setDoubleBuffer(true);

    _glpreview = new GLPreviewWidget(glFormat);
    _glwidget = _glpreview->getGLWidget();

    connect(_glwidget, SIGNAL(glInitialized()), this, SLOT(initGLInfo()));
}
Пример #18
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    // Register QML bindings fo DrumEngine and TouchEvents
#ifdef Q_OS_SYMBIAN
    qmlRegisterType<DrumEngine>("DrumEngine", 1,0, "DrumEngine");
#endif
    qmlRegisterType<TouchEvents>("TouchEvents", 1,0, "TouchEvents");

    QmlViewer viewer;
    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);

    // Check for VGA resolution and inform QML. Needed for some
    // gfx layouting on on Symbian devices with VGA resolution (E6).
    QDesktopWidget *desktop = QApplication::desktop();
    const QRect screenRect = desktop->screenGeometry();
    QDeclarativeContext* context = viewer.rootContext();
    if (screenRect.width() == 640 && screenRect.height() == 480) {
        context->setContextProperty("screenVGA", true);
    } else {
        context->setContextProperty("screenVGA", false);
    }

    // Provide information whether running in simulator. Used in Pad.qml.
#ifdef QT_SIMULATOR
    context->setContextProperty("simulator", true);
#else
    context->setContextProperty("simulator", false);
#endif

    // Select the main.qml according to platform.
#ifdef Q_OS_SYMBIAN
    viewer.setMainQmlFile(QLatin1String("qml/symbian/main.qml"));
#else
    viewer.setMainQmlFile(QLatin1String("qml/harmattan/main.qml"));
#endif

    // Enable OpenGL rendering
    QGLFormat fmt = QGLFormat::defaultFormat();
    fmt.setDirectRendering(true);
    fmt.setDoubleBuffer(true);
    QGLWidget *glWidget = new QGLWidget(fmt);
    viewer.setViewport(glWidget);
    viewer.showFullScreen();

    return app.exec();
}
Пример #19
0
void TDisplay::initializeGL() {

    QGLFormat format;
    format.setDoubleBuffer(false);
    format.setSampleBuffers(true);
    setFormat(format);

    glEnable(GL_MULTISAMPLE);
    glEnable(GL_LIGHT1);
    glEnable(GL_LIGHTING);
    glEnable(GL_NORMALIZE);

    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
Пример #20
0
Viewer::Viewer(string innermodelMap, QWidget *p)
{
	innermodel = new InnerModel(innermodelMap);

	QGLFormat fmt;
	fmt.setDoubleBuffer(true);
	QGLFormat::setDefaultFormat(fmt);
	world3D = new OsgView(p);
	world3D->init();

	innermodelviewer = new InnerModelViewer(innermodel, "root", world3D->getRootGroup());

	world3D->getRootGroup()->addChild(innermodelviewer);
	world3D->show();
	world3D->setHomePosition(osg::Vec3(0,0,0),osg::Vec3(0.f,0.,-4000.),osg::Vec3(0.0f,1000.f,0.0f), false);

	innermodelmanager = new InnerModelManager(innermodel, innermodelviewer);
}
Пример #21
0
int main(int argc, char **argv)
{
    QGLFormat fmt;
    fmt.setRgba(true);
    fmt.setAlpha(true);
    fmt.setDepth(true);
    fmt.setDoubleBuffer(true);
    QGLFormat::setDefaultFormat(fmt);

    QApplication app(argc, argv);

    MainWindow window;
    window.showMaximized();

    for (int i = 1; i < argc; i++)
        window.objectSet()->loadFile(argv[i]);

    return app.exec();
}
Пример #22
0
TwoDFrame::TwoDFrame( QWidget * parent, Qt::WFlags f ) :
	QFrame(parent, f) {
	
	setFocusPolicy(Qt::StrongFocus);
	 // Create our OpenGL widget.  
	QGLFormat fmt;
	fmt.setAlpha(true);
	fmt.setRgba(true);
	fmt.setDoubleBuffer(true);
	fmt.setDirectRendering(true);
    glTwoDWindow = new GLTwoDWindow(fmt, this, "gltwoDwindow", this);
	if (!(fmt.directRendering() && fmt.rgba() && fmt.alpha() && fmt.doubleBuffer())){
		Params::BailOut("Unable to obtain required OpenGL rendering format",__FILE__,__LINE__);	
	}
	QHBoxLayout* flayout = new QHBoxLayout( this);
    flayout->addWidget( glTwoDWindow, 1 );
	twoDParams = 0;
	isDataWindow = true;

}
Пример #23
0
// Updates "format" with the parameters of the selected configuration.
void qt_glformat_from_eglconfig(QGLFormat& format, const EGLConfig config)
{
    EGLint redSize     = 0;
    EGLint greenSize   = 0;
    EGLint blueSize    = 0;
    EGLint alphaSize   = 0;
    EGLint depthSize   = 0;
    EGLint stencilSize = 0;
    EGLint sampleCount = 0;
    EGLint level       = 0;

    EGLDisplay display = QEgl::display();
    eglGetConfigAttrib(display, config, EGL_RED_SIZE,     &redSize);
    eglGetConfigAttrib(display, config, EGL_GREEN_SIZE,   &greenSize);
    eglGetConfigAttrib(display, config, EGL_BLUE_SIZE,    &blueSize);
    eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE,   &alphaSize);
    eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE,   &depthSize);
    eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &stencilSize);
    eglGetConfigAttrib(display, config, EGL_SAMPLES,      &sampleCount);
    eglGetConfigAttrib(display, config, EGL_LEVEL,        &level);

    format.setRedBufferSize(redSize);
    format.setGreenBufferSize(greenSize);
    format.setBlueBufferSize(blueSize);
    format.setAlphaBufferSize(alphaSize);
    format.setDepthBufferSize(depthSize);
    format.setStencilBufferSize(stencilSize);
    format.setSamples(sampleCount);
    format.setPlane(level);
    format.setDirectRendering(true); // All EGL contexts are direct-rendered
    format.setRgba(true);            // EGL doesn't support colour index rendering
    format.setStereo(false);         // EGL doesn't support stereo buffers
    format.setAccumBufferSize(0);    // EGL doesn't support accululation buffers
    format.setDoubleBuffer(true);    // We don't support single buffered EGL contexts

    // Clear the EGL error state because some of the above may
    // have errored out because the attribute is not applicable
    // to the surface type.  Such errors don't matter.
    eglGetError();
}
Пример #24
0
void SimObjectWidget::exportAsImage(int resolution)
{
  int width = resolution >> 16;
  int height = resolution & 0xffff;

  QSettings& settings = CoreModule::application->getSettings();
  QString fileName = QFileDialog::getSaveFileName(this,
    tr("Export as Image"), settings.value("ExportDirectory", "").toString(), tr("Portable Network Graphic (*.png)"));
  if(fileName.isEmpty())
    return;
  settings.setValue("ExportDirectory", QFileInfo(fileName).dir().path());

  QImage image;
  {
    unsigned int winWidth, winHeight;
    objectRenderer.getSize(winWidth, winHeight);

    // render object using a temporary widget
    QGLFormat format = this->format();
    format.setDoubleBuffer(false);
    QGLWidget widget(format, 0, 0, Qt::CustomizeWindowHint);
#ifdef OSX
    widget.setWindowOpacity(0.f);
    widget.show();
#endif
    widget.setMaximumSize(width, height);
    widget.resize(width, height);
    widget.makeCurrent();
    objectRenderer.resize(fovy, width, height);
    objectRenderer.init(false);
    objectRenderer.draw();
    image = widget.grabFrameBuffer();

    makeCurrent();
    objectRenderer.resize(fovy, winWidth, winHeight);
  }

  image.save(fileName);
}
Пример #25
0
/**
 * Constructor.
 */
CQGLViewport::CQGLViewport(QWidget* pParent, Qt::WFlags f):
    QFrame(pParent, f)
    , mpVerticalScrollbar(new QScrollBar(Qt::Vertical, NULL))
    , mpHorizontalScrollbar(new QScrollBar(Qt::Horizontal, NULL))
    , mpNetworkPainter(NULL)
{
  QVBoxLayout* pVBoxLayout = new QVBoxLayout();
  this->setLayout(pVBoxLayout);
  QFrame* pHBox = new QFrame(this);
  pHBox->setLayout(new QHBoxLayout());
  pVBoxLayout->addWidget(pHBox);
  QGLFormat format;
  format.setDoubleBuffer(TRUE);
  this->mpNetworkPainter = new CQGLNetworkPainter(format, pHBox);
  pHBox->layout()->addWidget(this->mpNetworkPainter);
  pHBox->layout()->addWidget(this->mpVerticalScrollbar);
  this->mpVerticalScrollbar->setSingleStep(1);
  pVBoxLayout->addWidget(this->mpHorizontalScrollbar);
  this->mpHorizontalScrollbar->setSingleStep(1);
  connect(this->mpVerticalScrollbar, SIGNAL(valueChanged(int)), this, SLOT(slotVValueChanged(int)));
  connect(this->mpHorizontalScrollbar, SIGNAL(valueChanged(int)), this, SLOT(slotHValueChanged(int)));
}
Пример #26
0
    void GridsPlugin::initDockWidget()
    {
        // create and add doc widget
        _dock_widget = new QDockWidget(QObject::tr("Grid Viewer"));
        _dock_widget->setAllowedAreas(Qt::RightDockWidgetArea);
        _dock_widget->setObjectName("gridViewerDock");

        QGLFormat format;
        format.setVersion(2, 1);
        format.setDoubleBuffer(true);
        format.setDepth(true);
        format.setRgba(true);
        format.setAlpha(false);
        format.setAccum(false);
        format.setStencil(false);
        format.setStereo(false);
        format.setDirectRendering(true);
        format.setOverlay(false);

        _viewer = new GridViewer(format);
        _viewer->setMinimumSize(250, 0);
        _viewer->setObjectName("gridViewer");

        QVBoxLayout *layout = new QVBoxLayout();
        layout->addWidget(_viewer);

        QWidget *widget = new QWidget();
        widget->setLayout(layout);

        _dock_widget->setWidget(widget);

        NeuroGui::MainWindow::instance()->addDockWidget(Qt::RightDockWidgetArea, _dock_widget);

        // add to view menu
        NeuroGui::MainWindow::instance()->toolBarsMenu()->addAction(_dock_widget->toggleViewAction());
    }
Пример #27
0
GLView * GLView::create( NifSkope * window )
{
	QGLFormat fmt;
	static QList<QPointer<GLView> > views;

	QGLWidget * share = nullptr;
	for ( const QPointer<GLView>& v : views ) {
		if ( v )
			share = v;
	}

	// All new windows after the first window will share a format
	if ( share ) {
		fmt = share->format();
	} else {
		fmt.setSampleBuffers( Options::antialias() );
	}
	
	// OpenGL version
	fmt.setVersion( 2, 1 );
	// Ignored if version < 3.2
	//fmt.setProfile(QGLFormat::CoreProfile);

	// V-Sync
	fmt.setSwapInterval( 1 );
	fmt.setDoubleBuffer( true );

	fmt.setSamples( Options::antialias() ? 16 : 0 );

	fmt.setDirectRendering( true );
	fmt.setRgba( true );

	views.append( QPointer<GLView>( new GLView( fmt, window, share ) ) );

	return views.last();
}
Пример #28
0
QGLGraphicsSystem::QGLGraphicsSystem(bool useX11GL)
    : QGraphicsSystem(), m_useX11GL(useX11GL)
{
#if defined(Q_WS_X11) && !defined(QT_OPENGL_ES)
    // only override the system defaults if the user hasn't already
    // picked a visual
    if (X11->visual == 0 && X11->visual_id == -1 && X11->visual_class == -1) {
        // find a double buffered, RGBA visual that supports OpenGL
        // and set that as the default visual for windows in Qt
        int i = 0;
        int spec[16];
        spec[i++] = GLX_RGBA;
        spec[i++] = GLX_DOUBLEBUFFER;

        if (!qgetenv("QT_GL_SWAPBUFFER_PRESERVE").isNull()) {
            spec[i++] = GLX_DEPTH_SIZE;
            spec[i++] = 8;
            spec[i++] = GLX_STENCIL_SIZE;
            spec[i++] = 8;
            spec[i++] = GLX_SAMPLE_BUFFERS_ARB;
            spec[i++] = 1;
            spec[i++] = GLX_SAMPLES_ARB;
            spec[i++] = 4;
        }

        spec[i++] = XNone;

        XVisualInfo *vi = glXChooseVisual(X11->display, X11->defaultScreen, spec);
        if (vi) {
            X11->visual_id = vi->visualid;
            X11->visual_class = vi->c_class;

            QGLFormat format;
            int res;
            glXGetConfig(X11->display, vi, GLX_LEVEL, &res);
            format.setPlane(res);
            glXGetConfig(X11->display, vi, GLX_DOUBLEBUFFER, &res);
            format.setDoubleBuffer(res);
            glXGetConfig(X11->display, vi, GLX_DEPTH_SIZE, &res);
            format.setDepth(res);
            if (format.depth())
                format.setDepthBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_RGBA, &res);
            format.setRgba(res);
            glXGetConfig(X11->display, vi, GLX_RED_SIZE, &res);
            format.setRedBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_GREEN_SIZE, &res);
            format.setGreenBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_BLUE_SIZE, &res);
            format.setBlueBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_ALPHA_SIZE, &res);
            format.setAlpha(res);
            if (format.alpha())
                format.setAlphaBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_ACCUM_RED_SIZE, &res);
            format.setAccum(res);
            if (format.accum())
                format.setAccumBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_STENCIL_SIZE, &res);
            format.setStencil(res);
            if (format.stencil())
                format.setStencilBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_STEREO, &res);
            format.setStereo(res);
            glXGetConfig(X11->display, vi, GLX_SAMPLE_BUFFERS_ARB, &res);
            format.setSampleBuffers(res);
            if (format.sampleBuffers()) {
                glXGetConfig(X11->display, vi, GLX_SAMPLES_ARB, &res);
                format.setSamples(res);
            }

            QGLWindowSurface::surfaceFormat = format;
            XFree(vi);

            printf("using visual class %x, id %x\n", X11->visual_class, X11->visual_id);
        }
    }
#elif defined(Q_WS_WIN)
    QGLWindowSurface::surfaceFormat.setDoubleBuffer(true);

    qt_win_owndc_required = true;
#endif
}
Пример #29
0
WaveformWidgetFactory::WaveformWidgetFactory() :
        m_type(WaveformWidgetType::Count_WaveformwidgetType),
        m_config(0),
        m_skipRender(false),
        m_frameRate(30),
        m_defaultZoom(3),
        m_zoomSync(false),
        m_overviewNormalized(false),
        m_openGLAvailable(false),
        m_openGLShaderAvailable(false),
        m_vsyncThread(NULL),
        m_frameCnt(0),
        m_actualFrameRate(0) {

    m_visualGain[All] = 1.5;
    m_visualGain[Low] = 1.0;
    m_visualGain[Mid] = 1.0;
    m_visualGain[High] = 1.0;

    if (QGLFormat::hasOpenGL()) {
        QGLFormat glFormat;
        glFormat.setDirectRendering(true);
        glFormat.setDoubleBuffer(true);
        glFormat.setDepth(false);
        // Disable waiting for vertical Sync
        // This can be enabled when using a single Threads for each QGLContext
        // Setting 1 causes QGLContext::swapBuffer to sleep until the next VSync
#if defined(__APPLE__)
        // On OS X, syncing to vsync has good performance FPS-wise and
        // eliminates tearing.
        glFormat.setSwapInterval(1);
#else
        // Otherwise, turn VSync off because it could cause horrible FPS on
        // Linux.
        // TODO(XXX): Make this configurable.
        // TOOD(XXX): What should we do on Windows?
        glFormat.setSwapInterval(0);
#endif


        glFormat.setRgba(true);
        QGLFormat::setDefaultFormat(glFormat);

        QGLFormat::OpenGLVersionFlags version = QGLFormat::openGLVersionFlags();

        int majorVersion = 0;
        int minorVersion = 0;
        if (version == QGLFormat::OpenGL_Version_None) {
            m_openGLVersion = "None";
        } else if (version & QGLFormat::OpenGL_Version_3_0) {
            majorVersion = 3;
        } else if (version & QGLFormat::OpenGL_Version_2_1) {
            majorVersion = 2;
            minorVersion = 1;
        } else if (version & QGLFormat::OpenGL_Version_2_0) {
            majorVersion = 2;
            minorVersion = 0;
        } else if (version & QGLFormat::OpenGL_Version_1_5) {
            majorVersion = 1;
            minorVersion = 5;
        } else if (version & QGLFormat::OpenGL_Version_1_4) {
            majorVersion = 1;
            minorVersion = 4;
        } else if (version & QGLFormat::OpenGL_Version_1_3) {
            majorVersion = 1;
            minorVersion = 3;
        } else if (version & QGLFormat::OpenGL_Version_1_2) {
            majorVersion = 1;
            minorVersion = 2;
        } else if (version & QGLFormat::OpenGL_Version_1_1) {
            majorVersion = 1;
            minorVersion = 1;
        }

        if (majorVersion != 0) {
            m_openGLVersion = QString::number(majorVersion) + "." +
                    QString::number(minorVersion);
        }

        m_openGLAvailable = true;

        QGLWidget* glWidget = new QGLWidget(); // create paint device
        // QGLShaderProgram::hasOpenGLShaderPrograms(); valgind error
        m_openGLShaderAvailable = QGLShaderProgram::hasOpenGLShaderPrograms(glWidget->context());
        delete glWidget;
    }

    evaluateWidgets();
    m_time.start();
}
Пример #30
0
int main(int argc, char *argv[])
{
    int i;
    const char *resPath = 0;
    char    override_base_file[MAX_STR_LEN] = "";
    int     override_local_port = 0;
    char    override_remote_host[MAX_STR_LEN] = "";
    int     override_remote_port = 0;
    char    configfile[MAX_STR_LEN] = "mume.ini";
    int     default_local_port = 3000;
    int     default_remote_port = 4242;
    int     mud_emulation = 0;

#ifdef Q_OS_MACX
    CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
    CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef,
						  kCFURLPOSIXPathStyle);
    const char *appPath = CFStringGetCStringPtr(macPath,
						CFStringGetSystemEncoding());
    resPath = (char *)malloc(strlen(appPath)+25);
    strcpy(resPath, appPath);
    strcat(resPath, "/Contents/Resources/");

    char    default_base_file[MAX_STR_LEN] = "mume.pmf";
    char    default_remote_host[MAX_STR_LEN] = "";
    strcpy(configfile, "configs/default.conf");

    CFRelease(pluginRef);
    CFRelease(macPath);

#else
    resPath = "";
    char    default_base_file[MAX_STR_LEN] = "mume.pmf";
    char    default_remote_host[MAX_STR_LEN] = "129.241.210.221";
#endif
    QApplication::setColorSpec( QApplication::CustomColor );
    QApplication app( argc, argv );

    QPixmap pixmap("images/logo.png");
    QSplashScreen *splash = new QSplashScreen(pixmap);
    splash->show();

    splash->showMessage("Loading configuration and database...");

    for (i=1; i < argc; i++) {

      if ((strcmp(argv[i], "--config") == 0) || ( strcmp(argv[i], "-c") == 0))
      {
        if (i == argc) {
          printf("Too few arguments. Missing config file name.\r\n");
          print_usage();
          exit(1);
        }
        i++;

        strcpy(configfile, argv[i]);
	resPath = ""; // obviously the user has an own config file - including the path
      }

      if ((strcmp(argv[i], "--emulate") == 0) || ( strcmp(argv[i], "-e") == 0))
      {
        printf("Pandora: Starting in MUD emulation mode.\r\n");
        mud_emulation = 1;
      }

      if ((strcmp(argv[i], "--base") == 0) || ( strcmp(argv[i], "-b") == 0))
      {
        if (i == argc) {
          printf("Too few arguments. Missing database.\r\n");
          print_usage();
          exit(1);
        }
        i++;
        strcpy(override_base_file, argv[i]); // overriding the database file is possible even with default config file
      }

      if ((strcmp(argv[i], "--hostname") == 0) || ( strcmp(argv[i], "-hn") == 0))
      {
        if (i == argc) {
          printf("Too few arguments. Wrong hostname given.\r\n");
          print_usage();
          exit(1);
        }
        i++;
        strcpy(override_remote_host, argv[i]);
      }

      if ((strcmp(argv[i], "--localport") == 0) || ( strcmp(argv[i], "-lp") == 0))
      {
        if (i == argc) {
          printf("Too few arguments. Missing localport.\r\n");
          print_usage();
          exit(1);
        }
        i++;
        override_local_port = atoi(argv[i]);
      }

      if ((strcmp(argv[i], "--remoteport") == 0) || ( strcmp(argv[i], "-rp") == 0))
      {
        if (i == argc) {
          printf("Too few arguments. Missing targetport.\r\n");
          print_usage();
          exit(1);
        }
        i++;
        override_remote_port = atoi(argv[i]);
      }


      if ((strcmp(argv[i], "--help") == 0) || ( strcmp(argv[i], "-h") == 0))
      {
        print_usage();
        exit(1);
      }

    }


    /* set analyzer engine defaults */
    //engine_init();
    splash->showMessage(QString("Loading the configuration ") + configfile);
    conf = new Cconfigurator();
    conf->loadConfig(resPath, configfile);
    print_debug(DEBUG_SYSTEM, "starting up...");


    if (override_base_file[0] != 0) {
      conf->setBaseFile(override_base_file);
    } else if ( conf->getBaseFile() == "") {
      conf->setBaseFile(default_base_file);
    }
    print_debug(DEBUG_SYSTEM, "Using database file : %s.", (const char*) conf->getBaseFile() );

    if (override_remote_host[0] != 0) {
      conf->setRemoteHost(override_remote_host);
    } else if ( conf->getRemoteHost().isEmpty() ) {
      conf->setRemoteHost(default_remote_host);
    }
    print_debug(DEBUG_SYSTEM, "Using target hostname : %s.", (const char*) conf->getRemoteHost() );

    if (override_local_port != 0) {
      conf->setLocalPort(override_local_port);
    } else if ( conf->getLocalPort() == 0) {
      conf->setLocalPort(default_local_port);
    }
    print_debug(DEBUG_SYSTEM, "Using local port : %i.", conf->getLocalPort());

    if (override_remote_port != 0) {
      conf->setRemotePort(override_remote_port);
    } else if (conf->getRemotePort() == 0) {
      conf->setRemotePort(default_remote_port);
    }
    print_debug(DEBUG_SYSTEM, "Using target port : %i.", conf->getRemotePort());

    conf->setConfigModified( false );

    splash->showMessage("Starting Analyzer and Proxy...");

    engine = new CEngine(new CRoomManager());
    proxy = new Proxy();

    /* special init for the mud emulation */
    if (mud_emulation) {
        print_debug(DEBUG_SYSTEM, "Starting in MUD emulation mode...");
        engine->initEmulationMode();
    }

    proxy->setMudEmulation( mud_emulation );


    print_debug(DEBUG_SYSTEM, "Starting renderer ...\n");

    if ( !QGLFormat::hasOpenGL() ) {
        qWarning( "This system has no OpenGL support. Quiting." );
        return -1;
    }

    QRect rect = app.desktop()->availableGeometry(-1);
    if (conf->getWindowRect().x() == 0 || conf->getWindowRect().x() >= rect.width() ||
        conf->getWindowRect().y() >= rect.height() ) {
        print_debug(DEBUG_SYSTEM && DEBUG_INTERFACE, "Autosettings for window size and position");
        int x, y, height, width;

        x = rect.width() / 3 * 2;
        y = 0;
        height = rect.height() / 3;
        width = rect.width() - x;

        conf->setWindowRect( x, y, width, height);
    }


    QGLFormat f = QGLFormat::defaultFormat();
    f.setDoubleBuffer( true );
    f.setDirectRendering( true );
    f.setRgba( true );
    f.setDepth( true );
    f.setAlpha( true );

    if (conf->getMultisampling())
   	f.setSampleBuffers( true );
    //f.setSamples(4);

    QGLFormat::setDefaultFormat( f );

    renderer_window = new CMainWindow;

    renderer_window->show();

    splash->finish(renderer_window);
    delete splash;

    proxy->start();
    QObject::connect(proxy, SIGNAL(startEngine()), engine, SLOT(slotRunEngine()), Qt::QueuedConnection );
    QObject::connect(proxy, SIGNAL(startRenderer()), renderer_window->renderer, SLOT(display()), Qt::QueuedConnection);

    // this will be done via mainwindow itself
    //userland_parser->parse_user_input_line("mload");

    return app.exec();
}