Qt Code:
  1. #include <stdlib.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <fcntl.h>
  5. #include <linux/fb.h>
  6. #include <sys/mman.h>
  7. #include <sys/ioctl.h>
  8.  
  9. int main()
  10. {
  11. int fbfd = 0;
  12. struct fb_var_screeninfo vinfo;
  13. struct fb_fix_screeninfo finfo;
  14. long int screensize = 0;
  15. char *fbp = 0;
  16. int x = 0, y = 0;
  17. long int location = 0;
  18.  
  19. // Open the file for reading and writing
  20. fbfd = open("/dev/fb0", O_RDWR);
  21. if (fbfd == -1) {
  22. perror("Error: cannot open framebuffer device");
  23. exit(1);
  24. }
  25. printf("The framebuffer device was opened successfully.\n");
  26.  
  27. // Get fixed screen information
  28. if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {
  29. perror("Error reading fixed information");
  30. exit(2);
  31. }
  32.  
  33. // Get variable screen information
  34. if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
  35. perror("Error reading variable information");
  36. exit(3);
  37. }
  38.  
  39. printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
  40.  
  41. // Figure out the size of the screen in bytes
  42. screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
  43.  
  44. // Map the device to memory
  45. fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
  46. fbfd, 0);
  47. if ((int)fbp == -1)
  48. {
  49. perror("Error: failed to map framebuffer device to memory");
  50. exit(4);
  51. }
  52. printf("The framebuffer device was mapped to memory successfully.\n");
  53.  
  54. x = 100; y = 100; // Where we are going to put the pixel
  55.  
  56. // Figure out where in memory to put the pixel
  57. for (y = 100; y < 300; y++)
  58. {
  59. for (x = 100; x < 5000; x++)
  60. {
  61.  
  62. location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + (y+vinfo.yoffset) * finfo.line_length;
  63. if (vinfo.bits_per_pixel == 32)
  64. {
  65. *(fbp + location) = 100; // Some blue
  66. *(fbp + location + 1) = 15+(x-100)/2; // A little green
  67. *(fbp + location + 2) = 200-(y-100)/5; // A lot of red
  68. *(fbp + location + 3) = 0; // No transparency
  69. }
  70. else
  71. { //assume 16bpp
  72. int b = 10;
  73. int g = (x-100)/6; // A little green
  74. int r = 31-(y-100)/16; // A lot of red
  75. unsigned short int t = r<<11 | g << 5 | b;
  76. *((unsigned short int*)(fbp + location)) = t;
  77.  
  78. }
  79.  
  80. }
  81. munmap(fbp, screensize);
  82. close(fbfd);
  83. return 0;
  84. }
  85.  
  86. }
To copy to clipboard, switch view to plain text mode 


the result return message Successfull but it dont display Pixel on Desktop, can you help me