Graphics Programming in C under GNU Linux (Ubuntu distribution)
Graphics Programming in C under
GNU / Linux (Ubuntu Distribution)
Tushar B Kute
Nashik Linux User Group
Graphics Programming in C
OpenGL (Open Graphics Library) is a cross-language,
multi-platform application programming interface (API) for
rendering 2D and 3D computer graphics. The API is typically
used to interact with a Graphics processing unit (GPU), to
achieve hardware-accelerated rendering.
OpenGL was developed by Silicon Graphics Inc. (SGI) from 1991
and released in January 1992 and is widely used in CAD, virtual
reality, scientific visualization, information visualization, flight
simulation, and video games. OpenGL is managed by the
non-profit technology consortium Khronos Group.
GTK+ (GIMP Toolkit) is a cross-platform widget toolkit
for creating graphical user interfaces. It is licensed
under the terms of the GNU LGPL, allowing both free
and proprietary software to use it. It is one of the most
popular toolkits for the X Window System, along with
The name GTK+ originates from GTK; the plus was
added to distinguish an enhanced version. It was
originally created for the GNU Image Manipulation
Program (GIMP), a free software raster graphics editor
Simple DirectMedia Layer (SDL) is a cross-platform, free and open
source multimedia library written in C that presents a simple interface
to various platforms' graphics, sound, and input devices. It is widely
used due to its simplicity. Over 700 games, 180 applications, and 120
demos have been posted on its website.
SDL has the word "layer" in its title because it is actually a wrapper
around operating-system-specific functions. The main purpose of SDL
is to provide a common framework for accessing these functions. For
further functionality beyond this goal, many libraries have been
created to work on top of SDL.
This project is not part of the GNU Project.
libgraph is an implementation of the TurboC graphics API (graphics.h)
on GNU/Linux using SDL. The library requires SDL for primitive
graphics and SDL_image (to blit fonts). Functions for text display are
based heavily on code "borrowed" from Karl Bartel's SFont library.
The library is not very powerful or flexible. It is probably not suitable
for use in production-quality applications. I see it more as a simple,
easy-to-use 2D graphics interface - could be used for simple
prototyping, visualization or studying graphics algorithms.
It is simplified library to run graphics programs in C.
It works efficiently with open source C compiler
It is required to add the sdl-libgraph library to
current existing gcc.
Let's see how to do it in GNU/Linux Ubuntu
distribution. [Next slide]
Make sure you have the basic compiler installed.
You need the build-essential package. For this, run
the command on terminal:
sudo apt-get install build-essential
You must have internet connection for this
command to work.
You 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
Now, download libgraph from:
Then copy the file libgraph-1.0.2.tar.gz to our home folder. Right
click on the file and select Extract here.
Open a terminal and run the following commands, one by one.
sudo make install
sudo cp /usr/local/lib/libgraph.* /usr/lib
Now you are ready to compile your C program!
Write your C program using any editor and save.
Open the terminal for the specified folder and then
gcc MyProg.c -lgraph
Once all this installation process is done, you don't
need to follow this process again and again. Just
compile and execute the program.
int gd = DETECT, gm = 0;
initgraph(&gd, &gm,""); // initialize graphics
circle(300, 300, 150);
// graphics function for circle
// this is must to hold output!