Search code examples
openglxlib

How to draw 2d text on in Xlib window which is using opengl?


I am using opengl in a Xlib window.How do I draw text on this window (not in 3d)?


Solution

  • You can use the usual X font drawing functions. In a single buffered window OpenGL is just another drawing primitive. In a double buffered Window after the glXSwapBuffers you need to XSync but then can draw over the OpenGL drawing using X font primitives (you can also use Xft).

    However note that in the case of a double buffered OpenGL window you can not freely mix X text with OpenGL.

    Update:

    Also if you have the GLX_ARB_texture_from_pixmap extension available (which main use is the implementation of compositors, but you can use it for other things as well): You can draw your text into a server side X11 pixmap using the regular X11 drawing primitives (+ X11 extensions like XRender and Xft), and then bind that very pixmap to a OpenGL texture unit as image source.

    Of course using any of the X11 specialized functions locks your program to X11.