I was expecting a Linux API similar to the Windows API. All I see on Google is references to Qt and GTK. I really don't need anything more than a simple window to draw on with OpenGL, so these libraries appear bloated for my use. What do Qt and GTK use to create windows under Linux? Is there nothing more low-level?
-
2The X Windows API is typically the lowest level API for generic "Windowing" on *nix. http://tronche.com/gui/x/xlib/introduction/ – Chad Jun 25 '12 at 14:14
-
I am curious: why would you expect "linux api" (whatever you mean by that exactly) to be the same as winapi? – PlasmaHH Jun 25 '12 at 14:17
-
1You really don't want to go lower level. Use one of the higher level abstractions (QT/GTK/WxLib/More) otherwise you will get stuck in a lot of minutia that you don't want to handle that the higher level frameworks take care off. They all allow you to get hold of an OpenGL layer and draw on it. – Martin York Jun 25 '12 at 18:46
-
20If someone ask for the lowest possible API, please answer on that question. Please don't talk about "why use that, use this, ....". – parzival Mar 12 '16 at 13:34
6 Answers
The X window system generally does the drawing - you then use a toolkit such as Qt or GTK on top of raw Xlib to provide event loops, drag and drop, starting apps on mouseclicks and all the other 'desktop' stuff
It's fairly easy to work directly with Xlib and opengl or if you just want to learn opengl the glut provides the framework you need to display a window, handle mouse/keyboard events and so on.

- 94,801
- 28
- 188
- 263
-
1In principle, you could even avoid Xlib and just transmit (and receive, and interpret) raw X11 protocol. But that is not reasonable. – Basile Starynkevitch Jun 26 '12 at 05:45
For OpenGL, the easiest way to do it is by using GLUT or SDL. Here's an approximate example using GLUT:
#include <GL/glut.h>
int main (int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("My new window");
/* ... */
}
You really want to avoid using Xlib directly as it's extremely tedious to use. Furthermore, GLUT and SDL make it easier to port your OpenGL application to different platforms.

- 5,452
- 2
- 27
- 39
-
-
@LokiAstari: If you mean some kind of opaque type that holds the drawing state, I don't really know. When I used to code in OpenGL (back in version 1.2), there was only one, global, place to draw which was handled internally by the OpenGL implementation. – C2H5OH Jun 25 '12 at 20:06
Updated answer for 2019. Unix like systems normally uses the X window system. You can work with it directly using Xlib this is the low level API. But you likely need a more welcoming and cross-platform solution. You can use:
- OpenGL Utility Toolkit - GLUT
- Simple and Fast Multimedia Library - SFML
- Simple DirectMedia Layer - SDL
- Graphics Library Framework - GLFW (my recommendation)
GLFW is written in C and has native support for Windows, macOS and many Unix-like systems using the X Window System, such as Linux and FreeBSD.
Once installed, create a window with :
#include <GLFW/glfw3.h>
.
. //Entry and glfwInit()
.
GLFWwindow* window = glfwCreateWindow(1000, 1000, "MyWindow", NULL, NULL);
glfwMakeContextCurrent(window);

- 13
- 5

- 1,080
- 1
- 12
- 14
Ax Martin said, X11 (or its fork XOrg these days) is the windowing system, but you can actually write X11 applications (i.e. clients) without using a toolkit, just using the X libraries. See here for documentation.
It is generally not the best idea to do so, as it is rather painful and will involve a lot of code for relatively simple applications to work as you expect them to.

- 3,689
- 18
- 22
I know this is an old post. But for people that have found this recently like me here is a useful diagram. It is just a matter of how far down do you want/need to go in abstraction; if you arent careful you'll end up trying to code in binary. XLib is a dependency for SFML and XLib has it's dependencies.

- 21
- 1
Assuming by simple window you mean the drawing should appear on the screen: The Weston compositor uses EGLOutput/EGLDevice to display the composited Weston desktop or individual Wayland applications on a physical display device.
For drawing with other manufacturer's hardware studying GEM may give hints.

- 1,636
- 15
- 28