How to create a game loop with xlib

后端 未结 2 2038
情深已故
情深已故 2020-12-21 07:52

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

2条回答
  •  我在风中等你
    2020-12-21 08:45

    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

提交回复
热议问题