Professional Documents
Culture Documents
Semester 7 at college came up with a bunch of new and interesting stuff. One of them is the
computer graphics lab, where we all got to do simple graphic programming in C.
Then there was some solution here. Basically, we've to install some packages and libraries which
enable us to compile graphics.h programs in linux. The original article is a bit old and many
packages mentioned are obsolete now. So I've written a patched up, more up-to-date version of the
same.
Hope this saves you from going back to the bitter blue screen of Turbo C ;)
Step #0
Make sure you have the basic compilers installed.
You need the build-essential package. For this, run the command:
sudo apt-get install build-essential
Step #1
First we need to install a hand full of packages. You can simply run the following command and get
it all done.
sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev libsdl1.2debian-all
libart-2.0-dev libaudiofile-dev libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev
libxext-dev x11proto-xext-dev libfreetype6 libaa1 libaa1-dev libslang2-dev libasound2 libasound2-
dev
Step #2
Now, download libgraph.
Copy the file libgraph-1.0.2.tar.gz to our home folder. Right click on the file and select Extract
here.
Step #3
Now you're ready to compile your C program!
You have to type in the line #include<graphics.h> , just like you'd do in Windows.
Finally, while compiling the C file, don't forget to add a -lgraph parameter. The code will be
something like this:
gcc heart.c -o heart -lgraph
./heart
Bugs:
Although this implementation helps us to run all graphics.h functions, some predefined constants
like SOLID_FILL may not be supported. Anyways, we can use integers instead of such names. This
fixes the problem without much effort.
The graphics window can occasionally crash on focus. Rather than a bug in the graphics.h
implementation, this is a common bug in gnu/linux graphics which apparently affects many other
applications.