Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display pixel on screen in C

Tags:

c

graphics

How would I change a pixel on a display, in C?

Assume NOTHING: I am using a linux machine from console to do this. I do not want to use GUI toolkits or frameworks to draw the pixel. I do not want to draw the pixel in a window. I want to draw the pixel directly to the screen.

EDIT: I have a screen. I'm on a laptop running linux from console. I'd prefer a solution not using X as I'd rather learn how X works than how to use X.

If theres more information, ask, but don't assume. I'm not trying to build a GUI, and that was the main purpose of blocking assumptions as I don't want people to assume I'm doing things the long way when in reality I'm just tinkering.

EDIT 2: You may use any X11 related libraries provided that you can explain how they work.

like image 776
DavidJFelix Avatar asked Nov 11 '10 18:11

DavidJFelix


3 Answers

If we really assume nothing, can we even assume that X is running? For that matter, can we even assume that there is a video card? Perhaps Linux is running headless and we're accessing it over a serial console.

If we are allowed to assume a few things, let's assume that Linux has booted with framebuffer support. (It's been a couple years since I worked with Linux framebuffers, I may get some of the details wrong.) There will be a device created, probably /dev/fb or /dev/fb0. Open that file and start writing RGB values at an offset, and the screen will change, pretty much regardless of anything: text console, graphical console, full-fledged desktop envrionment, etc. If you want to see if framebuffer support is working, do dd if=/dev/zero of=/dev/fb on the command line, and the display should go all black.

like image 191
David Yaw Avatar answered Oct 15 '22 11:10

David Yaw


C doesnt have any graphics capabilities - you'd need to use a third party library for this.

like image 13
PaulJWilliams Avatar answered Oct 15 '22 12:10

PaulJWilliams


You cannot assume a display in C. There is literally no way to do what you ask.

Edit: Okay, you have a display, but again, there's not a whole lot you can get from there. The point is that there are a TON of competing standards for graphics displays, and while some of them (VGA interfaces, for example) are standardized, a lot of the others (display driver interfaces, for example) are NOT. Much of what X (and other display device drivers, such as Windows or the like) do, is have specific interface code for how to talk to the display drivers; they abstract out the complexity of dealing with the display drivers. The windowing systems, though, have HUGE libraries of complicated and specific code for dealing with the display drivers; the fact that these things are relatively transparent is an indication of just how much work they've put into these things over time.

like image 6
Paul Sonier Avatar answered Oct 15 '22 11:10

Paul Sonier