Sunteți pe pagina 1din 3

Ubuntu Community Ask!

Developer Design Hardware Insights Juju Shop More



signup login tour help

_
AskUbuntuisaquestionandanswersite Here'showitworks:
forUbuntuusersanddevelopers.Join
themitonlytakesaminute:

Signup
Anybodycanask Anybodycan Thebestanswersarevoted
aquestion answer upandrisetothetop

HowdoIusegraphics.hinUbuntu?

IsthereanyLinuxbasedcompilerwhichsupports graphics.h library?Iwanttoimplementgraphicprograms,sopleasekindlyletmeknowif


thereisanysuchsoftware.

IfnotthenhowcanIuseit?

libraries compiler

editedFeb21'15at8:52 askedSep17'14at7:12
muru AtulSingh
85.5k 13 166 239 77 1 1 3

Whatexactlyyouneedtoknow?Thecompilersaresupposedtofindalltheheadersifyouputthecorrect..umm...
hearersinyoursourcefile.Braiam Sep17'14at13:27

@BraiamThecompilerwon'tmagicallyfindaheaderfilejustbecauseyouincludeit.Firstly,clearlythatfileneedsto
beinstalledonyousystem(typicallyheaderfilescomewith *dev packagesonLinuxdistros)thecompiler
won'tdownloaditforyou.Secondly,thatheaderfileneedstoeitherbeinsomestandardlocationwhereacompiler
willlookforit(suchas /usr/include ),orelsethatlocationhastobespecifiedwith I onthecommandline
(for gcc or g++ ).Additionallyyouusuallyneedtheruntimelibsforthelinkingstage(exceptforheaderonlylibs)...
MalteSkoruppaSep17'14at14:34

@MalteSkoruppawell,butwhatyouneedtouseit?Putitinyourheaders,no?Braiam Sep17'14at14:37

@BraiamErr...whatareyouasking?Look,theOP'squestionisjustthis:whatdoIneedtodosoastob eab leto


usethe graphic.h lib raryonUb untu?It'sperfectlyclear.Anappropiateanswerwillexplainwhatpackagesare
neededandhowtoinstallthem(astheexistinganswerdoes),andpossiblywhatparametersareneededonthe
commandlineatcompiletime.MalteSkoruppaSep17'14at14:54

@MalteSkoruppaareyoureadingthebody?Braiam Sep17'14at14:58

2Answers

ThereareseveraloptionavailabletodographicsprogrammingusingUbuntu.

UsingSDL

Ifyouwanttouse graphics.h onUbuntuplatformyouneedtocompileandinstall libgraph .Itis


theimplementationofturbocgraphicsAPIonLinuxusingSDL.

Itisnotverypowerfulandsuitableforproductionqualityapplication,butitissimpleandeasyto
useforlearningpurpose.

Youcandownloaditfromhere.

Firstinstallbuildessentialbytyping
sudoaptgetinstallbuildessential

Intallsomeadditionalpackagesbytyping
sudoaptgetinstalllibsdlimage1.2libsdlimage1.2devguile1.8\
guile1.8devlibsdl1.2debianlibart2.0devlibaudiofiledev\
libesd0devlibdirectfbdevlibdirectfbextralibfreetype6dev\
libxextdevx11protoxextdevlibfreetype6libaa1libaa1dev\
libslang2devlibasound2libasound2dev

Nowextractthedownloaded libgraph1.0.2.tar.gz file.


Gotoextractedfolderandrunfollowingcommand
./configure
make
sudomakeinstall
sudocp/usr/local/lib/libgraph.*/usr/lib

Nowyoucanuse #include<graphics.h> onubuntuplatform


usefollowinglineinyourprogram
intgd=DETECT,gm;
initgraph(&gd,&gm,NULL);

Hereisasampleprogramusing graphics.h

/*demo.c*/
#include<graphics.h>
intmain()
{
intgd=DETECT,gm,left=100,top=100,right=200,bottom=200,x=300,y=150,radius=50;
initgraph(&gd,&gm,NULL);
rectangle(left,top,right,bottom);
circle(x,y,radius);
bar(left+300,top,right+300,bottom);
line(left10,top+150,left+410,top+150);
ellipse(x,y+200,0,360,100,50);
outtextxy(left+100,top+325,"CGraphicsProgram");

delay(5000);
closegraph();
return0;
}

Tocompileituse
gccdemo.codemolgraph

Toruntype
./demo

UsingOpenGL(viaGLUT)

AlthoughOpenGLisbasicallymadefor3Dprogramming,drawing2Dshapesgivesthebasic
outlineandintroductiontoOpenGLandgivestheideaabouthowtostartdrawingobjectsin
OpenGL.

ToinstallGLUT,openterminalandtype sudoaptgetinstallfreeglut3dev .
HereisasimplegraphicsprogramusingGLUT

/*demo.c*/
#include<GL/gl.h>
#include<GL/glut.h>
#include<GL/glu.h>
voidsetup(){glClearColor(1.0f,1.0f,1.0f,1.0f);}
voiddisplay()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(0.0f,0.0f,0.0f);
glRectf(0.75f,0.75f,0.75f,0.75f);
glutSwapBuffers();
}
intmain(intargc,char*argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(800,600);
glutCreateWindow("HelloWorld");
setup();
glutDisplayFunc(display);
glutMainLoop();
return0;
}

Compileitusing gccdemo.codemolglutlGL

Runitusing ./demo

editedFeb21'15at8:51 answeredSep17'14at7:20
muru g_p
85.5k 13 166 239 9,286 1 31 47

1 IamusingSDL,butididallstuffsassaid,intalllibgraphtoo,butafterprogramrun,ithaltsandendssuddenlywith
anerror[xcb]UnknownsequencenumberwhileprocessingqueueLuzanBaralNov10'14at17:10

whichversionofUbuntuyouareusing?g_pNov11'14at1:57

iamusingubuntu14.04LuzanBaralDec14'14at10:40

@LuzanBaral,ItseemsproblemwithGTK,butyoucanstillruntheprogram.g_pJan24'15at14:52

wherecanifindthedocumentationforlibgraph?In78Aug31'16at18:30

Ifyouwanttousegraphics.hinubuntuoranyotherlinuxdistro,thenIpreferlibxbgi.Itcando
almostallthethingsthatyouexpectfromthegraphics.hforwindows.Youcandownloaditfrom
here:http://libxbgi.sourceforge.net/

OtherwiseifyouwanttodosomehighendgraphicsthenyouarethereforSDL(whichismostly
forprogrammingvideogames)andOpenGL(whichisfor3Dgraphics).Youcanalsousea
mixtureofthetwo.Oneexampleisthegamebriquolo(spellingmaybewrong).

HAPPYGRAPHICSPROGRAMMING!!

answeredJan28'15at11:19
Gprogrammer
11 1

protectedbyCommunity Feb11'16at17:17
Thankyouforyourinterestinthisquestion.Becauseithasattractedlowqualityorspamanswersthathadtoberemoved,postingananswernowrequires10reputation
onthissite(theassociationbonusdoesnotcount).

Wouldyouliketoansweroneoftheseunansweredquestions instead?

S-ar putea să vă placă și