gokernel
(usa Linux Mint)
Enviado em 18/09/2018 - 06:01h
"theniel02", escreveu:
Não estou tentando criar uma janela com SDL, estou tentando executar o SDL em um linux sem interface gráfica.
Desculpe-me ao escrever isso:
Se compilar e executar ... se aparecer uma janela por 3 segundos, então o seu sistema funciona com SDL 1.x
Me expressei mau ... quis dizer:
"... se aparecer algo por 3 segundos, então o seu sistema funciona com SDL 1.x"
Aproveitando o ensejo, testa essa parada FB:
/*
**-------------------------------------------------------------------
**
** LIBFB: Linux Frame Buffer Library
**
** FILE:
** libfb.c
**
** START DATE: 28/06/2017 - 16:02
**
** BY: Francisco - gokernel@hotmail.com
**
**-------------------------------------------------------------------
*/
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <time.h>
//-------------------------------------------------------------------
//######################### ENUM / DEFINE #########################
//-------------------------------------------------------------------
#define UCHAR unsigned char
//-------------------------------------------------------------------
//############################# STRUCT ############################
//-------------------------------------------------------------------
//
typedef struct {
UCHAR *screen;
int smem_len; // fb_fix_info.smem_len
int w; // fb_var_info.xres
int h; // fb_var_info.yres
int bpp; // 8 | 16 | 32
int fd; // file id
char drive_name [20];
}FB_DRIVE;
struct fb_var_screeninfo fb_var_info;
struct fb_fix_screeninfo fb_fix_info;
FB_DRIVE FB;
int size;
int fb_init (void) {
static int init = 0;
if (init == 0) {
init = 1;
FB.fd = open ("/dev/fb0", O_RDWR);
if (FB.fd < 0) {
printf ("Frame Buffer Not Found ( /dev/fb0 )\n");
return 0;
}
ioctl (FB.fd, FBIOGET_FSCREENINFO, &fb_fix_info);
ioctl (FB.fd, FBIOGET_VSCREENINFO, &fb_var_info);
FB.smem_len = fb_fix_info.smem_len;
FB.w = fb_var_info.xres;
FB.h = fb_var_info.yres;
FB.bpp = fb_var_info.bits_per_pixel;
sprintf (FB.drive_name, "%s", fb_fix_info.id);
size = fb_var_info.xres * fb_var_info.yres * fb_var_info.bits_per_pixel / 8;
FB.screen = (UCHAR*) mmap (NULL, FB.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, FB.fd, 0);
printf ("... Starting LIBFB ...\n");
return 1;
}
return 0;
}
void fb_exit (void) {
munmap (FB.screen, FB.smem_len);
close (FB.fd);
}
void putpixel16 (int x, int y, unsigned short color) {
UCHAR *p;
p = (UCHAR*)(FB.screen + (y * FB.w + x) * 2);
*(unsigned short*)p = color;
}
void putpixel32 (int x, int y, int color) {
int location = (x+fb_var_info.xoffset) * (fb_var_info.bits_per_pixel/8) +
(y+fb_var_info.yoffset) * fb_fix_info.line_length;
if (fb_var_info.bits_per_pixel == 32)
*((unsigned int*)(FB.screen + location)) = color;
if (fb_var_info.bits_per_pixel == 16)
*((unsigned short*)(FB.screen + location)) = color;
}
int makecol16 (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));
}
int makecol32 (unsigned char r, unsigned char g, unsigned char b) {
return b + (g << 8) + (r << 16);
}
int main (void) {
int color;
if (fb_init()) {
printf ("Dive: %s\n", FB.drive_name);
printf (" w: %d\n", FB.w);
printf (" h: %d\n", FB.h);
printf (" bpp: %d\n", FB.bpp);
printf (" mem: %d\n", FB.smem_len);
printf ("size: %d\n", size);
printf (" fd: %d\n", FB.fd);
printf ("fb_fix_info.line_length: %d\n", fb_fix_info.line_length);
printf ("accel_flags: %s\n", (fb_var_info->accel_flags > 0 ? "true" : "false"));
printf ("----------------------------\n");
printf ("xres_virtual: %d\n", fb_var_info.xres_virtual);
printf ("yres_virtual: %d\n", fb_var_info.yres_virtual);
printf ("xoffset: %d\n", fb_var_info.xoffset);
printf ("yoffset: %d\n", fb_var_info.yoffset);
if (FB.bpp == 16)
color = makecol16(255,130,30); // orange
if (FB.bpp == 32)
color = makecol32(255,130,30);
putpixel32 (100, 100, color);
putpixel32 (101, 100, color);
putpixel32 (102, 100, color);
putpixel32 (103, 100, color);
putpixel32 (104, 100, color);
putpixel32 (105, 100, color);
putpixel32 (106, 100, color);
putpixel32 (107, 100, color);
putpixel32 (100, 130, color);
putpixel32 (101, 130, color);
putpixel32 (102, 130, color);
putpixel32 (103, 130, color);
putpixel32 (104, 130, color);
putpixel32 (105, 130, color);
putpixel32 (106, 130, color);
putpixel32 (107, 130, color);
fb_exit();
}
else printf ("Lib FB not Found\n");
return 0;
}
Esse código acima é um Frame Buffer para Linux ... não sei se vai funcionar no PI.
Se a libFB funcionar vai desenhar 2 pequenas "linhas".