You are here

Porting an OpenGL program from X11 to Wayland (using jwzGLES & EGLX)

Objectives : make an X11/GLX program run natively on Wayland/EGL, with minimal modifications to the code.

The Linux world is rapidly migrating from the legacy X11 display protocol and server, to Wayland. There are a lot of reasons why this change is necessary, but it's best watching this conference to understand why X is now left behind.

However, there are a few challenges, especially when it comes to OpenGL programs.

There a few different OpenGL APIs today (GL1, GL2, GL3, GLES1, GLE2...) ; on the desktop, the most popular has always been GL1/GL2, whereas GLES, by contrast, is mostly used on mobile OSes (Android, iOS...).
We also need more than pure OpenGL to draw to the screen : a glue for the underlying window system. It's called WGL on Windows, CGL on Mac OS X, and traditionally GLX on Linux/X11.

For instance, our good ol' glxgears benchmark runs on X11 using OpenGL1 and GLX :

glxgears running with GL/GLX

And now, here comes the problem : Wayland doesn't support desktop GL nor GLX.
Instead, it only supports GLES with a new binding named EGL.

We'd normally be forced to rewrite all our implementation code. But let's see how to deal with this case with minimum effort.

Wrapping OpenGL with jwzGLES

One year ago, jwz needed to port xscreensaver to the iPhone. As the iPhone knows GLES and nothing else, he wrote a GL-to-GLES1 wrapper which one can download from various places.

So for a code including GL headers :

#include <GL/gl.h>

we basically replace them with jwzGLES/GLES1 ones :

#include <GLES/gl.h>
#include "jwzgles.h"

And to link replace :
with :
-lGLESv1_CM -DHAVE_JWZGLES -ljwzgles

Wrapping GLX with EGLX

I recently needed to port a GLX program under native Wayland ; so I wrote the EGLX wrapper, which remaps GLX calls to EGL-Wayland ones (hence the name ;-) ).

You can download it from here with :
git clone
or alternatively download a tarball :
EGLX_0.1.tar.bz2 (88.9 Kb)

So for a code including GLX headers :

#include <GL/glx.h>

we basically replace them with EGLX ones :

#include "EGLX.h"

and put at the beginning of the main() function :

EGLX_main (0); 

And to link add :

Real implementation : glxgears under Wayland

In the EGLX source tree, once you've compiled the library, have a look at the modified version of "examples/glxgears.c".
Then build it with :
And run it with :

Wrapped glxgears running on Wayland ; note you can move the surface with the pointer

Here we go !

A video a available HERE.


Hope this is not out-of-date.
Did not read the source-code,but what happened to the "Depth" of the green wheel in the wayland-Version?
Thanks for your work.
Kind regards

Hello Herr Schwarz,

You mean the Z-order ? Yes, it's a bug in the jwzgles wrapper. As my work concentrates on porting code rather than doing pure OpenGL rendering, I didn't fix this. I suppose someone (or I) *may* do it eventually.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.