Qt3d RenderStateSet does not works.



  • Hi! I try to add QRenderState to my Qt3DWindow(i hope they will global for all entity), but it take no effect. Is there any mistake in my code?

        view = new Qt3DExtras::Qt3DWindow();
    	QWidget* wid = QWidget::createWindowContainer(view);
    	QBoxLayout * Lay = new QBoxLayout(QBoxLayout::Down, this);
    	Lay->addWidget(wid);
    	root = new Qt3DCore::QEntity();
    	camera = view->camera();
    
    renderStateSet = new Qt3DRender::QRenderStateSet(view->activeFrameGraph());
    	
    	const auto  lineWidth2 = new Qt3DRender::QLineWidth();
    	lineWidth2->setValue(4.0f);
    	
    	const auto  pointweight = new Qt3DRender::QPointSize();
    	pointweight->setValue(4.0f);
    	
    	const auto cullFront = new Qt3DRender::QCullFace();
    	cullFront->setMode(Qt3DRender::QCullFace::FrontAndBack);
    
    	const auto depthTest = new Qt3DRender::QDepthTest();
    	depthTest->setDepthFunction(Qt3DRender::QDepthTest::LessOrEqual);
    	
    	
    	renderStateSet->addRenderState(depthTest);
    	renderStateSet->addRenderState(lineWidth2);
    	renderStateSet->addRenderState(pointweight);
    	renderStateSet->addRenderState(cullFront);
    


  • I find solution. The structure of entityes must include Layerfilter.

    Qt3DRender::QViewport *viewport = new Qt3DRender::QViewport(view->renderSettings()->activeFrameGraph());//here must be your framegraph
    	auto surselector =new Qt3DRender::QRenderSurfaceSelector(viewport);
    	surselector->setSurface(view);
    	auto layerfilter = new Qt3DRender::QLayerFilter(surselector);
    	auto layer = new Qt3DRender::QLayer(root);//yours root entity
    	layer ->setRecursive(true);
    	Qt3DRender::QCameraSelector *cameraSelector = new Qt3DRender::QCameraSelector(layerfilter);
    	Qt3DRender::QClearBuffers *clearBuffers = new Qt3DRender::QClearBuffers(cameraSelector);
    	clearBuffers->setClearColor(QColor(100.0, 100.0, 100.0));
    	cameraSelector->setCamera(view->camera());
    	clearBuffers->setBuffers(Qt3DRender::QClearBuffers::AllBuffers);
    
    	Qt3DRender::QRenderStateSet* rendstate = new Qt3DRender::QRenderStateSet(clearBuffers);
    	rendstate->setParent(clearBuffers);
    
    	Qt3DRender::QDepthTest* depth = new Qt3DRender::QDepthTest();//Without this nothing will work
    	depth->setDepthFunction(Qt3DRender::QDepthTest::LessOrEqual);
    	rendstate->addRenderState(depth);
    
    	Qt3DRender::QLineWidth* lw = new Qt3DRender::QLineWidth(rendstate);//render state for example
    	lw->setValue(8);
    	rendstate->addRenderState(lw);
    

    " layer " must be adde as component to entity


Log in to reply
 

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