cannot-get-Z-buffer for legacy-OpenGL with Nvidia-drivers

After many tests it seems:
- Gtk3 + gtkglarea does not accept legacy-OpenGL-calls
- Gtk3 + GLX cannot get Z-buffer - only 2D;
- Gtk2 + GLX works fine,

Testprogs (minimal code) see: 
https://github.com/gcad3d/gcad-GL/blob/master/tests_gl_legacy/

Ad Gtk3 + gtkglarea (gtk3_gla.c):
- Linux: cannot get OpenGL-context for legacy-OpenGL
- cannot get working gtk_gl_area_set_required_version
  and / or gtk_gl_area_set_has_depth_buffer

Ad Gtk3 + GLX  (gtk3_glx.c):
- Linux: driver nouveau works, but crashes with more than ~10000 listobjects
  - all versions of Nvidia-drivers on Ubuntu 20 and Ubuntu 18 refuse Z-buffer
  - AMD-card with radeon-driver works OK (identical code)
- MS-Win: Nvidia-drivers and radeon-drivers OK (identical code)

Ad Gtk2 + GLX (gtk2_glx.c):
- Linux: Nvidia-drivers and radeon-drivers OK
- MS-Win: Nvidia-drivers and radeon-drivers OK (identical code)

Ad GLX-only (glx_only.c): Linux and MS-Win OK


Problem occurs eg on
- GraficCard NVIDIA GeForce GTX 1050 Ti/PCIe/SSE2
- Ubuntu 20.04.3 LTS (Focal Fossa) 64-bit and also Ubuntu 18;
- NV-Driver 390.144 - and NV-Driver 460.91.03 - and NV-Driver 470.86

Legacy-OpenGL is and will be a good basis for a grafic-interface for many general-purpose grafic programs, especially cad-programs.
 
What is wrong with gtk3_gla.c and gtk3_glx.c
or is there a example for Gtk3 + gtkglarea + legacy-OpenGL in the net ?
Regards,
Franz

Hi, Franz.

First of all, the OpenGL support in GTK+ REQUIRES core GL profiles.
It will not work with the fixed pipeline API (things like glBegin(), etc, will not run).

And about Z-buffering vs 2D/3D they are related but are not the same thing.
You can draw into a 3D space without Z-buffer at all.

Good luck.

OK, Gtk3 REQUIRES core GL profiles;
but Gtk2 works OK !
Core-profiles and Vulkan are not the end of development, and cannot yet provide a useful interface.
Until a good replacement for the legacy-mode is found, the legacy-mode is a good interface for many
applications (except games).
Drawing in legacy-mode without z-buffer makes no use in 3D.
Franz

Hello, Franz !

I don’t know GTK2, but if if fits your requirements and is supported (is it ?) why are you dealing with GTK3 ?

And also (about Z), I’m not experienced with the legacy API, but isn’t the case of drawing far faces first and nearest faces last ?

Anyway, there is support for DEPTH_TEST in GTK3, as it comes from OpenGL itself.

Lastly, yes, I understand that modern OpenGL is different from the the fixed pipeline. But it is also similar in many aspects.

Maybe the GTK team adds ‘legacy OpenGL support’ to GTK3 or GTK4, but i’m not very confident about it.

I hope you get your needs fulfilled, by staying with GTK2 or by migrating to core GL.

Regards.

There is nothing wrong with GTK3 and GtkGLArea.

No. It’s 2022: legacy (pre-3.2 core profile) OpenGL contexts are not going to be supported. It’s like asking us to support Windows XP, at this point. You either use GL 3.0 legacy contexts, or you use GL 3.2+ core profile ones.

Additionally, “CAD programs” are unlikely to be using old GL either; if they do, they are also using old toolkits and windowing systems anyway, and won’t be ported to modern ones.

This GPU is perfectly capable of supporting GL 3.2 core profile contexts; I dare even say that it’s only meant to be used with modern OpenGL.

You have to explicitly enable depth testing with GtkGLArea using gtk_gl_area_set_has_depth_buffer(); by default GtkGLArea will allocate a framebuffer object without depth and stencil buffer.

