我无法在XCB窗口中显示图像(使用libpng提取的PNG格式),它总是完全空白/白色。 我相信PNG提取是正确的,因为我可以将其完美地重写到另一个文件中。
我尝试了我能找到的一切(说明、指南、文档),但已经没有任何想法:
- 创建一个
xcb_pixmap_t
,使用从PNG中获取的数据调用xcb_create_pixmap_from_bitmap_data()
,然后在事件循环的EXPOSE部分调用xcb_copy_area()
。 - 创建一个
xcb_image_t*
,使用xcb_image_create_from_bitmap_data()
创建,然后尝试使用xcb_image_put()
将其映射到窗口。 我甚至尝试使用xcb_image_put_pixel()
来显示每个像素,但没有成功。
代码示例:
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->black_pixel, // screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data (type: xcb_screen_t*)
screen->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->data seems fine
xcb_image_put(connection,
window,
graphicsContext,
image, 0, 0, 0); // This does nothing
for (unsigned int i = 0; i < screen->height_in_pixels; ++i)
for (unsigned int j = 0; j < screen->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<xcb_expose_event_t*>(event);
xcb_copy_area(connection,
pixmap,
window,
graphicsContext,
exposeEvent->x, exposeEvent->y, // Top left x & y coordinates of the source's region to copy
exposeEvent->x, exposeEvent->y, // Top left x & y coordinates of the destination's region to copy to
exposeEvent->width,
exposeEvent->height);
xcb_flush(connection);
break;
}
根据我找到的例子,我发现它不需要颜色映射,但这是真的吗? 有人能告诉我哪里错了吗?
XCB_COPY_FROM_PARENT
。通过将此字段替换为8
,窗口甚至都不会出现。 - Razakhelxcb_image_create
(如果我没记错的话,我之前已经尝试过了),但我一直收到段错误。我已经花了两天时间在这上面,只是因为XCB无法提供适当的文档。我想我会简单地创建GLX窗口(反正我以后还需要OpenGL)。 - Razakhel