Affichage avec le framebuffer Linux

Fermé
amal89 Messages postés 1 Date d'inscription vendredi 1 juin 2012 Statut Membre Dernière intervention 1 juin 2012 - Modifié par mamiemando le 2/06/2012 à 14:32
Bogomips Messages postés 123 Date d'inscription mardi 5 avril 2011 Statut Membre Dernière intervention 18 mars 2015 - 2 juin 2012 à 14:57
Bonjour,

j'utilise le code de synthèse 3D celui de shaune Daure s'executant sur une plateforme windows avec compilateur turboC3
j'ai voulu afficher la matrice virtuelle sur le système linux embarqué(carte devkit8000) en accédant directement au framebuffer(sans utilisation d'une biblio graphique)
j'ai utilisé le code suivant:

#include <stdlib.h>  
#include <unistd.h>  
#include <stdio.h>  
#include <fcntl.h>  
#include <linux/fb.h>  
#include <sys/mman.h>  
#include <sys/ioctl.h>  

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 == -1) {  
        perror("Error: cannot open framebuffer device");  
        exit(1);  
    }  
    printf("The framebuffer device was opened successfully.\n");  

    // Get fixed screen information  
    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {  
        perror("Error reading fixed information");  
        exit(2);  
    }  

    // Get variable screen information  
    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {  
        perror("Error reading variable information");  
        exit(3);  
    }  

    printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);  

    // 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) {  
        perror("Error: failed to map framebuffer device to memory");  
        exit(4);  
    }  
    printf("The framebuffer device was mapped to memory successfully.\n");  

    x = 0; y = 0;       // Where we are going to put the pixel  
int k=0;  

    // Figure out where in memory to put the pixel  
    for (y = 0; y < 480; y++)  
        for (x = 0; x < 800; x++) {  

            location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +  
                       (y+vinfo.yoffset) * finfo.line_length;  

           // if (vinfo.bits_per_pixel == 32) {  
              //  *(fbp + location) = virtuel[k+2];        // Some blue  
              //  *(fbp + location + 1) = virtuel[k+1];     // A little green  
              //  *(fbp + location + 2) = virtuel[k];    // A lot of red  
              //  *(fbp + location + 3) = 0;      // No transparency  
                  
                *(fbp + location) = 250;  
                *(fbp + location + 1) =250;  
                *(fbp + location + 2) = 250;  
                *(fbp + location + 3) = 0;      // No transparency  
k+=3;  
                  
        location += 4;  

        }  
    munmap(fbp, screensize);  
    close(fbfd);  
    return 0;  
}  


Mais pour le résultat j'ai eu une succession de forme 2D non 3D au lieu d'avoir un seul objet 3D
SVP il y a t'il quelqu'un qui peut m'aider

merciii

A voir également:

2 réponses

mamiemando Messages postés 33654 Date d'inscription jeudi 12 mai 2005 Statut Modérateur Dernière intervention 4 mai 2025 7 847
2 juin 2012 à 14:36
Petite erreur ici :

if ((int)fbp == -1)


... devrait s'écrire :

if (fbp == (void *) -1)


Bon à part ça je n'ai pas pu tester le programme (et je ne peux pas changer ma configuration pour activer le framebuffer) :(

(mando@aldur) (~) $ ./a.out 
Error: cannot open framebuffer device: No such file or directory


Bonne chance
0
Bogomips Messages postés 123 Date d'inscription mardi 5 avril 2011 Statut Membre Dernière intervention 18 mars 2015 16
2 juin 2012 à 14:57
Salut

J'ai obtenu un grand rectangle rose.
0