Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Tech Nibbles: C Graphics Programming in Ubuntu

http://shekhar-technibbles.blogspot.com/2010/08/c-graph...

Share

Report Abuse

Next Blog

Create Blog

Sign In

Tech Nibbles
A Blog created with a purpose to meet the requirements of the pacing technical needs.
Home About Me
ABOUT ME

WEDNESDAY, AUGUST 25, 2010

SHEKHAR

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 guile1.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.

I'm pursuing B.Tech. in Computer Science & Engineering from School Of Engineering,CUSAT. I will be posting some technical stuffs on this blog. Hope you would love the things posted. View my complete profile
BLOG ARCHIVE

2010 (2) August (1) C Graphics Programming in Ubuntu February (1)

SHARE IT
Share this on Facebook Tweet this
View stats
Get more gadgets for your site

TOTAL PAGEVIEWS

1,794

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 some furthur issues related to this post, post it here.
Posted by SHEKHAR at 9:30 AM
0

43 comments:
anu said... some error occurring while installing .....so I am unable to use it. kindly guide me.... October 6, 2010 2:17 PM

FOLLOWERS Join this site


with Google Friend Connect

Members (5)

SHEKHAR said... Pls mention the error details u r getting....


Already a member? Sign in

1 of 8

Thursday 15 September 2011 09:05 PM

Tech Nibbles: C Graphics Programming in Ubuntu


October 8, 2010 12:53 PM

http://shekhar-technibbles.blogspot.com/2010/08/c-graph...

Sanjay said... bresen.o: ../../src/xcb_io.c:249: process_responses: Assertion `(((long) (dpy->last_request_read) - (long) (dpy->request)) <= 0)' failed. Aborted I get this message and the graph closes. Please help! email:whisperingwind.sanjay@gmail.com October 10, 2010 11:56 AM

Sanjay said... In turbo c++, i use : int gdriver=detect,gmode,errorcode; initgraph(&gdriver,&gmode,"C:\\tcplus\\BGI"); so whats the equivalent code here?? October 10, 2010 12:02 PM

SHEKHAR said... libgraph is so much equivalent to Turbo C++. It had been introduced keeping in view the users comfortable with Turbo C++. Simply use: int gd=DETECT,gm; initgraph(&gd,&gm,""); U don't need to specify any path in initgraph. Even in Turbo C++,u can avoid writing the path in initgraph() by copying the file EGAVGA.bgi from BGI folder and pasting it in Bin folder. October 12, 2010 4:40 AM

SHEKHAR said... The message u gave here flashes on the terminal due to initialization of the graph while u r receiving inputs. Just initialize the graph after u have entered the inputs. Just consider ur example.Perhaps u were drawing line by bresenham algorithm.....Take the inputs from the user (in this case the end points of the line) before initializing the graph(or calling initgraph()). If still anything happens....make me know.... One more thing...use the kbhit() function and closegraph() at the end for closing the graph. October 12, 2010 4:48 AM

Sanjay said... thanks a lot! I got it working... October 23, 2010 6:06 AM

manish nagar said... thanks buddy its wotking October 26, 2010 1:24 AM

chetan@cse10 said... hi shekhar,after entering the values a flash screen pops up and closes immediately ,so how can i be able to see the out put????no error mesgs are being displayed.

one more thing,,when i used conio.h its showing me error ---->no such file or directory<----

2 of 8

Thursday 15 September 2011 09:05 PM

Tech Nibbles: C Graphics Programming in Ubuntu


plzz help me get out of this ,,,chetan November 3, 2010 1:14 AM

http://shekhar-technibbles.blogspot.com/2010/08/c-graph...

SHEKHAR said... conio.h is not available under libgraph...so just don't use it.... use kbhit() or getch() function to see the output screen and then use closegraph() to close the graph. write the following at the end of the program before return: while(!kbhit()); closegraph(); This will do...if still u r unable to see the output, let me know.. Here a sample program for u. Try it.. #include #include int main() { int gd=DETECT,gm; initgraph(&gd,&gm,""); circle(100,100,50); while(!kbhit()); closegraph(); return 0; } November 3, 2010 4:21 AM

SHEKHAR said... first include is stdio.h and the 2nd one is graphics.h... November 3, 2010 4:23 AM

chetan@cse10 said... thank u shekar its working fine. i didn't expect such a quick repl from u,really thank u man. November 4, 2010 11:08 AM

chetan@cse10 said... why should we use gcc filename.c -lgraph for compiling isn't cc filename.c enough???(of course i did not get output using that command) just clarify me, thanks in advance November 4, 2010 11:11 AM

SHEKHAR said... gcc filename.c -lgraph is used to link the program with libgraph which contains graphics.h . cc instead of gcc will do but u need to append -lgraph at the end. If u want a short command u can use grc filename For viewing the manual entry on libgraph, use the command " man libgraph ". November 4, 2010 12:33 PM

Rudrakshya said... i get the following errors while installing >>>>>Makefile:934: warning: overriding commands for target `libgraph.pc' Makefile:409: warning: ignoring old commands for target `libgraph.pc' make install-recursive make[1]: Entering directory `/home/rudrakshya/libgraph-1.0.2' Makefile:934: warning: overriding commands for target `libgraph.pc' Makefile:409: warning: ignoring old commands for target `libgraph.pc' Making install in doc make[2]: Entering directory `/home/rudrakshya/libgraph-1.0.2/doc' Making install in man

3 of 8

Thursday 15 September 2011 09:05 PM

Tech Nibbles: C Graphics Programming in Ubuntu


make[3]: Entering directory `/home/rudrakshya/libgraph-1.0.2/doc/man' make[4]: Entering directory `/home/rudrakshya/libgraph-1.0.2/doc/man' make[4]: Nothing to be done for `install-exec-am'. test -z "/usr/local/man/man1" || mkdir -p -- . "/usr/local/man/man1" mkdir: cannot create directory `/usr/local/man': File exists make[4]: *** [install-man1] Error 1 make[4]: Leaving directory `/home/rudrakshya/libgraph-1.0.2/doc/man' make[3]: *** [install-am] Error 2 make[3]: Leaving directory `/home/rudrakshya/libgraph-1.0.2/doc/man' make[2]: *** [install-recursive] Error 1 make[2]: Leaving directory `/home/rudrakshya/libgraph-1.0.2/doc' make[1]: *** [install-recursive] Error 1 make[1]: Leaving directory `/home/rudrakshya/libgraph-1.0.2' make: *** [install] Error 2 -pls help November 25, 2010 11:32 AM

