graphics programming in c under gnu linux (ubuntu distribution)
DESCRIPTION
How to do Graphics Programming in C under GNU Linux (Ubuntu distribution)TRANSCRIPT
Tushar B KuteNashik Linux User Group
http://snashlug.org
Graphics Programming in C under GNU / Linux (Ubuntu Distribution)
Graphics Programming in C
● OpenGL● Gtk+● SDL Libgraph
OpenGL
● 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+
● 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 Qt.
● 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 in 1997.
SDL
● 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.
libgraph
● 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.
SDL-Libgraph
● It works efficiently with open source C compiler gcc.
● 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]
Step-1
● 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.
Actual Demo
Step-2
● 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● libsdl-image1.2-dev● guile-1.8● guile-1.8-dev● libart-2.0-dev● libaudiofile-dev● libesd0-dev● libdirectfb-dev
● libdirectfb-extra
● libxext-dev
● x11proto-xext-dev
● libfreetype6
● libaa1
● libaa1-dev
● libslang2-dev
● libasound2
● libasound2-dev
Single stroke command
● sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev 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
Actual Demo
Step-3
● Now, download libgraph from: (http://download.savannah.gnu.org/releases/libgraph/libgraph-1.0.2.tar.gz)
● 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.
cd libgraph-1.0.2
./configure
sudo make
sudo make install
sudo cp /usr/local/lib/libgraph.* /usr/lib
Actual Demo
Step-4
● 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
run with:
gcc MyProg.c -lgraph
./a.out● Once all this installation process is done, you don't
need to follow this process again and again. Just compile and execute the program.
Example: MyProg.c
#include<graphics.h>
int main()
{
int gd = DETECT, gm = 0;
initgraph(&gd, &gm,""); // initialize graphics
circle(300, 300, 150); // graphics function for circle
getch(); // this is must to hold output!
closegraph();
return 0;
}
Execution of program
Output Window
You may use print screen (PrtSc) button to take output.
By default, this image get stored in /home/Pictures.
Final work
● You may use “Shotwell Photo Viewer” to crop the image output!
● Generally making background White and foreground Black create good effect in output for taking printout.
Sample Program
int gd = DETECT, gm = 0;
initgraph(&gd, &gm,"");
setbkcolor(WHITE);
setcolor(BLACK);
circle(300, 300, 150);
getch();
closegraph();
Final Output
Thank you
http://tusharkute.com
This presentation is created using LibreOffice Impress 4.0.2.2 Use open source, be safe and secure