How do you create a window in Linux with C++?

SteveDeFacto picture SteveDeFacto · Jun 25, 2012 · Viewed 35.4k times · Source

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?

Answer

Martin Beckett picture Martin Beckett · Jun 25, 2012

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.