You are not logged in.

#1 2008-03-01 03:50:50

sharkconi
Member
Registered: 2007-06-20
Posts: 10

how to show graphic framebuffer program

Dear All:
  I write a sample frambuffer program according to <framebuffer How to>. I successfully compile the program, but nothing appears.
According to the program, it will paint some color on the screen. I run the program, there's nothing changed.
The following are my configurations:
  boot (hd0,0)
kernel /boot/vmlinuz ro root=/dev/sda1  vga=771
  initrd /boot/kernel26.img

There's the program:
int main()
{
        int fbfd = 0;
        struct fb_var_screeninfo vinfo;
        struct fb_fix_screeninfo finfo;
        long int screensize = 0;
        char *fbp = 0;
        int x = 0, y = 0;
        long int location = 0;

        /* Open the file for reading and writing */
        fbfd = open("/dev/fb0", O_RDWR);
        if (!fbfd) {
                printf("Error: cannot open framebuffer device.\n");
                exit(1);
        }
        printf("The framebuffer device was opened successfully.\n");

        /* Get fixed screen information */
        if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
                printf("Error reading fixed information.\n");
                exit(2);
        }

        /* Get variable screen information */
        if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
                printf("Error reading variable information.\n");
                exit(3);
        }

        /* Figure out the size of the screen in bytes */
        screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
       
        /* Map the device to memory */
        fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,fbfd, 0);       
        if ((int)fbp == -1) {
        printf("Error: failed to map\
        framebuffer device to memory.\n"); exit(4);
        }
        printf("The framebuffer device was mapped to memory successfully.\n");


        x = 100; y = 100;       /* Where we are going to put the pixel */

        /* Figure out where in memory to put the pixel */
    location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
            (y+vinfo.yoffset) * finfo.line_length;

        *(fbp + location) = 100;    /* Some blue */
        *(fbp + location + 1) = 15;     /* A little green */
        *(fbp + location + 2) = 200;    /* A lot of red */
        *(fbp + location + 3) = 0;      /* No transparency */

        munmap(fbp, screensize);
        close(fbfd);
        return 0;
}
Can anyone tell me how to show the program on the screen?
Any ideas appreciated.

Offline

Board footer

Powered by FluxBB