title: How to display an image into an XCB window?
body: <p>I'm having trouble displaying an image (PNG extracted with libpng) into an XCB window, it is always entirely empty/white. I'm pretty sure the PNG extraction is correct since I can perfectly re-write it into another file.</p>
  
  <p>I've tried everything I found (explanations, guides, documentation) and I'm running out of ideas:</p>
  
  <ul>
  <li>Creating an <code>xcb_pixmap_t</code> calling <code>xcb_create_pixmap_from_bitmap_data()</code> with the data taken from the PNG, then calling <code>xcb_copy_area()</code> into the EXPOSE part of the event loop.</li>
  <li>Creating an <code>xcb_image_t*</code> calling <code>xcb_image_create_from_bitmap_data()</code> then trying to map it to the window with <code>xcb_image_put()</code>. I've even tried to display each pixel with <code>xcb_image_put_pixel()</code>, but without success.</li>
  </ul>
  
  <p>Code sample:</p>
  
  <pre><code>  xcb_pixmap_t pixmap = xcb_create_pixmap_from_bitmap_data(
                              connection, // xcb_connect(0, 0)    (type: xcb_connection_t*)
                              window, // xcb_generate_id(connection)    (type: xcb_window_t)
                              img.getData(), // uint8_t*
                              img.getWidth(), // 128
                              img.getHeight(), // 128
                              img.getBitDepth(), // 8
                              screen-&gt;black_pixel, // screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data    (type: xcb_screen_t*)
                              screen-&gt;white_pixel,
                              nullptr);
  
     // "img" is an instance of my own custom class, result of PNG reading
    xcb_image_t* image = xcb_image_create_from_bitmap_data(
                                img.getData(),
                                img.getWidth(),
                                img.getHeight()); // image-&gt;data seems fine
  
    xcb_image_put(connection,
                  window,
                  graphicsContext,
                  image, 0, 0, 0); // This does nothing
  
    for (unsigned int i = 0; i &lt; screen-&gt;height_in_pixels; ++i)
      for (unsigned int j = 0; j &lt; screen-&gt;width_in_pixels; ++j)
        xcb_image_put_pixel(image, j, i, 0); // Displays nothing
  
    [...]
  
    // Into event loop
    case XCB_EXPOSE: {
      xcb_expose_event_t* exposeEvent = reinterpret_cast&lt;xcb_expose_event_t*&gt;(event);
      xcb_copy_area(connection,
                    pixmap,
                    window,
                    graphicsContext,
                    exposeEvent-&gt;x, exposeEvent-&gt;y, // Top left x &amp; y coordinates of the source's region to copy
                    exposeEvent-&gt;x, exposeEvent-&gt;y, // Top left x &amp; y coordinates of the destination's region to copy to
                    exposeEvent-&gt;width,
                    exposeEvent-&gt;height);
      xcb_flush(connection);
      break;
    }
  </code></pre>
  
  <p>From the examples I found I saw that it didn't need a colormap, but could that be the case? Could anyone tell me where I've gone wrong?</p>