http://shekhar-technibbles.blogspot.com/2010/08/c-graph...

SHEKHAR said... Make sure you have you have installed build-essential and run the configuration command again. November 28, 2010 12:19 AM

lakshmi prashob said... hi shekhar..i followed the steps and its working...thanks a lot!!! it ws xtremely helpful!!! December 17, 2010 1:46 AM

jose said... SDl window is small sized. How to get 640*480 graphics mode January 25, 2011 12:25 AM

SHEKHAR said... For 640*480 graphics mode, use the program statement: int gd=DETECT,gm; initgraph(&gd,&gm,""); For further details on the enumerations used for graphics driver, see the documentation of libgraph. You can use 0 to 10 instead of DEFAULT. 0 gives the default enumeration. February 2, 2011 8:36 AM

Jayendra said... When I am trying to compile file I got these errors /tmp/ccJKVMEj.o: In function `main': graph.c:(.text+0x11): undefined reference to `grprintf' collect2: ld returned 1 exit status February 9, 2011 5:48 AM

SHEKHAR said... @Jayendra... Please post your program here. There's no problem related to the installation. February 20, 2011 5:49 AM

guru said... thanks for grate blog can we change then name of a.out like if program is for circle then we can call circle.out somthing February 21, 2011 10:33 AM

4 of 8

Thursday 15 September 2011 09:05 PM

Tech Nibbles: C Graphics Programming in Ubuntu

http://shekhar-technibbles.blogspot.com/2010/08/c-graph...

SHEKHAR said... @GURU ... For that, you need to compile the program using the command: gcc filename.c -lgraph -o filename And run it using "./filename". Quotes are not included in the command. Consdering your example, the command for compilation would be "gcc circle.c -lgraph -o circle" and it can be executed using "./circle". One more thing, the executable file can be generated with a name different from the source file using the command: gcc filename.c -lgraph -o newfilename and the program can be executed using the command: ./newfilename One point to be noted in this case is that the .obj filename will be the same as the source file name. February 21, 2011 11:15 AM

aryan said... /usr/bin/ld: cannot find -lgrpah collect2: ld returned 1 exit status i am encountering this error while compiling March 9, 2011 8:17 PM

SHEKHAR said... @aryan It's "-lgraph" not "-lgrpah" March 10, 2011 3:10 AM

