Last active
December 17, 2018 08:45
-
-
Save spudro228/e72836de66f24b6943dea8076e957f9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <stdint.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <sys/ioctl.h> | |
#include <sys/mman.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
#include <linux/fb.h> | |
#define ANSI_COLOR_RED "\x1b[31m" | |
#define ANSI_COLOR_GREEN "\x1b[32m" | |
#define ANSI_COLOR_YELLOW "\x1b[33m" | |
#define ANSI_COLOR_BLUE "\x1b[34m" | |
#define ANSI_COLOR_MAGENTA "\x1b[35m" | |
#define ANSI_COLOR_CYAN "\x1b[36m" | |
#define ANSI_COLOR_RESET "\x1b[0m" | |
struct fb_fix_screeninfo finfo; | |
struct fb_var_screeninfo vinfo; | |
uint32_t pixel_color(uint8_t r, uint8_t g, uint8_t b, struct fb_var_screeninfo *vinfo) | |
{ | |
return (r << vinfo->red.offset) | (g << vinfo->green.offset) | (b << vinfo->blue.offset); | |
} | |
int main() | |
{ | |
printf(ANSI_COLOR_GREEN "Framebeffer." ANSI_COLOR_RESET "\n"); | |
int fb_fd = open("/dev/fb0", O_RDWR); | |
if(fb_fd == -1){ | |
printf("Can't open \"/dev/fb0\"\n"); | |
exit(1); | |
} | |
//get variable screen information | |
ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo); | |
vinfo.grayscale=0; | |
vinfo.bits_per_pixel=32; | |
ioctl(fb_fd, FBIOPUT_VSCREENINFO, &vinfo); | |
ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo); | |
ioctl(fb_fd, FBIOGET_VSCREENINFO, &finfo); | |
long screensize = vinfo.yres_virtual * finfo.line_length; | |
printf("Screen size: %ld\n", screensize); | |
uint8_t *fbp = mmap(NULL, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); | |
//location where we want to draw pizel | |
long x; | |
long y; | |
// The pixel we want to draw at location | |
uint32_t pixel; | |
printf("x resolution: %d\n", vinfo.xres); | |
printf("y resolution: %d\n", vinfo.yres); | |
for(x = 0; x < vinfo.xres; x++) | |
{ | |
for(y = 0; y < vinfo.yres; y++) | |
{ | |
long location = (x + vinfo.xoffset) * (vinfo.bits_per_pixel / 8) + (y + vinfo.yoffset) * finfo.line_length; | |
//printf("%ld\n", location); | |
uint32_t pix = pixel_color(0xFF, 0x00, 0xFF, &vinfo); | |
*((uint32_t*)(fbp + location)) = pix; //вот тут сегфол бля | |
} | |
} | |
close(fb_fd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment