2

I'm currently writing a program that involves graphics. After some thought I decided to write directly to the frame buffer on /dev/fb0 and the code is working great but the writing speed is slow. It takes 0.161s to write a blank screen (0.213s is the program with the fb0 writing and 0.052s is the program without writing to fb) which means 6fps without any 3d rendering. Is there a way to write faster to a file like the /dev/fb0 on C? I'm currently using fb = freopen("/dev/fb0","w",stdout); to open the file and the regular printfto write to the file, also the display is 320x240. Thanks :)

3
  • 4
    1. Turn off buffering; 2. Don't use printf - write into a memory buffer and blit it using fwrite. 3. Ensure you are using optimizations (-O2 or -O3). In any case, you should show your actual code, not just try to describe what you're doing. Maybe you're doing something insane like using printfto write one character at a time.
    – paddy
    Commented Sep 15, 2016 at 23:13
  • Depending on your hardware, you could replace the generic framebuffer driver with fbvesa - That is way faster.
    – tofro
    Commented Sep 16, 2016 at 10:14
  • @paddy after using fwrite instead of printing one character at a time with printf my program went from 0.213s total to 0.034s. Thanks a lot, do you want to post it as an answer so I can accept it as the answer?
    – C32
    Commented Sep 17, 2016 at 16:41

1 Answer 1

2

You can map the framebuffer device into memory using mmap() and blit to and from it with memcpy() or pointers. Unless you are running X windows, in which case you need to go through an API such as X11, OpenGL or SDL.

1
  • betteros.org/tut/graphics1.php#dumb is a tutorial with more details. One caveat: it just takes a guess about what buffer size is “more than enough space and assume[s] that it will always be enough.” Don’t do that with external interfaces that are meant to support every piece of graphics hardware that will ever be created.
    – Davislor
    Commented May 29, 2017 at 6:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.