How to force OCC use desktop OpenGL?

Hello,I have an occ view embedded in a qt app with configuation like this:

Ubuntu 24.04
OCC 7.8.1
QT 6.4.2

and it works fine under Windows like attached picture:works fine under windows.png,

but under ubuntu, all QT UI got messed up like attached pictures: messed_up_under_ubuntu.png;
and at the same time, two lines warning got repeated forever:

2024-12-31 17:46:19 [Warning]: QOpenGLContext::makeCurrent() called with non-opengl surface 0x5ecb89d98a80
2024-12-31 17:46:19 [Warning]: QRhiGles2: Failed to make context current. Expect bad things to happen.
2024-12-31 17:46:19 [Warning]: QOpenGLContext::makeCurrent() called with non-opengl surface 0x5ecb89d990a0
2024-12-31 17:46:19 [Warning]: QRhiGles2: Failed to make context current. Expect bad things to happen.
2024-12-31 17:46:19 [Warning]: QOpenGLContext::makeCurrent() called with non-opengl surface 0x5ecb89d87dc0
2024-12-31 17:46:19 [Warning]: QRhiGles2: Failed to make context current. Expect bad things to happen.
.....

And if removing OCC related stuff, qt app works fine(under ubuntu) without any warnings,
since occ view still works, I doubt that OCC caused this problem,
because based on warning message,the Gles2 is used,
and this type of opengl API should be used in a mobile environment,
but my ubuntu run inside a desktop machine. I have tried to:

1, Add:
QApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
as first line of main function.
2, Add/delete:
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
as second line of main function.

but same errors still exist, so questions are:

1, How can I make sure whether Gles2 cause this problem?
2, If Gles2 do cause this problem, how to force OCC use desktop OpenGL?

gkv311 n's picture

The question looks confusing - you have a problem with selecting OpenGL in Qt, but ask for the help with OCCT.

OCCT doesn't have runtime switcher between OpenGL and OpenGL ES - since OCCT 7.6 you either link application to TKOpenGles for OpenGL ES or to TKOpenGl for desktop OpenGL. Both libraries export the same class OpenGl_GraphicDriver which your application is expected to use, so make sure not to link to both libraries to avoid making things harder to trace.

In your log, it seems that Qt persists in choosing GLES (from the name QRhiGles2, but I'm not quite familiar with the newer versions of Qt). Note that Qt might just ignore QApplication::setAttribute(Qt::AA_UseDesktopOpenGL) without any messages if Qt has been built without Desktop OpenGL support (at least older versions that I've tested), so make sure that Qt in your Linux actually support this mode. You may also try using TKOpenGles in OCCT for testing (but you might need reworking initialization code).

And finally - it would be more productive to share versions of Qt and OCCT frameworks you are actually using, how they have been built (by yourself or somebody else), version of tested systems, some elements of OCCT and Qt initialization code related to 3D Viewer initialization, etc.

AlexLuya's picture

Thanks,I have shared the verion info.Why I doubt that OCC caused this problem?Because?
1,Same source code works fine under Windows
2,Under linux, APP UI works fine before initialiising occ view.