title: What is the most efficient way to put multiple colours on a window, especially in frame-by-frame format?
body: <p>I am making a game with C and X11. I've been trying for quite a while to find a way to put different coloured pixels on a window, frame by frame. I've seen fully developed games get thousands of frames per second. What is the most efficient way of doing this?</p>
  
  <p>I have seen 2-coloured bitmaps with XImages, allocating 256 colours on a fade of black-white, and using XPutPixel with XImages (which I wasn't able to figure how to create an XImage properly that could later have pixels put on it).</p>
  
  <p>I have made this for loop that creates a random image, but it is, obviously, pixel-by-pixel instead of frame-by-frame and takes 18 seconds to render one entire frame.</p>
  
  <pre><code>XColor pixel;
  for (int x = 0; x &lt; currentWindowWidth; x++) {
      for (int y = 0; y &lt; currentWindowHeight; y++) {
          pixel.red = rand() % 256 * 256; //Converting 16-bit colour to 8-bit colour
          pixel.green = rand() % 256 * 256;
          pixel.blue = rand() % 256 * 256;
          XAllocColor(display, XDefaultColormap(display, screenNumber), &amp;pixel); //This probably takes the most time,
          XSetForeground(display, graphics, pixel.pixel); //as does this.
          XDrawPoint(display, window, graphics, x, y);
      }
  }
  </code></pre>