I am trying to create a game loop for an xlib window, but I cannot manage to paint the window correctly. Right now I am creating a window with XCreateSimpleWindow(...), and
Communicating directly with Xlib is so early-90s (read: noone has done this, unless he's a framework designer, in the last 20 years!).
You're right, looping through pixels to update them on the screen is incredibly slow. That's why almost all modern GUI Frameworks use their own Xbuffers that they just draw on and instruct X to render.
As a comment on your approach: Game development on raw X doesn't make the least sense, as there are more protable, better performing, easier to use, small, well-tested libraries. Take SDL as an example.
The reason you are not seeing anything is because you are neglecting the X event loop. All you do is sending data to the X server, but there is no way for the X server to communicate back.
You must set up a loop where XEvents are read from the queue and dispatched c.q. processed. Something like:
XEvent event;
while (XPending (m_display))
{
XNextEvent (m_display, &event);
if (XFilterEvent (&event, None))
{
continue;
}
switch (event.type)
{
case KeyPress:
..
case ButtonPress:
..
case Expose:
..
case MapNotify:
..
// etc
}
}
This can be combined with your endless loop, though.
But yes, painting pixel by pixel is extremely slow. I don't even want to calculate the protocol overhead... :P