Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I write bytes directly to video memory under Linux, or is there a better way to get data onto the screen?

I'm teaching my son programming "the right/hard way", so we're starting with C, like real men :)

Printing text to the console is fun, but I still remember the exhilaration of switching my old i386 to the 320x200x256 mode and drawing a few colored rectangles... back in the day it was as easy as invoking int 10h and then you just write bytes to [A000:0000] to draw pixels on the screen.

With modern Linux, however, such low-level access to the hardware seems to be more complicated (for obvious reasons). I've briefly looked at mmap-ing /dev/fd0 as described here - turns out there's no /dev/fb0 device on my Ubuntu 13.04. I also looked at using svgalib - however, their example code displays nothing on my monitor.

So the question is: are there easy ways to obtain direct access to video memory in modern Linux which do not require much system configuration and boilerplate code? It does not have to be a fullscreen access - opening an X window and drawing pixels there would be fine too, as long as it's done via writing data directly to memory.

like image 724
Sergey Avatar asked Jul 15 '13 00:07

Sergey


1 Answers

Instead of accessing the screen memory directly (which is fraught with more pitfalls than one can believe), you should consider using Simple DirectMedia Layer for your graphics (and much more!) and letting the OS handle drawing it to the screen.

like image 179
Ignacio Vazquez-Abrams Avatar answered Nov 08 '22 03:11

Ignacio Vazquez-Abrams