No GL implementation is available

Steps to reproduce

  1. On my embedded system (arm64), run a.out which is generated by opengles.cpp as follow
  #include <string.h>
  #include <stdio.h>
  #include <gtk/gtk.h>
  #include <epoxy/gl.h>
  
  unsigned int WIDTH = 800;
  unsigned int HEIGHT = 600;

  const GLchar *VERTEX_SOURCE =
      "#version 300 es\n"
      "layout (location = 0) in vec3 aPosition;\n"
      "void main()\n"
      "{\n"
      "   gl_Position = vec4(aPosition, 1.0);\n"
      "}\n";

  const GLchar *FRAGMENT_SOURCE =
      "#version 300 es\n"
      "precision mediump float;\n"
      "out mediump vec4 FragColor;\n"
      "void main()\n"
      "{\n"
      "   FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
      "}\n";

  static GtkWidget *gl_area = NULL;
  static GLuint vbo;
  static GLuint vao;
  static GLuint vertex, fragment;
  static GLuint program;

  static const GLfloat vertex_data[] = {
      0.0f,  0.5f, 0.0f,
      -0.5f, -0.5f, 0.0f,
      0.5f, -0.5f, 0.0f
  };

  static GLuint
  create_shader (int type)
  {
    GLuint shader, program;
    shader = glCreateShader (type);
    if (type== GL_FRAGMENT_SHADER){
      glShaderSource (shader, 1, &FRAGMENT_SOURCE, NULL);
    }
    if (type== GL_VERTEX_SHADER){
      glShaderSource (shader, 1, &VERTEX_SOURCE, NULL);
    }
    glCompileShader (shader);
  
    return shader;
  }

  static void
  realize (GtkWidget *widget)
  {
    GdkGLContext *context;
    gtk_gl_area_make_current (GTK_GL_AREA (widget));
    if (gtk_gl_area_get_error (GTK_GL_AREA (widget)) != NULL)
      return;
    context = gtk_gl_area_get_context (GTK_GL_AREA (widget));
  
    glGenVertexArrays (1, &vao);
    glBindVertexArray (vao);
  
    glGenBuffers (1, &vbo);
    glBindBuffer (GL_ARRAY_BUFFER, vbo);
    glBufferData (GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
    glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
    glEnableVertexAttribArray (0);
   
    vertex = create_shader(GL_VERTEX_SHADER);
    fragment = create_shader(GL_FRAGMENT_SHADER);
  
    program = glCreateProgram ();
    glAttachShader (program, vertex);
    glAttachShader (program, fragment);
    glLinkProgram (program);
    glDetachShader (program, vertex);
    glDetachShader (program, fragment);
  }

  static gboolean
  render (GtkGLArea    *area,
          GdkGLContext *context)
  {
    if (gtk_gl_area_get_error (area) != NULL)
      return FALSE;
  
    glClearColor (0.0, 0.0, 0.0, 1.0);
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glUseProgram (program);
  
    glBindVertexArray (vao);
    glDrawArrays (GL_TRIANGLES, 0, 3);
   
    gtk_gl_area_queue_render (area);
    return TRUE;
  }

  int main(int argc, char **argv)
  {
    GtkWidget *window, *box;
    gtk_init(&argc, &argv);
  
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size (GTK_WINDOW(window), WIDTH, HEIGHT);
    gtk_window_set_title (GTK_WINDOW(window), "GL Area");
    gtk_container_set_border_width (GTK_CONTAINER(window), 10);
    box = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE);
    g_object_set (box, "margin", 12, NULL);
    gtk_box_set_spacing (GTK_BOX (box), 6);
    gtk_container_add (GTK_CONTAINER (window), box);
  
    gl_area = gtk_gl_area_new ();
    gtk_box_pack_start (GTK_BOX(box), gl_area, 1, 1, 0);
  
    g_signal_connect (gl_area, "realize", G_CALLBACK (realize), NULL);
    g_signal_connect (gl_area, "render", G_CALLBACK (render), NULL);
    g_signal_connect (G_OBJECT(window), "delete-event", G_CALLBACK(gtk_main_quit), NULL);
    gtk_widget_show_all (GTK_WIDGET(window));
  
    gtk_main();
  
    return 0;
  }
  1. GLArea shows “No GL implementation is available”

