Link to home
Start Free TrialLog in
Avatar of dhyanesh
dhyanesh

asked on

Plot a pixel in Linux

I want to know how to access various graphics modes and plot a pixel in C under Linux platform.

I do not want to use any library other than the standard libraries provided by gcc. This is not part of any assignment or project. I just want to learn how to do it. I have tried reading the source code of standard libraries but it has not been helpful. Can someone guide me here ?

I am also posting a link to this question in the Linux programming section.

Thanks for your help.

Dhyanesh
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

You need to learn about how to switch the display mode, and then use the framebuffer directly. I would suggest that you read code to learn how to do that. The Linux framebuffer driver should have all this information. You can find it in your Linux source tree in the ./drivers/video directory. The standard libraries don't support this, but the fb console does.
Avatar of dhyanesh
dhyanesh

ASKER

Hi

Thanks for your comment khkremer.

When I mentioned I tried reading source code of standard libraries I actually meant graphic libraries like SDL which are available for graphics in Linux. I would like a bit of explanation of how the code works. I will read the code of the Linux framebuffer driver but if someone can explain it, it would be better.

Dhyanesh

Sorry about that, I thought that you did read things like the "standard library that comes with every C compiler - as defined by the C standard". I have to admit that I never even tried to create a pixel "the hard way". However, I did this back in the DOS days

Take a look at this page, it shows how to paint pixels using the framebuffer device, they even have a sample program near the end of the page that does just that.
Hi

I do want to know how to create a pixel the hard way. I know how to do it in DOS. Using int 10h interrupt and with framebuffer starting at 0xA0000000.

You have not given the link to the page you are mentioning.

Dhyanesh
ASKER CERTIFIED SOLUTION
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi

I am checking out the links given by  khkremer. Please give me some time to go through them.

I will also try out what you have posted, Kent. I have RedHat 7.1 and X Windows system so most probably I will be having XLIB

Dhyanesh
If you want to go the X11 route, the three lines given by Kdo will not give you a working program. There is quite a bit of code that's required to create even the most simple X11 program.
Hi

If possible please do post the code for X11 also. However as I just brushed through the third link you sent i.e. the PDF document I found that the X11 route is indirect involving quite a few steps involving network layer, decoder, X-server etc.

I will go through the method you have posted first. I hope you do not mind if I take a bit time to respond again as I am a bit busy now. Also I will take some time before closing this question.


Dhyanesh
Look at this link: http://www-h.eng.cam.ac.uk/help/tpl/graphics/Summary.html_old

Search for the string "A SAMPLE X11 PROGRAM WRITTEN IN C" in this document (it's about half way down). It shows a sample program (written in C - just as the title says :-) It draws a line and displays a string. You should be able to add the three lines from above.

Hi dhyanesh,

khkremer is correct that the three line snippet that I gave isn't sufficient to give you a working program.  (I also seem to have trouble spelling 'XCreateImage', but that's another matter. :) )

I've got an entire X11 "console" that I can post or send to you but it's fairly long.  The link provided above gives a much shorter program.  (I like it.)  Plugging XPutPixel() into it shouldn't be tough.


Kent
Thanks for your posts I will reply in detail after two three days. Hope that is fine

Dhyanesh
Sorry for the delay but I have a problem. I have study leave at present and do not have access to a Linux Box. I will be able to try out your suggestions by start of January.

Do not worry I will not abandon this question . I will definitely give points to one person or the other.

Dhyanesh
hi,
 try looking at the sources of svgalib.
http://www.svgalib.org/
As this question is 1000 points. I split it Kdo - 250 and  khkremer  - 750

khkremer get your remaining 500 points here

https://www.experts-exchange.com/questions/20813999/1000-pts-Answer-this-question.html

Dhyanesh