gokernel
(usa Linux Mint)
Enviado em 12/01/2010 - 12:31h
Depois de pesquisar muito aprendi como fazer um programa usando o FRAME BUFFER, para criar um modulo nativo GRÁFICO para LUA.
Para quem interessar, vai o codigo.
//###################################################################
//-------------------------------------------------------------------
// Example of basic FRAME BUFFER program.
// Code from: busybox-1.15.3(fbsplash.c)
//-------------------------------------------------------------------
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <getopt.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include <stdio.h>
#define BITS_PER_PIXEL 2
#define USHORT unsigned short
struct _fbb {
struct fb_var_screeninfo info;
unsigned char *addr; // pointer to framebuffer memory
}fbb;
int FBB_base_init() {
int fd;
if ( (fd = open("/dev/fb0", O_RDWR)) < 0 ) {
printf("'/dev/fb0' NOT FOUND.\n");
return 0; // ERROR
}
ioctl(fd, FBIOGET_VSCREENINFO, &fbb.info);
// map the device in memory
fbb.addr = mmap(NULL, fbb.info.xres * fbb.info.yres * BITS_PER_PIXEL,
PROT_WRITE, MAP_SHARED, fd, 0);
close(fd); // No need.
// Only 16 Bits
if (fbb.info.bits_per_pixel == 16)
return 1;
else {
printf("ERROR: Suport only FRAME BUFFER 16 Bits.\n");
return 0;
}
}
//-------------------------------------------------------------------
// NAME: FBB_base_makecol.
// USE: color = FBB_base_makecol(255, 130, 30);
//
// DESC:
// Make a color only in 16 bits.
//
// CODE BASEAD IN:
// See file: from busybox-1.15.3: /miscutils/fbsplash.c
// Function: static void fb_drawfullrectangle(...).
// Copyright (C) 2008 Michele Sanges <michele.sanges@gmail.com>
//
// BY: gokernel
//-------------------------------------------------------------------
int FBB_base_makecol(unsigned char r, unsigned char g, unsigned char b) {
r >>= 3; // 5-bit red
g >>= 2; // 6-bit green
b >>= 3; // 5-bit blue
return b + (g << 5) + (r << (5+6));
}
// Put PIXEL
void FBB_base_putpixel(short x, short y, register unsigned short color) {
register unsigned short *pointer;
pointer = (USHORT*)(fbb.addr + (y * fbb.info.xres + x) * BITS_PER_PIXEL);
*pointer = color; // <-- Put HERE;
}
// Horizontal Lines
void FBB_base_hline(short x1, short y, short x2, register unsigned short color) {
register short count;
register unsigned short *pointer;
// horizontal lines
pointer = (USHORT*)(fbb.addr + (y * fbb.info.xres + x1) * BITS_PER_PIXEL);
count = x2 - x1;
do {
*pointer++ = color;
} while (--count >= 0);
}
// Vertical Lines
void FBB_base_vline(short x, short y1, short y2, register unsigned short color) {
register short count;
register unsigned short *pointer;
// vertical lines
pointer = (USHORT*)(fbb.addr + (y1 * fbb.info.xres + x) * BITS_PER_PIXEL);
count = y2 - y1;
do {
*pointer = color;
pointer += fbb.info.xres; // Screen HEIGHT;
} while (--count >= 0);
}
int main() {
int color;
if ( !FBB_base_init() )
return 1; // ERROR
// Color ORANGE
color = FBB_base_makecol(255, 130, 30);
FBB_base_putpixel(150, 150, color);
FBB_base_hline(100, 100, 500, color);
FBB_base_vline(100, 100, 500, color);
return 0;
}
//###################################################################