繁体   English   中英

X11-图形渲染改进

[英]X11 - Graphics Rendering Improvement

我目前正在将无符号整数数组呈现给窗口上的2D图像,但是,对于我要完成的操作而言,它太慢了。 这是我的代码:

int x = 0;
int y = 0;

GC gc;
XGCValues gcv;
gc = XCreateGC(display, drawable, GCForeground, &gcv);

while (y < height) {
    while (x < width) {
            XSetForeground(display, gc, AlphaBlend(pixels[(width*y)+x], backcolor));
            XDrawPoint(display, drawable, gc, x, y);
            x++;
    }
    x = 0;
    y++;
}

XFlush(display);

我想知道是否有人向我展示了一种更快的方法,同时仍将我的无符号整数数组用作绘制到窗口的基本图像并将其保留在X11 API中。 我想让它尽可能独立。 我不想使用OpenGL,SDL或其他不需要的其他图形库。 谢谢。

我认为使用XImage可以满足您的需求:请参阅https://tronche.com/gui/x/xlib/graphics/images.html

XImage * s_image;

void init(...)
{
    /* data linked to image, 4 bytes per pixel */
    char *data = calloc(width * height, 4);
    /* image itself */
    s_image = XCreateImage(display, 
        DefaultVisual(display, screen),
        DefaultDepth(display, screen), 
        ZPixmap, 0, data, width, height, 32, 0);
}

void display(...)
{
    /* fill the image */    
    size_t offset = 0;
    y = 0;
    while (y < height) {  
        x = 0;
        while (x < width) {
            XPutPixel(s_image, x, y, AlphaBlend((pixels[offset++], backcolor));
            x++;
        }    
        y++;
    }

    /* put image on display */
    XPutImage(display, drawable, cg, s_image, 0, 0, 0, 0, width, height);

    XFlush(display);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM