LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-25-2013, 09:47 AM   #1
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Rep: Reputation: 255Reputation: 255Reputation: 255
C tutorial using framebuffer?


Hi,

After several tools made for the terminal and the raspberry, I would like to go to graphics.

This person did that already,
http://stackoverflow.com/questions/1...g-console-text

For my raspberry I would like to code a simple
but first ... learning a bit about framebuffer (without X).

There are very few tutorials about C and framebuffer.

Would you know several examples using ioctl(fd, KDSETMODE, KD_GRAPHICS) ?

Many thanks
 
Old 08-25-2013, 10:07 AM   #2
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Original Poster
Rep: Reputation: 255Reputation: 255Reputation: 255
Possible simple example to display a bitmap image:

http://repository.timesys.com/builds...-omap3530zoom/


Unfortunately it does not work.

I get a black screen in the console / tty


Code:
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

#include <sys/ioctl.h>
#include <sys/kd.h>


#define IMAGE_INTERVAL  10
#define X               480
#define Y               640
#define BITS_PER_PIXEL  16
#define BITS_PER_BYTE   8
#define SCREEN_SIZE (X * Y * ( BITS_PER_PIXEL / BITS_PER_BYTE ))




void show_bitmap (const char *image_name)
{
    int status, image_fd, fb_fd;
    unsigned char buffer[SCREEN_SIZE];

    fb_fd = open("/dev/fb0", O_RDWR);
    if (!fb_fd) {
        fprintf(stderr,"Could not open framebuffer.\n");
        exit(1);
    }

    image_fd = open("images/flower.bmp", O_RDONLY);
    if (image_fd < 0)
    {
        fprintf(stderr,"Failed to open image: %s\n", image_name);
        exit(1);
    }

    status = read(image_fd, (char*)buffer, SCREEN_SIZE);
    if (status < 0)
    {
        fprintf(stderr,"Failed to read image: %s\n", image_name);
        exit(1);
    }
    status = write(fb_fd, (const char*)buffer, SCREEN_SIZE);
    if (status < 0)
    {
        fprintf(stderr,"Failed to write image to buffer.\n");
        exit(1);
    }
    close(image_fd);
    close(fb_fd);
}




int main (int argc, char *argv[])
{
    int index = 1;
    int vconsole_fd; 

    if (argc < 2)
    {
        printf("Usage: %s [image] [image...]\n", argv[0]);
        exit(1);
    }
    
    /* open the framebuffer virtual console */
    vconsole_fd = open("/dev/tty0", O_RDWR);
    if (!vconsole_fd) {
        fprintf(stderr,"Could not open virtual console.\n");
        exit(1);
    }
    
    /* disable blanking on the console by setting the KD_GRAPHICS mode */
    if (ioctl( vconsole_fd, KDSETMODE, KD_GRAPHICS))
    {
        fprintf(stderr,"Could not set virtual console to KD_GRAPHICS mode.\n");
        exit(1);      
    }

    close(vconsole_fd);

    /* no chdir and no stdio close */
    daemon(1,1);

    while (1)
    {
        show_bitmap(argv[index]);

        index++;
        if (index >= argc)
            index = 1;

        sleep(IMAGE_INTERVAL);
    }
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP-MySQL tutorial and Linux Networking tutorial needed Please dlux45 Linux - Software 6 04-19-2010 01:10 PM
framebuffer confusion with Hauppauge PVR 350 framebuffer /dev/fb0 tofino_surfer Linux - General 4 09-18-2008 11:36 PM
LXer: Tutorial: How to Write a Tutorial LXer Syndicated Linux News 0 08-01-2008 06:41 AM
LXer: Tutorial: An Easy Tutorial on IP Tables and Port Knocking LXer Syndicated Linux News 0 02-04-2008 04:20 PM
VESA framebuffer vs Intel framebuffer in Slackware 10.0 with default kernel brancalessio Slackware 3 01-20-2005 03:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration