Sunday, November 7, 2010

C Graphics Programming in UBUNTU


The solution for doing graphics programming in ubuntu is:
libgraph - library providing the TurboC graphics API ( graphics.h) in Linux using SDL.
For using this , you need to follow some simple steps as mentioned below:
First of all, you need to install the dependencies so that all the required compiler tools gets installed.For that you need to run the given command on the terminal:
sudo apt-get install build-essential
Next you need to install some packages. They are: libsdl-image1.2,libsdl-image1.2-dev,guile-1.8 and guile-1.8-dev. For that run the given command at the terminal:
sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev
Now, download and install libgraph-1.0.2.tar.gz from the link :
http://mirror.veriportal.com/savannah/libgraph/
Download this file in any folder and extract it in the home folder or on the desktop wherever you want.
Open the terminal and navigate to the folder where you have extracted libgraph-1.0.2 with the help of cd command. Install this using the commands given below:
./configure (Return)
sudo make (Return)
sudo make install (Return)
After this you can start your C graphics programming in linux. Now try writing a simple C graphics program by including the header file "graphics.h". You can do the programs as you in TURBO C.
For writing the programs you can use the "gedit" tool in ubuntu. For compiling the programs, navigate to the source program folder and use the following command:
gcc filename.c -lgraph
For executing the program, use the command ./a.out
The error “./a.out: error while loading shared libraries: libgraph.so.1: cannot open shared object file: No such file or directory” can be solved by
sudo cp /usr/local/lib/libgraph.* /usr/lib
If you still have any further doubts, then plz post here...hope i'll answer

2 comments:

Unknown said...

Hi, I actually installed libgraph and I found that setfillstyle() function, a BGI function is not working and linker error is being shown during compilation. Any workarounds known?

Sachidanand said...

@neel libgraph doesn't support the setfillstyle() function. For advanced graphics programming, make use of openGL.