Solved

Plot a pixel in Linux

Posted on 2003-11-28
15
750 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:dhyanesh
  • 7
  • 5
  • 2
  • +1
15 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 9842405
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.
0
 
LVL 4

Author Comment

by:dhyanesh
ID: 9844508
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

0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 9845106
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.
0
 
LVL 4

Author Comment

by:dhyanesh
ID: 9848014
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
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 250 total points
ID: 9849446
I'm sorry about that. Here is the link:

http://doc.trolltech.com/3.0/emb-framebuffer-howto.html

.. and another one:

http://l4fdyos.ciwunion.com/ARTICEL/Linux%202.2%20Framebuffer%20Device%20Programming%20Tutorial.htm

... and a Linux magazine article about the frame buffer device in general:

http://www.linux-magazine.com/issue/03/EmbeddedGraphics.pdf

Again, I'm sorry about the missing link.
0
 
LVL 45

Assisted Solution

by:Kdo
Kdo earned 250 total points
ID: 9859327
Hi dhyanesh,

DOS output to the terminal is completely different than linux output.  Linux has no equivalent to a DOS interupt that will diddle a particular pixel.

You'll have to work within whatever graphics mode you're using.  Under linux, this is almost always X (X11) an is included with most linux distributions in XLIB.

  Image = ECreateImage ();
  XInitImage (Image);
  XPutPixel (Image, X, Y, PixelCharacteristics);

Will do what you want.  But you'll be dealing with the image (window) that you create.


Kent
0
 
LVL 4

Author Comment

by:dhyanesh
ID: 9864327
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
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 9865600
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.
0
 
LVL 4

Author Comment

by:dhyanesh
ID: 9865900
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
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 9866024
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.
0
 
LVL 45

Expert Comment

by:Kdo
ID: 9866379

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
0
 
LVL 4

Author Comment

by:dhyanesh
ID: 9866458
Thanks for your posts I will reply in detail after two three days. Hope that is fine

Dhyanesh
0
 
LVL 4

Author Comment

by:dhyanesh
ID: 9940802
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
0
 
LVL 8

Expert Comment

by:manish_regmi
ID: 10171534
hi,
 try looking at the sources of svgalib.
http://www.svgalib.org/
0
 
LVL 4

Author Comment

by:dhyanesh
ID: 10333177
As this question is 1000 points. I split it Kdo - 250 and  khkremer  - 750

khkremer get your remaining 500 points here

http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_20813999.html

Dhyanesh

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now