Current behavior

Expected outcome

print a triangle on GLArea

Version information

GTK 3.24.34

Additional information

  • My environment has installed OpenGL ES, cause I can run xeglgears successfully
  • I even try to not include <epoxy/gl.h>, but include <GLES3/gl3.h> and still get nothing
  • the opengles.cpp can run on Ubuntu successfully

GTK3 defaults to OpenGL, and always has; GLES is supported only if there is no OpenGL implementation available on the system, or if you exported GDK_GL=gles in your environment.

Thanks, you mean GDK_GL=gles ./a.out ?
But it still got “No GL implementation is available”

At this point, you may want to run with GDK_DEBUG=opengl in your environment and get a more detailed log of what’s happening behind the scenes.

You may need to build GTK with debugging enabled:

Oh, I see!

My GTK3 library was downloaded from Yocto project
https://layers.openembedded.org/layerindex/recipe/5136/

According to this note, the default value is minimum

Perhaps, this value must be “yes” for GDK_DEBUG=opengl to be valid?

It’s a bit different, because those instructions are for the Autotools build, and recent GTK3 versions have switched to Meson.

If you build GTK3 yourself, you will need to add --debug to the Meson options in the recipe.

Hi, I’m not familiar with Meson. Your “Meson option” mean EXTRA_OEMESON or GTKDOC_MESON_OPTION from here?

No, meson options are arguments passed to the meson build tool when compiling GTK. I found in the INSTALL.md of the gtk-3-24 branch the following instructions for building:

$ meson setup _build
$ meson compile -C _build
$ meson install -C _build

I believe what @ebassi refers to is running the following instead, for meson compile:

$ meson compile --debug -C_build

No, this is incorrect. The --debug option is a build configuration one, and it’s for the setup sub-command.

In this case, though, we’re talking about a Yocto recipe, which will call Meson for you; the appropriate way to pass extra arguments to Meson’s configuration step with Yocto is to use EXTRA_OEMESON to include --debug, or you can set MESON_BUILDTYPE to debug.

EXTRA_OEMESON is the variable to update.

1 Like

Oh whoops, mixed setup for compile. Thank you for the clarification. :slight_smile:

Sorry for the late reply. I finally build a debug gtk library, but still display no log when using GDK_DEBUG=opengl ./a.out :joy:

The debug gtk library is much bigger.
企业微信截图_17199910491064

Thanks for your joining and feedback. G’day~ :muscle:

1 Like

Are you sure you’re running a.out against the debug build of GTK? What happens when you use GDK_DEBUG=all ./a.out?

Here are the output

root@am62xx-evm:/USBDisk# GDK_DEBUG=all ./a.out 

Gdk-Message: 16:42:07.871: Trying x11 backend
Gdk-Message: 16:42:07.883: visual: true color: 32
Gdk-Message: 16:42:07.883: visual: true color: 24
Gdk-Message: 16:42:07.890: Creating XI2 (version 2.4) device manager
Gdk-Message: 16:42:07.892: input device:
	name: Virtual core pointer
	type: master
	source: mouse
	mode: screen
	has cursor: 1
	touches: 0
Gdk-Message: 16:42:07.893: 
	axis: Rel X (ignored)
Gdk-Message: 16:42:07.893: 
	axis: Rel Y (ignored)
Gdk-Message: 16:42:07.893: input device:
	name: Virtual core keyboard
	type: master
	source: keyboard
	mode: screen
	has cursor: 0
	touches: 0
Gdk-Message: 16:42:07.893: input device:
	name: Virtual core XTEST pointer
	type: slave
	source: mouse
	mode: disabled
	has cursor: 0
	touches: 0
Gdk-Message: 16:42:07.894: 
	axis: Rel X (ignored)
Gdk-Message: 16:42:07.894: 
	axis: Rel Y (ignored)
Gdk-Message: 16:42:07.894: input device:
	name: Virtual core XTEST keyboard
	type: slave
	source: keyboard
	mode: disabled
	has cursor: 0
	touches: 0
