从 C 语言在 Linux 的帧缓冲区上绘制文本

发布于 2024-08-13 22:10:11 字数 163 浏览 4 评论 0原文

程序如何在映射为数组的帧缓冲区上绘制文本?所需要的是一种表示各个字符的方法,以及以不太低效的方式逐像素绘制字符的方法。理想情况下,字符的表示应仅在代码中定义,并且不需要第三方库。

有谁知道在自由许可下可以执行此操作的代码吗?或者为程序代码中使用的字体生成数据定义的工具,例如位图字形/字符值数组?

How can a program draw text on a frame buffer mapped in as an array? What is needed is both a means of representing the individual characters, and of drawing the characters pixel by pixel in a manner that is not too inefficient. The representation of the characters should ideally be defined solely in code, and no third party libraries would be required.

Does anyone know of code to do this available under a liberal license? Or a tool to generate data definitions for the font for use in program code e.g. the array of bitmap glyph/character values?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

枫以 2024-08-20 22:10:11

我没有任何特定于帧缓冲区的信息,但我确实有一种有趣的字体编码方法。

如果您有一个可以写入 XBM 格式 的应用程序,您可以通过以下方式对字体进行编码创建包含所有字符的图像。 XBM 文件可以作为 C 或 C++ 文件包含在内,并且通过使用正确的偏移量,您可以轻松访问单个字符。确保每个字符从可被 8 整除的 X 坐标开始,因为图像被编码为每像素一位;任何不在 8 位边界上排列的内容都需要屏蔽和移位。

I don't have any information specific to frame buffers, but I do have an interesting way of encoding a font.

If you have an application that can write to the XBM format, you can encode a font just by creating an image containing all the characters. The XBM file can be included as a C or C++ file, and by using the proper offsets you can easily access a single character. Make sure each character starts at an X-coordinate divisible by 8, because the image is coded as one bit per pixel; anything that doesn't line up on an 8-bit boundary will need masking and shifting.

妥活 2024-08-20 22:10:11

我认为最好的方法是使用位图字体: http:// www.iua.upf.es/~ggeiger/redbookhtml/ch09.html。本教程适用于 OpenGL,但您可能会发现很多有用的信息。

I think the best way to do it is using bitmap fonts: http://www.iua.upf.es/~ggeiger/redbookhtml/ch09.html. This tutorial is for OpenGL but you probably find a lot of useful info.

昔梦 2024-08-20 22:10:11

要在 2D 数组上绘制一条线,请使用 Besengam 算法

要使用直线绘制字符,请使用一系列 moveTo、lineTo 构建字母表。例如,对于一个简单的“L”:

image.moveTo(0,-fontHeight);
image.lineTo(0, 0);
image.lineTo(fontWidth,0);

To draw a line on a 2D array, use the Besengam's algorithm.

To draw the characters using straight lines , build your alphabet using a series of moveTo, lineTo. E.g. for a simple 'L':

image.moveTo(0,-fontHeight);
image.lineTo(0, 0);
image.lineTo(fontWidth,0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文