使用 Xlib 启用抗锯齿
我正在尝试开发一组自定义库,用于在 Linux 中创建 GUI,其中包含小部件、按钮等。所以我现在正在学习使用 X11 及其 X11 创建用户界面em>Xlib。我得到了一个漂亮的窗口,它具有指定的大小、指定的位置、指定的背景颜色,并且可以绘制点、矩形、圆弧。然而,当我绘制第一个圆圈时,我对这个圆圈没有抗锯齿感到非常失望。我可以将每个像素视为一个正方形。
现在问题很简单了。有没有办法告诉X:请在绘制之前进行抗锯齿处理?或者我是否必须避免使用 XDrawArc 并使用为圆的每个点调用 XDrawPoint 的自定义函数?或者还有第三种解决方案?
提前致谢。
I'm trying to develop a custom set of libraries for creating GUIs in Linux, with, you know, widgets, buttons, etc. So I'm now learning to creating user interfaces using X11 and its Xlib. I get to the point of having a nice window of a size specified, at a position specified, of a specified background color, and the possibility of drawing points, rectangles, arcs. However as I drew my first circle I got really disappointed by the fact that the circle is not antialiased. I can see every single pixel as a square.
Now the question is easy. Is there any way to tell X: please antialias anything before drawing? Or do I have to avoid using XDrawArc and use a custom function which calls XDrawPoint for each point of the circle? Or there is a third solution?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简短的回答是“不”。 Xlib 不进行抗锯齿处理。
更长的答案是“您可以使用更高级别的 API,例如 Cairo Graphics”。没有必要自己动手。
The short answer is "no". Xlib doesn't do anti-aliasing.
The longer answer is "you can use a higher level API such as Cairo Graphics". It's not necessary to roll your own.
您遇到的是X11核心协议的限制;从技术上讲,完全有可能为其添加抗锯齿功能,但这并没有发生。
相反,有 XRender 扩展,它提供了很好的抗锯齿基元。您还需要研究 Xft 以使用矢量字体呈现抗锯齿文本。
What you encountered are the limitations of the X11 core protocol; technically it would be perfectly possible to add antialiasing to it, but that didn't happen.
Instead there's the XRender extension, that provides nice antialiased primitives. You'll also want to look into Xft to render antialiased text using vector fonts.
您可以推出自己的抗锯齿算法。您只需要 2 个基元:1)绘制 TrueColor 点的函数(即 xcb_poly_point(),如果您正在使用XCB),以及2)用于 循环。
You can roll your own antialiasing algorithm. You have the only 2 primitives you need: 1) a function to draw TrueColor points (namely, xcb_poly_point(), if you're using XCB), and 2) for loops.