situkangsayur said... I still get an error when running the program: .. / .. / src / xcb_io.c: 249: process_responses: assertion `(((long) (dpy-> last_request_read) - (long) (dpy-> request)) <= 0) 'failed. I've kept the initialization after the input process and use getch () and closegraphic (); but still error when running .. i am using ubuntu 10.10 March 16, 2011 4:05 PM

shyam said... Good Job Shekhar !!! March 21, 2011 10:35 AM

SHEKHAR said... @Situkangsayur.. I have tried this on Ubuntu 10.10 and it works fine. Try compiling it again. If the error persists , mail me the program so that i can have a look at it. March 21, 2011 12:11 PM

fractalistic said... used your sample code: #include #include int main()

5 of 8

Thursday 15 September 2011 09:05 PM

Tech Nibbles: C Graphics Programming in Ubuntu

http://shekhar-technibbles.blogspot.com/2010/08/c-graph...

{ int gd=DETECT,gm; initgraph(&gd,&gm,""); circle(100,100,50); while(!getch()); closegraph(); return 0; } error: /tmp/ccUpRxaW.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status thanks for the solution April 11, 2011 11:27 PM

Sagar Rakshe said... Thanks a lot!! I was searching for it like hell. Thanks once again!!! June 21, 2011 10:27 PM

SHEKHAR said... Glad I could help. June 21, 2011 11:09 PM

Sagar Rakshe said... How to fill the rectangle with a color? and how to make delay's in gcc for graphics programs? June 22, 2011 9:50 AM

Sagar Rakshe said... how to draw rectangles of different line-widths? June 22, 2011 9:47 PM

SHEKHAR said... Refer the documentation provided for graphics programming on the internet or some nice books. You will find everything there. As for filling a polygon flood filling method(recursive or non-recursive one) will do or you can make use of the others methods. C provides a built-in function for filling polygons (refer the documentation). For making delay in gcc for graphics programs, make use of the delay() function. You can use any integral parameter for the delay function. Don't forget to include the necessary header files. If still you have some problems send me your email id, i will mail you the programs for the same. July 3, 2011 9:50 AM

Sagar Rakshe said... gcc doesn't include the DOS.H file which is neccessary for the DELAY function. What to do now? July 9, 2011 1:15 AM

Rats said... thanks a million sir , it worked for me too July 10, 2011 9:49 AM

6 of 8

Thursday 15 September 2011 09:05 PM

Tech Nibbles: C Graphics Programming in Ubuntu

http://shekhar-technibbles.blogspot.com/2010/08/c-graph...

Nisha said... this is my code #include void main() { int gd=DETECT ,gm; initgraph(&gd ,&gm,"E:/TC/BGI"); circle(150,150,150); getch(); closegraph(); return 0; } when i compile this i get errors ..pls help me.. Desktop$ gcc CIR.C -lgraph CIR.C:2:18: error: conio.h: No such file or directory CIR.C:3: error: ::main must return int CIR.C: In function int main(): CIR.C:6: warning: deprecated conversion from string constant to char* pls help me July 13, 2011 9:57 AM

SHEKHAR said... @Nisha CIRC.C:2:18:error: conio.h: No such file or directory :- conio.h is not available in gcc. So just include it in your source file. CIR.C:3: error: ::main must return int :- Instead of void main() , make use of int main() and make sure you put the statement "return 0" in the end. initgraph(&gd ,&gm,"E:/TC/BGI"); :- Change the path in the statement. It should be null . Make use of initgraph(&gd,&gm,""). The path you have mentioned in the program is used in case of the Turbo C compiler. Hope it helps. July 15, 2011 9:51 PM

rajesh said...

July 21, 2011 1:00 PM

shyam said... i get the following error.

/tmp/cc0y4aXz.o:POLYGON.CPP:(.text+0x1ad): more undefined references to `line' follow /tmp/cc0y4aXz.o: In function `main': POLYGON.CPP:(.text+0x28a): undefined reference to `grgetch' collect2: ld returned 1 exit status July 21, 2011 1:19 PM

SHEKHAR said... @shyam.. Post your program here. Can tell only after I see the program.

7 of 8

Thursday 15 September 2011 09:05 PM

Tech Nibbles: C Graphics Programming in Ubuntu


July 21, 2011 1:53 PM

http://shekhar-technibbles.blogspot.com/2010/08/c-graph...

soham20491 said... i keep getting this error in the terminal while the graphic window is open, and it ultimately aborts the program. a.out: ../../src/xcb_io.c:249: process_responses: Assertion `(((long) (dpy->last_request_read) - (long) (dpy->request)) <= 0)' failed. i have cleared the input output buffer prior to initialising the graph using getchar(). i would really appreciate it if you could tell me how this can be solved. July 28, 2011 1:06 PM

SHEKHAR said... @Soham - Initialize the graph after u have received the inputs. July 29, 2011 3:16 PM

Post a Comment

Comment as:

Select prole... Preview

Post Comment

Home
Subscribe to: Post Comments (Atom)

Older Post

Shekhar. Picture Window template. Powered by Blogger.

8 of 8

Thursday 15 September 2011 09:05 PM

You might also like