Example on how to setup offscreen rendering for OCCT + Qt5 QML

Hi everyone,

I'm looking for a minimal example on how to use OCCT (7.4) for offscreen rendering onto Qt5 QML.

I plan to be able to render through the Qt/QML QOpenGLFramebufferObject, which seems to be the way to go to implement such feature.

The idea beeing to be able to put as many of these items inside one QML window.

So far, I've checked the QtAndroid sample and various posts from M.Gavrilov on the forum about methods that seems

to be related to such implementation ( OpenGl_FrameBuffer::InitWrapper(), OpenGl_Context::SetDefaultFrameBuffer() .. ).

But I couldn't figure out a way to make a minimal example working.

Here is how I try to setup the context and the view for OCCT :
 

m_oGlContext = new OpenGl_Context();
m_oGlContext->Init();
m_oGlFrameBuffer = new OpenGl_FrameBuffer();
m_oGlFrameBuffer->InitWrapper(m_oGlContext);
Handle(OcctDummyWindow) aWindow = new OcctDummyWindow(100, 100);
m_oGlDriver = new OpenGl_GraphicDriver(nullptr, false);
m_oGlDriver->ChangeOptions().buffersNoSwap = Standard_False;
m_theV3dViewer = new V3d_Viewer(m_oGlDriver);
m_theCtx = new AIS_InteractiveContext(m_theV3dViewer);
m_theV3dView = m_theV3dViewer->CreateView();
m_theV3dView->SetImmediateUpdate(Standard_False);
// Handle(WNT_Window) aWindow = new WNT_Window((HWND) occView->window()->winId());
m_theV3dView->SetWindow(aWindow, (Aspect_RenderingContext) wglGetCurrentContext());
// m_theV3dView->View()->SetFBO(m_oGlFrameBuffer);
m_theV3dView->SetBackgroundColor(Quantity_TOC_RGB, 1.0, 1.0, 0.0);

But I still can't figure out how to setup a dummy window for offscreen rendering.

The code ( using the implementation of a WNT_Window found in the QtAndroid sample ) above results in an OpenGL error telling me that the pixel format is not valid.

Can someone share some example or insights on this matter ?

That would be great.

Thanks,

Paul

Hugues Delorme's picture

I tried some months ago to do the same thing but failed as well.
Maybe not related but did you try with using Aspect_NeutralWindow ?

Paul BIGEON's picture

Thanks for your answer M.DELORME,

I tried using Aspect_NeutralWindow too, but couldn't achieve it either. ( The program won't crash, but the error : "wglMakeCurrent() has failed. the pixel format is not valid." pops. ).

However, a part of my goal is achieved as I found a workaround to display OCCT views on several QML items, ( halas still using the QML window ) :

kndscan's picture

Hi Pual. I am trying to run AndriodQt example.
The AndroidQt view alwary locats in the left bottom corner. I tried changing the location, but it doesn't work.
I hope to display a 3d model in a qquickitem, which may locat anywhere in an applicationwindow.
Could you please put some code snippet.