1
votes

I have been studying lately OpenGL in university and searched on my own about Windows GUI programming in c++ like Qt. I even went deeper and found XLib for Windows GUI. But I still don't get the big picture.

I understand that Qt is build on-top of XLib. And to do OpenGL I need to define context through some libraries like GLUT. From what I understand, GLUT is basically a library that connects between XLib and OpenGL through something called GLX.

I also get that OpenGL runs on the GPU, and that XLib is embedded into the operating system. So what happens when the operating system is installed on computer that doesn't have a GPU. As far as I know it will work. Does that mean XLib does not rely on OpenGL to draw Windows and such? If so, what does it rely on? Or maybe it draws it pixel by pixel through some driver.

In short, how does LibX implement its GUI elements, is it through openGL or something else?

Note 1: I am referring with 'Windows GUI' to buttons, text box and window generations and such. Note 2: I am running on Linux.

1
I don't know the details, but this may help: OpenGL is only a specification, it's driver can be implemented in a wide range of possibilities from GPU to full software emulation.lisyarus

1 Answers

5
votes

Xlib is the traditional client side implementation of the X11 protocol. The modern (replacement for Xlib) client side implementation would be Xcb, however OpenGL/GLX are a bit of a hassle to use with Xcb. X11 has nothing to do with Microsoft Windows. Xlib/Xcb are essentially protocol implementations that turn function calls into a stream of commands sent to the X11 server. One of these commands for example would be "draw a line with the color black from point (x0,y0) to point (x1,y1)".

On Microsoft Windows the underlying graphics system is the GDI. It's similar in its functionality to X11, however programs are calling directly to it instead of talking through a serialized command protocol like X11 does.

Qt is not built on top of Xlib, nor Xcb. Rather X11 is one of the possible graphics backends that can be used with Qt. If running on Microsoft Windows the backend used by Qt (and incidently OpenGL) is the GDI, and when it comes to OpenGL there are some GDI functions, forming the set of the WGL API. WGL is to GDI what GLX is to X11.

OpenGL contexts are created with a graphics system specific API: GLX on X11, WGL on Microsoft Windows, CGL on MacOS X. An OpenGL context can be made current on a drawable, which is usually a window of the underlying graphics system. Then OpenGL calls are sent either through the graphics system or bypassing that directly to the graphics driver.

Also OpenGL does not run on the GPU. OpenGL is an API and the API calls ultimately go to the graphics drivers, which then talks to the GPU, translating OpenGL calls into GPU command buffers that are then transferred to the GPU and executed there.

In short, how does LibX implement its GUI elements, is it through openGL or something else?

It sends plain X11 drawing commands to the X server. A GUI toolkit can make use of the graphics primitives offered by X11, or OpenGL to draw nice widgets.