Multiple Viewport Issue Qt C++



  • Hi,

    I am trying to implement a multiple viewport scene using following code. Some lines might not be necessary for a functional scene as I am new to this kind of implementation. I have mixed multiple suggestions and not sure if this is the correct way of sorting out the necessary things I need for my 3D scene.
    When I run my project, it just shows a black screen and not sure if it is already a multi-viewport scene or still a single view. I was thinking that it might be possible that I am not able to link one of the viewports to the main view. Currently I am using a single view and it shows the 3D scene without any problem, but what I want to do for now to show the same view via only one of the 4 veiwports as a test and finally define multiple cameras to support the remaining viewports.

    Thank you!

    MyView3D::MyView3D(QWidget *parent)
        : QWidget(parent)
    {
    
    //QRgb(0x4d4d4f)
        this->view = new Qt3DExtras::Qt3DWindow();
        this->view->defaultFrameGraph()->setClearColor(QColor(135,206,235));
        this->container  = QWidget::createWindowContainer(this->view);
        this->screenSize = view->screen()->size();
        this->container->setMinimumSize(QSize(200, 100));
        this->container->setMaximumSize(screenSize);
        this->container->resize(200, 100);
        this->view->resize(200,100);
    
        this->hLayout  = new QHBoxLayout(this);
        this->hLayout->addWidget(this->container, 1);
    
        this->font = new QFont ("Courier New");
        font->setPixelSize ( 11 );
        this->logMessage = new QTextEdit;
        this->logMessage->setReadOnly ( 1 );
        this->logMessage->setLineWrapMode ( QTextEdit::NoWrap );
        this->logMessage->setCurrentFont ( * font );
        this->logMessage->setLineWrapColumnOrWidth ( 50 );
        this->logMessage->setMinimumHeight ( 50 );
    
        this->input = new Qt3DInput::QInputAspect;
        this->view->registerAspect(this->input);
    
        // Root entity
        this->rootEntity = new Qt3DCore::QEntity();
    
    /DECLARE A FRAME GRAPH
        this->frameGraph = new Qt3DRender::QFrameGraphNode();
        this->techniqueFilter = new Qt3DRender::QTechniqueFilter();
        Qt3DRender::QRenderSettings *activeFrameGraph = new Qt3DRender::QRenderSettings();
        this ->viewport1 = new Qt3DRender::QViewport(techniqueFilter);
        this->viewport2 = new Qt3DRender::QViewport(techniqueFilter);
        this->viewport3 = new Qt3DRender::QViewport(techniqueFilter);
        this->viewport4 = new Qt3DRender::QViewport(techniqueFilter);
        viewport1->setNormalizedRect(QRectF(0, 0, 0.5, 0.5));
        viewport2->setNormalizedRect(QRectF(0.5, 0, 0.5, 0.5));
        viewport3->setNormalizedRect(QRectF(0, 0.5, 0.5, 0.5));
        viewport4->setNormalizedRect(QRectF(0.5, 0.5, 0.5, 0.5));
    
        //SET ACTIVE FRAME GRAPH NODE TO YOUR WINDOW
        this->clearBuffer = new Qt3DRender::QClearBuffers(viewport1);
        this->cameraSelector = new Qt3DRender::QCameraSelector(clearBuffer);
        (void) new Qt3DRender::QRenderPassFilter(cameraSelector);
        clearBuffer->setBuffers(Qt3DRender::QClearBuffers::ColorDepthBuffer);
    
        // Camera
        this->cameraEntity = this->view->camera();
        this->cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
        this->cameraEntity->setPosition(QVector3D(-7, -3, 1.0f));
        this->cameraEntity->setUpVector(QVector3D(0, 0, 1));  // defines z-direction
        this->cameraEntity->setViewCenter(QVector3D(10, 0, 0));
    
        Qt3DRender::QRenderSurfaceSelector *surfaceSelector = new Qt3DRender::QRenderSurfaceSelector;
        //(surfaceSelector->setSurface(this->window());
       cameraSelector->setCamera(this->cameraEntity);
       this->view->setActiveFrameGraph(frameGraph);
       
       m_dummySurface = new QOffscreenSurface;
       m_dummySurface->setParent(this); // parent to something suitably long-living
       m_dummySurface->create();
       surfaceSelector->setSurface(view);
    
    ....

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.