如何画用C语言在framebuffer的图形..? [英] How to draw the graph in framebuffer using c language..?
问题描述
我是新来的这本Linux的framebuffer所以不要任何人指导我绘制帧缓冲线路图。和我有code绘制在Turbo C的图形,但现在在Linux。所以,请帮助我。
i am new to this linux framebuffer so do anybody guide me to draw the line-graph in framebuffer. And i have the code to draw graph in turbo c but now in linux. So please help me out.
感谢您,
拉胡尔
Thank You, Rahul
推荐答案
使用 的open()
在正确的文件的/ dev
(如的/ dev / fb0设备
),然后使用 mmap()的
映射入存储器。联机手册将帮助这些系统调用,如果你不知道如何使用它们。
Use open()
on the right file in /dev
(eg. /dev/fb0
), then use mmap()
to map it into memory. Manpages will help for these syscalls if you do not know how to use them.
然后有一些 的ioctl() 一些结构和常量code> S IN
< Linux的/ fb.h>
。像许多内核头文件,你可以学到很多简单的浏览文件。
Then there are some structures and constants for some ioctl()
s in <linux/fb.h>
. Like many kernel headers, you can learn a lot simply browsing the file.
特别有趣的是读写控制 FBIOGET_VSCREENINFO
与结构fb_var_screeninfo
。请注意,这有 XRES
, yres
(分辨率)和 bits_per_pixel
。此外,还有 FBIOGET_FSCREENINFO
和结构fb_fix_screeninfo
里面有像更多信息键入
和 line_length
。
Particularly interesting is the ioctl FBIOGET_VSCREENINFO
with struct fb_var_screeninfo
. Note this has xres
, yres
(resolution) and bits_per_pixel
. Then there's FBIOGET_FSCREENINFO
and struct fb_fix_screeninfo
which has further information like type
and line_length
.
因此,在(X,Y)的像素可能会在 mmap_base_address + X * bits_per_pixel / 8 + Y * line_length
。像素将取决于你通过ioctl检索结构的具体格式;这是你的工作,以决定如何读/写。
So a pixel at (x, y) might be at mmap_base_address + x * bits_per_pixel/8 + y * line_length
. The exact format of the pixels will depend on the structures you retrieve via ioctl; it's your job to decide how to read/write them.
这是一段时间,因为我跟这个工作,所以我的更多细节几分朦胧..
It's been a while since I've worked with this so I'm a bit hazy on more details..
下面是一个快速和肮脏的code样品只是为了说明它是如何做......我没有测试过这一点。
Here's a quick and dirty code sample just to illustrate how it's done... I haven't tested this.
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <linux/fb.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
int main()
{
struct fb_var_screeninfo screen_info;
struct fb_fix_screeninfo fixed_info;
char *buffer = NULL;
size_t buflen;
int fd = -1;
int r = 1;
fd = open("/dev/fb0", O_RDWR);
if (fd >= 0)
{
if (!ioctl(fd, FBIOGET_VSCREENINFO, &screen_info) &&
!ioctl(fd, FBIOGET_FSCREENINFO, &fixed_info))
{
buflen = screen_info.yres_virtual * fixed_info.line_length;
buffer = mmap(NULL,
buflen,
PROT_READ|PROT_WRITE,
MAP_SHARED,
fd,
0);
if (buffer != MAP_FAILED)
{
/*
* TODO: something interesting here.
* "buffer" now points to screen pixels.
* Each individual pixel might be at:
* buffer + x * screen_info.bits_per_pixel/8
* + y * fixed_info.line_length
* Then you can write pixels at locations such as that.
*/
r = 0; /* Indicate success */
}
else
{
perror("mmap");
}
}
else
{
perror("ioctl");
}
}
else
{
perror("open");
}
/*
* Clean up
*/
if (buffer && buffer != MAP_FAILED)
munmap(buffer, buflen);
if (fd >= 0)
close(fd);
return r;
}
这篇关于如何画用C语言在framebuffer的图形..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!