Gdk-Message: 16:42:07.894: input device:
	name: Wired USB Keyboard
	type: slave
	source: keyboard
	mode: disabled
	has cursor: 0
	touches: 0
Gdk-Message: 16:42:07.895: input device:
	name: Wired USB Keyboard System Control
	type: slave
	source: keyboard
	mode: disabled
	has cursor: 0
	touches: 0
Gdk-Message: 16:42:07.895: input device:
	name: Wired USB Keyboard Consumer Control
	type: slave
	source: mouse
	mode: disabled
	has cursor: 0
	touches: 0
Gdk-Message: 16:42:07.896: 
	axis: Rel X (ignored)
Gdk-Message: 16:42:07.896: 
	axis: Rel Y (ignored)
Gdk-Message: 16:42:07.896: 
	axis: Rel Horiz Scroll (ignored)
Gdk-Message: 16:42:07.896: 
	axis: Rel Vert Scroll (ignored)
Gdk-Message: 16:42:07.896: 
	scroll valuator 2: horizontal, increment 120.000000
Gdk-Message: 16:42:07.896: 
	scroll valuator 3: vertical, increment 120.000000
Gdk-Message: 16:42:07.897: input device:
	name: Wired USB Keyboard Consumer Control
	type: slave
	source: keyboard
	mode: disabled
	has cursor: 0
	touches: 0
Gdk-Message: 16:42:07.900: Detectable autorepeat supported.
Gdk-Message: 16:42:08.057: property notify:	window: 18874369, atom(282): "_NET_WM_NAME"
Gdk-Message: 16:42:08.058: property notify:	window: 18874369, atom(39): "WM_NAME"
Gdk-Message: 16:42:08.058: property notify:	window: 18874369, atom(348): "_NET_WM_ICON_NAME"
Gdk-Message: 16:42:08.058: property notify:	window: 18874369, atom(37): "WM_ICON_NAME"
Gdk-Message: 16:42:08.058: property notify:	window: 18874369, atom(259): "WM_PROTOCOLS"
Gdk-Message: 16:42:08.058: property notify:	window: 18874369, atom(40): "WM_NORMAL_HINTS"
Gdk-Message: 16:42:08.058: property notify:	window: 18874369, atom(36): "WM_CLIENT_MACHINE"
Gdk-Message: 16:42:08.058: property notify:	window: 18874369, atom(344): "WM_LOCALE_NAME"
Gdk-Message: 16:42:08.058: property notify:	window: 18874369, atom(310): "_NET_WM_PID"
Gdk-Message: 16:42:08.059: property notify:	window: 18874369, atom(343): "WM_CLIENT_LEADER"
Gdk-Message: 16:42:08.059: property notify:	window: 18874369, atom(34): "WM_COMMAND"
Gdk-Message: 16:42:08.059: property notify:	window: 18874369, atom(36): "WM_CLIENT_MACHINE"
Gdk-Message: 16:42:08.059: property notify:	window: 18874369, atom(67): "WM_CLASS"
Gdk-Message: 16:42:08.059: property notify:	window: 18874369, atom(344): "WM_LOCALE_NAME"
Gdk-Message: 16:42:08.059: property notify:	window: 18874369, atom(310): "_NET_WM_PID"
Gdk-Message: 16:42:08.059: property notify:	window: 18874370, atom(282): "_NET_WM_NAME"
Gdk-Message: 16:42:08.059: property notify:	window: 18874370, atom(39): "WM_NAME"
Gdk-Message: 16:42:08.059: property notify:	window: 18874370, atom(348): "_NET_WM_ICON_NAME"
Gdk-Message: 16:42:08.059: property notify:	window: 18874370, atom(37): "WM_ICON_NAME"
Gdk-Message: 16:42:08.059: property notify:	window: 18874370, atom(67): "WM_CLASS"
Gdk-Message: 16:42:08.059: property notify:	window: 18874370, atom(259): "WM_PROTOCOLS"
Gdk-Message: 16:42:08.060: property notify:	window: 18874369, atom(282): "_NET_WM_NAME"
Gdk-Message: 16:42:08.060: property notify:	window: 18874369, atom(39): "WM_NAME"
Gdk-Message: 16:42:08.060: property notify:	window: 18874370, atom(40): "WM_NORMAL_HINTS"
Gdk-Message: 16:42:08.060: property notify:	window: 18874370, atom(36): "WM_CLIENT_MACHINE"
Gdk-Message: 16:42:08.060: property notify:	window: 18874370, atom(344): "WM_LOCALE_NAME"
Gdk-Message: 16:42:08.060: property notify:	window: 18874370, atom(310): "_NET_WM_PID"
Gdk-Message: 16:42:08.060: property notify:	window: 18874370, atom(343): "WM_CLIENT_LEADER"
Gdk-Message: 16:42:08.060: property notify:	window: 18874370, atom(360): "_NET_WM_USER_TIME_WINDOW"
Gdk-Message: 16:42:08.060: property notify:	window: 18874370, atom(319): "_NET_WM_SYNC_REQUEST_COUNTER"
Gdk-Message: 16:42:08.060: property notify:	window: 18874370, atom(308): "_NET_WM_WINDOW_TYPE"
Gdk-Message: 16:42:08.060: property notify:	window: 18874370, atom(585): "_NET_WM_OPAQUE_REGION"
Gdk-Message: 16:42:08.060: property notify:	window: 18874370, atom(387): "XdndAware"
Gdk-Message: 16:42:08.060: property notify:	window: 18874370, atom(40): "WM_NORMAL_HINTS"
Gdk-Message: 16:42:08.060: property notify:	window: 18874370, atom(587): "_GTK_THEME_VARIANT"
Gdk-Message: 16:42:08.061: property notify:	window: 18874370, atom(35): "WM_HINTS"
Gdk-Message: 16:42:08.061: property notify:	window: 18874370, atom(286): "_NET_WM_DESKTOP"
Gdk-Message: 16:42:08.063: property notify:	window: 18874370, atom(294): "_NET_WM_ALLOWED_ACTIONS"
Gdk-Message: 16:42:08.063: property notify:	window: 18874370, atom(257): "WM_STATE"
Gdk-Message: 16:42:08.063: reparent notify:	window: 18874370  x,y: 0 0  parent: 8388772	ovr: 0
Gdk-Message: 16:42:08.063: configure notify:	window: 18874370  x,y: 0 0	w,h: 800 600  b-w: 0  above: 0	 ovr: 0
Gdk-Message: 16:42:08.064: map notify:		window: 18874370
Gdk-Message: 16:42:08.065: visibility notify:	window: 18874370	 full
Gdk-Message: 16:42:08.065: expose:		window: 18874370  0	x,y: 0 0  w,h: 00 600
Gdk-Message: 16:42:08.066: enter notify:	window 18874370
	subwindow:0
	device: 2
	source device: 2
	notify type: 3
	crossing mode: 0