I have no idea how you’re testing GTK3 with GLX on Windows. I suspect you’re very confused.

Your code examples are also entirely broken for GTK3: you’re literally overdrawing on top of the GTK windowing system surface. This is wrong and unsupported.

Additionally, in your examples you use the legacy GL 2.x fixed pipeline API, but of course with that GPU and those drivers you’re going to get a core 3.2+ profile with GtkGLArea, which means nothing you’ll draw will ever appear on screen.

To make a long story short:

  • GTK only supports core 3.2+ GL profiles; it also has support for legacy 3.0 profiles, but they are not recommended
  • You can only use the legacy fixed pipeline API if GTK creates a legacy GL context; if it does not, you need to use the modern GL API
  • You can only draw within the GtkGLArea widget’s “render” callback
  • You most definitely cannot create your own random GL context and then draw on it like nothing matters

GTK2 works “okay” because it has no GL support; the extra libraries you need to use with GTK2 (assuming you don’t go calling into GLX directly) can only work on X11, and can only work on native surfaces, outside of the toolkit’s own rendering pipeline.

Additionally, GTK2 is unsupported, as it has been end-of-lifed in December 2020.

This sentence is hard to parse. Core profiles have been the proper way to use OpenGL since 2009; it’s been 13 years.

There is never going to be a “good replacement”: this is the API you get for everything, including CAD and drawing applications.

1 Like

gcad3d is using the OpenGL-legacy-retained-mode (glBegin, glCallList).
gcad3d will use this mode for 2 to 4 years more.
OpenGL-legacy-retained-mode works with Gtk3 with many grafic cards ok,
does not get Z-buffer on some; gtk_gl_area_set_has_depth_buffer does not help.
OpenGL-legacy-retained-mode works with Gtk2 works on most systems.

Ad:

Your code examples are also entirely broken for GTK3: you’re literally overdrawing on top of the GTK windowing system surface. This is wrong and unsupported.
???
GTK2 works “okay” because it has no GL support
???

So, is this correct -

  • Gtk3 does not support the OpenGL-legacy-retained-mode
  • Gtk3 cannot be used “without GL support” like Gtk2

Regards
Franz

Then you won’t be able to port to GTK3.

To be fair, if you’re going to way 2-4 years, I’d recommend moving to GTK4 directly, at this point. There’s no reason to switch to GTK3 at all.

Your problem has nothing to do with GtkGLArea’s depth buffer handling.

I honestly have ran out of ways of explaining this.

GTK3 supports legacy, GL 3.0 contexts. Those contexts still have the old, deprecated GL API for fixed function pipelines. What you are experiencing is that, by default, GTK3 will always ask for a GL 3.2+ core profile context, and will only fall back to legacy contexts if the GL driver does not support 3.2+ core profiles. Since you’re using GTK3 on a recent nVidia GPU, GtkGLArea will get a core profile context, and you will need to use the appropriate, non-deprecated API.

If you use the old, deprecated fixed function API, the depth buffer handling is not the cause of your issues.

No, you cannot use GTK3 the same way you used GTK2: grabbing the windowing system surface and creating a GLX context to draw on it at random is not going to work reliably, or at all.

In general, the approach of rendering behind the toolkit’s back is never going to be supported.

Ad:

Then you won’t be able to port to GTK3.
we have been using Gtk3 since 5 years, the problem came up last year.
So we have to use Gtk2 and then change to Gtk4,
thanks for your effort.

Note that if you really need to, it is technically possible to create a legacy context yourself with EGL, use it to render into a framebuffer, and then import the framebuffer texture into GDK’s GL context. I wouldn’t recommend this unless it’s really necessary though.

could be a solution if the Gtk2 support ends before we have Gtk4 (no Gtk4-dev-libs on Ubuntu-20-LTS yet).
many of our users require Ubuntu-18 binaries.
Thanks.

GTK2 is already end-of-life: there is no support, unless you pay somebody for it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.