void TriangleMeshViewerDisplay::initializeGL()
{
  if (_verbose)
    {
      std::cerr << "Double buffering " << (doubleBuffer() ? "ON" : "OFF") << "\n";
      std::cerr << "Auto Buffer Swap " << (autoBufferSwap() ? "ON" : "OFF") << "\n";
      std::cerr << "Multisampling    " << (format().sampleBuffers() ? "ON" : "OFF") << "\n";
    }

  const FloatRGBA bg=background_colour();
  glClearColor(bg.r,bg.g,bg.b,1.0f);

  // Switch depth-buffering on
  glEnable(GL_DEPTH_TEST);

  // Basic lighting stuff (set ambient globally rather than in light)
  GLfloat black_light[]={0.0,0.0,0.0,1.0};
  glLightfv(GL_LIGHT0,GL_AMBIENT,black_light);
  glLightfv(GL_LIGHT0,GL_SPECULAR,black_light);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHTING);

  // Do smooth shading 'cos colours are specified at vertices
  glShadeModel(GL_SMOOTH);

  // Use arrays of data
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_COLOR_ARRAY);
  glEnableClientState(GL_NORMAL_ARRAY);
}
QtCanvas::QtCanvas(const std::string& title,
                   const ivec2& size,
                   const Buffers buffers,
                   QWidget* parent, bool shared, Qt::WFlags f, char* /*name*/)
    : GLCanvas(title, size, buffers)
    , QGLWidget(getQGLFormat(buffers), parent, (shared ? shareWidget_ : 0), f)
{
    resize(size.x, size.y);
    if (shared && shareWidget_ == 0)
        shareWidget_ = this;

    setWindowTitle(QString(title.c_str()));

    setFocusPolicy(Qt::StrongFocus);
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    // we have our own AutoBufferSwap-mechanism (GLCanvas::setAutoFlush), so disable the one of qt
    setAutoBufferSwap(false);

    rgbaSize_ = ivec4(format().redBufferSize(),
                      format().greenBufferSize(),
                      format().blueBufferSize(),
                      format().alphaBufferSize());
    stencilSize_ = format().stencilBufferSize();
    depthSize_ = format().depthBufferSize();
    doubleBuffered_ = doubleBuffer();
    stereoViewing_ = format().stereo();
}
Ejemplo n.º 3
0
/*!
    Returns the registered object that is under the mouse position
    specified by \a point.  This function may need to regenerate
    the contents of the pick buffer by repainting the scene
    with paintGL().

    \sa registerObject()
*/
QObject *QGLView::objectForPoint(const QPoint &point)
{
    // Check the window boundaries in case a mouse move has
    // moved the pointer outside the window.
    if (!rect().contains(point))
        return 0;

    // Do we need to refresh the pick buffer contents?
    QGLPainter painter(this);
    if (d->pickBufferForceUpdate) {
        // Initialize the painter, which will make the window context current.
        painter.setPicking(true);
        painter.clearPickObjects();

        // Create a framebuffer object as big as the window to act
        // as the pick buffer if we are single buffered.  If we are
        // double-buffered, then use the window back buffer.
        bool useBackBuffer = doubleBuffer();
        if (!useBackBuffer) {
            QSize fbosize = size();
            fbosize = QSize(powerOfTwo(fbosize.width()), powerOfTwo(fbosize.height()));
            if (!d->fbo) {
                d->fbo = new QGLFramebufferObject(fbosize, QGLFramebufferObject::CombinedDepthStencil);
            } else if (d->fbo->size() != fbosize) {
                delete d->fbo;
                d->fbo = new QGLFramebufferObject(fbosize, QGLFramebufferObject::CombinedDepthStencil);
            }
        }

        // Render the pick version of the scene into the framebuffer object.
        if (d->fbo)
            d->fbo->bind();
        painter.clear();
        painter.setEye(QGL::NoEye);
        painter.setCamera(d->camera);
        paintGL(&painter);
        painter.setPicking(false);

        // The pick buffer contents are now valid, unless we are using
        // the back buffer - we cannot rely upon it being valid next time.
        d->pickBufferForceUpdate = useBackBuffer;
        d->pickBufferMaybeInvalid = false;
    } else {
        // Bind the framebuffer object to the window's context.
        makeCurrent();
        if (d->fbo)
            d->fbo->bind();
    }

    // Pick the object under the mouse.
    int objectId = painter.pickObject(point.x(), height() - 1 - point.y());
    QObject *object = d->objects.value(objectId, 0);
    
    // Release the framebuffer object and return.
    painter.end();
    if (d->fbo)
        d->fbo->release();
    doneCurrent();
    return object;
}
QtCanvas::QtCanvas(QWidget* parent, bool shared, Qt::WFlags f, char* /*name*/)
    : GLCanvas()
    , QGLWidget(parent, (shared ? shareWidget_ : 0), f)
{
    if (shared && shareWidget_ == 0)
        shareWidget_ = this;

    // we have our own AutoBufferSwap-mechanism (GLCanvas::setAutoFlush), so disable the one of qt
    setAutoBufferSwap(false);

    rgbaSize_ = ivec4(format().redBufferSize(),
                      format().greenBufferSize(),
                      format().blueBufferSize(),
                      format().alphaBufferSize());
    stencilSize_ = format().stencilBufferSize();
    depthSize_ = format().depthBufferSize();
    doubleBuffered_ = doubleBuffer();
    stereoViewing_ = format().stereo();
}
Ejemplo n.º 5
0
void QGLWidget::glDraw()
{
    makeCurrent();
    if ( glcx->deviceIsPixmap() )
	glDrawBuffer( GL_FRONT_LEFT );
    if ( !glcx->initialized() ) {
	glInit();
	QPaintDeviceMetrics dm( glcx->device() );
	resizeGL( dm.width(), dm.height() ); // New context needs this "resize"
    }
    paintGL();
    if ( doubleBuffer() ) {
	if ( autoSwap )
	    swapBuffers();
    }
    else {
	glFlush();
    }
}
Ejemplo n.º 6
0
/*!
    Returns the registered object that is under the mouse position
    specified by \a point.  This function may need to regenerate
    the contents of the pick buffer by repainting the scene
    with paintGL().

    \sa registerObject()
*/
QObject *QGLView::objectForPoint(const QPoint &point)
{
    QPoint pt(point);

    // What is the size of the drawing area after correcting for stereo?
    // Also adjust the mouse position to always be in the left half.
    QSize areaSize = size();
    switch (d->stereoType) {
    case QGLView::LeftRight:
    case QGLView::RightLeft:
        areaSize = QSize(areaSize.width() / 2, areaSize.height());
        if (pt.x() >= areaSize.width())
            pt.setX(pt.x() - areaSize.width());
        break;
    case QGLView::TopBottom:
    case QGLView::BottomTop:
        areaSize = QSize(areaSize.width(), areaSize.height() / 2);
        if (pt.y() >= areaSize.height())
            pt.setY(pt.y() - areaSize.height());
        break;
    case QGLView::StretchedLeftRight:
    case QGLView::StretchedRightLeft: {
        int halfwid = areaSize.width() / 2;
        if (pt.x() >= halfwid)
            pt.setX((pt.x() - halfwid) * 2);
        else
            pt.setX(pt.x() * 2);
        break; }
    case QGLView::StretchedTopBottom:
    case QGLView::StretchedBottomTop: {
        int halfht = areaSize.height() / 2;
        if (pt.y() >= halfht)
            pt.setY((pt.y() - halfht) * 2);
        else
            pt.setY(pt.y() * 2);
        break; }
    default: break;
    }

    // Check the area boundaries in case a mouse move has
    // moved the pointer outside the window.
    if (pt.x() < 0 || pt.x() >= areaSize.width() ||
            pt.y() < 0 || pt.y() >= areaSize.height())
        return 0;

    // Do we need to refresh the pick buffer contents?
    QGLPainter painter(this);
    if (d->pickBufferForceUpdate) {
        // Initialize the painter, which will make the window context current.
        painter.setPicking(true);
        painter.clearPickObjects();

        // Create a framebuffer object as big as the window to act
        // as the pick buffer if we are single buffered.  If we are
        // double-buffered, then use the window back buffer.
        bool useBackBuffer = doubleBuffer();
        if (!useBackBuffer) {
            QSize fbosize = QGL::nextPowerOfTwo(areaSize);
            if (!d->fbo) {
                d->fbo = new QGLFramebufferObject(fbosize, QGLFramebufferObject::CombinedDepthStencil);
            } else if (d->fbo->size() != fbosize) {
                delete d->fbo;
                d->fbo = new QGLFramebufferObject(fbosize, QGLFramebufferObject::CombinedDepthStencil);
            }
        }

        // Render the pick version of the scene.
        QGLViewPickSurface surface(this, d->fbo, areaSize);
        painter.pushSurface(&surface);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        painter.setEye(QGL::NoEye);
        painter.setCamera(d->camera);
        paintGL(&painter);
        painter.setPicking(false);
        painter.popSurface();

        // The pick buffer contents are now valid, unless we are using
        // the back buffer - we cannot rely upon it being valid next time.
        d->pickBufferForceUpdate = useBackBuffer;
        d->pickBufferMaybeInvalid = false;
    }

    // Pick the object under the mouse.
    if (d->fbo)
        d->fbo->bind();
    int objectId = painter.pickObject(pt.x(), areaSize.height() - 1 - pt.y());
    QObject *object = d->objects.value(objectId, 0);
    if (d->fbo)
        d->fbo->release();

    // Release the framebuffer object and return.
    painter.end();
    doneCurrent();
    return object;
}
Ejemplo n.º 7
0
void DrawZone::drawContents(QPainter* p,int clipx,int clipy,int clipw,int cliph)
{

// Erase background without flicker
	QRect updateRect(clipx,clipy,clipw,cliph);

	// Pixmap for double-buffering
  QPixmap doubleBuffer(updateRect.size());
  if (doubleBuffer.isNull())
  	return;

  QPainter p2(&doubleBuffer);
	p2.drawPixmap(0,0,zoomedImage,clipx,clipy,clipw,cliph);
	p2.setBackgroundColor(p->backgroundColor());

	if (zoomedImage.width() < (clipw+clipx) ) {
		int eraseWidth = clipw+clipx - zoomedImage.width();
		p2.eraseRect( QRect(clipw-eraseWidth,0,eraseWidth,cliph) );
	}

	if (zoomedImage.height() < (cliph+clipy) ) {
		int eraseHeight = cliph+clipy - zoomedImage.height();
		p2.eraseRect( QRect(0,cliph-eraseHeight,clipw,eraseHeight) );
	}

	p2.translate(-clipx, -clipy);
	p2.scale(_zoom,_zoom);

	QRect areaUpdateRect;
	areaUpdateRect.setX(myround(clipx/_zoom)-1);
	areaUpdateRect.setY(myround(clipy/_zoom)-1);
	areaUpdateRect.setWidth(myround(clipw/_zoom)+2);
	areaUpdateRect.setHeight(myround(cliph/_zoom)+2);

	AreaListIterator it=imageMapEditor->areaList();
	for ( it.toLast();it.current() != 0L; --it)
	{
     if (it.current()->rect().intersects(areaUpdateRect))
       it.current()->draw(p2);
	}

	// Draw the current drawing Area
	if (currentAction != MoveArea &&
			currentAction != MoveSelectionPoint &&
			currentAction != None &&
			currentAction != DoSelect)
	{
		currentArea->draw(p2);
	}

	if (currentAction == DoSelect )
  {
		QPen pen = QPen(QColor("white"),1);
		p2.setRasterOp(Qt::XorROP);
		pen.setStyle(Qt::DotLine);
		p2.setPen(pen);

		QRect r( drawStart.x(),drawStart.y(),drawCurrent.x()-drawStart.x(),drawCurrent.y()-drawStart.y());
		r = r.normalize();
		p2.drawRect(r);
	}



  p2.end();

  // Copy the double buffer into the widget
  p->drawPixmap(clipx,clipy,doubleBuffer);


}
Ejemplo n.º 8
0
void PrefGeneral::getData(Preferences * pref) {
	requires_restart = false;
	filesettings_method_changed = false;

	if (pref->mplayer_bin != mplayerPath()) {
		requires_restart = true;
		pref->mplayer_bin = mplayerPath();

		qDebug("PrefGeneral::getData: mplayer binary has changed, getting version number");
		// Forces to get info from mplayer to update version number
		InfoReader i( pref->mplayer_bin );
		i.getInfo(); 
		// Update the drivers list at the same time
		//setDrivers( i.voList(), i.aoList() );
	}

	TEST_AND_SET(pref->use_screenshot, useScreenshots());
	TEST_AND_SET(pref->screenshot_directory, screenshotDir());
	TEST_AND_SET(pref->vo, VO());
    TEST_AND_SET(pref->ao, AO());

	bool dont_remember_ms = !rememberSettings();
    TEST_AND_SET(pref->dont_remember_media_settings, dont_remember_ms);

	bool dont_remember_time = !rememberTimePos();
    TEST_AND_SET(pref->dont_remember_time_pos, dont_remember_time);

	if (pref->file_settings_method != fileSettingsMethod()) {
		pref->file_settings_method = fileSettingsMethod();
		filesettings_method_changed = true;
	}

	pref->audio_lang = audioLang();
    pref->subtitle_lang = subtitleLang();

	pref->initial_audio_track = audioTrack();
	pref->initial_subtitle_track = subtitleTrack();

	pref->close_on_finish = closeOnFinish();
	pref->pause_when_hidden = pauseWhenHidden();

	TEST_AND_SET(pref->use_soft_video_eq, eq2());
	TEST_AND_SET(pref->use_soft_vol, softVol());
	pref->global_volume = globalVolume();
	TEST_AND_SET(pref->use_audio_equalizer, useAudioEqualizer());
	TEST_AND_SET(pref->use_hwac3, Ac3DTSPassthrough());
	pref->initial_volnorm = initialVolNorm();
	TEST_AND_SET(pref->softvol_max, amplification());
	pref->initial_postprocessing = initialPostprocessing();
	pref->initial_deinterlace = initialDeinterlace();
	pref->initial_zoom_factor = initialZoom();
	TEST_AND_SET(pref->use_direct_rendering, directRendering());
	TEST_AND_SET(pref->use_double_buffer, doubleBuffer());
	TEST_AND_SET(pref->use_slices, useSlices());
	pref->start_in_fullscreen = startInFullscreen();
	if (pref->add_blackborders_on_fullscreen != blackbordersOnFullscreen()) {
		pref->add_blackborders_on_fullscreen = blackbordersOnFullscreen();
		if (pref->fullscreen) requires_restart = true;
	}
	TEST_AND_SET(pref->autoq, autoq());

#ifdef Q_OS_WIN
	pref->avoid_screensaver = avoidScreensaver();
	TEST_AND_SET(pref->turn_screensaver_off, turnScreensaverOff());
#else
	TEST_AND_SET(pref->disable_screensaver, disableScreensaver());
#endif

#ifndef Q_OS_WIN
	pref->vdpau = vdpau;
#endif

	pref->initial_audio_channels = audioChannels();
	TEST_AND_SET(pref->use_scaletempo, scaleTempoFilter());

	TEST_AND_SET(pref->autosync, autoSyncActivated());
	TEST_AND_SET(pref->autosync_factor, autoSyncFactor());

	TEST_AND_SET(pref->use_mc, mcActivated());
	TEST_AND_SET(pref->mc_value, mc());
}
Ejemplo n.º 9
0
/*!
    \internal
*/
void QGLView::paintGL()
{
    d->logEnter("QGLView::paintGL");
    // We may need to regenerate the pick buffer on the next mouse event.
    d->pickBufferMaybeInvalid = true;

    // Paint the scene contents.
    QGLPainter painter;
    painter.begin();
    painter.resetViewport();
    if (d->options & QGLView::ShowPicking &&
            d->stereoType == QGLView::RedCyanAnaglyph) {
        // If showing picking, then render normally.  This really
        // only works if we aren't using hardware or double stereo.
        painter.setPicking(true);
        painter.clearPickObjects();
        painter.setEye(QGL::NoEye);
        earlyPaintGL(&painter);
        painter.setCamera(d->camera);
        paintGL(&painter);
        painter.setPicking(false);
    } else if (d->camera->eyeSeparation() == 0.0f &&
                    (d->stereoType == QGLView::Hardware ||
                     d->stereoType == QGLView::RedCyanAnaglyph)) {
        // No camera separation, so draw without stereo.  If the hardware
        // has stereo buffers, then render the same image into both buffers.
#if defined(GL_BACK_LEFT) && defined(GL_BACK_RIGHT)
        if (d->stereoType == QGLView::Hardware) {
            bool doubleBuffered = doubleBuffer();
            if (doubleBuffered)
                glDrawBuffer(GL_BACK);
            else
                glDrawBuffer(GL_FRONT);
            painter.setEye(QGL::NoEye);
            earlyPaintGL(&painter);
            painter.setCamera(d->camera);
            paintGL(&painter);
        } else
#endif
        {
            painter.setEye(QGL::NoEye);
            earlyPaintGL(&painter);
            painter.setCamera(d->camera);
            paintGL(&painter);
        }
    } else {
        // Paint the scene twice, from the perspective of each camera.
        // In RedCyanAnaglyph mode, the color mask is set each time to only
        // extract the color planes that we want to see through that eye.
        if (d->stereoType == QGLView::RedCyanAnaglyph) {
            painter.setEye(QGL::LeftEye);
            glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
            earlyPaintGL(&painter);

            glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
            painter.setCamera(d->camera);
            paintGL(&painter);

            painter.setEye(QGL::RightEye);
            glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
            glClear(GL_DEPTH_BUFFER_BIT);
            painter.setCamera(d->camera);
            paintGL(&painter);

            glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
        } else if (d->stereoType != QGLView::Hardware) {
            // Render the stereo images into the two halves of the window.
            QSize sz = size();
            painter.setEye(QGL::LeftEye);
            qt_qglview_left_viewport(&painter, sz, d->stereoType);
            earlyPaintGL(&painter);
            painter.setCamera(d->camera);
            paintGL(&painter);
            painter.setEye(QGL::RightEye);
            qt_qglview_right_viewport(&painter, sz, d->stereoType);
            painter.setCamera(d->camera);
            paintGL(&painter);
            painter.setViewportOffset(QPoint(0, 0));
        }
#if defined(GL_BACK_LEFT) && defined(GL_BACK_RIGHT)
        else {
            bool doubleBuffered = doubleBuffer();
            if (doubleBuffered)
                glDrawBuffer(GL_BACK_LEFT);
            else
                glDrawBuffer(GL_FRONT_LEFT);
            painter.setEye(QGL::LeftEye);
            earlyPaintGL(&painter);
            painter.setCamera(d->camera);
            paintGL(&painter);

            if (doubleBuffered)
                glDrawBuffer(GL_BACK_RIGHT);
            else
                glDrawBuffer(GL_FRONT_RIGHT);
            painter.setEye(QGL::RightEye);
            earlyPaintGL(&painter);
            painter.setCamera(d->camera);
            paintGL(&painter);
        }
#endif
    }
    d->logLeave("QGLView::paintGL");
}