Gdk-Message: 16:42:08.071: focus out:		window: 18874370, detail: NotifyNonlinear, mode: NotifyNormal
Gdk-Message: 16:42:08.072: property notify:	window: 18874370, atom(273): "_NET_WM_STATE"
Gdk-Message: 16:42:08.072: property notify:	window: 18874370, atom(257): "WM_STATE"
Gdk-Message: 16:42:08.161:     0: layout_start=0.0  paint_start=0.1  frame_end=87.6 predicted=16.7
dk-Message: 16:49:18.403: key press:	window 18874370
	device:3
	source device:6
	key number: 64
Gdk-Message: 16:49:18.407: property notify:	window: 18874370, atom(323): "_NET_WM_USER_TIME"
Gdk-Message: 16:49:18.531: focus out:		window: 18874370, detail: NotifyAncestor, mode: NotifyGrab
Gdk-Message: 16:49:18.532: delete window:		window: 18874370

The “OpenGL Area” example of gtk3-demo cannot display any content neither

I print some debug code on my opengles.cpp and found that it does not trigger render event and entry the function.

Does this issue have anything to do with GtkGLArea doesn't work on GLES-only systems (#5330) · Issues · GNOME / gtk · GitLab ?

That issue is for GTK4, not GTK3.

Well, I think the problem is not on my environment as I can cross compile src/egl/opengles2/es2tri.c · main · Mesa / demos · GitLab and run successfully on my system :joy:

Maybe something wrong with my opengles.cpp :thinking: