Professional Documents
Culture Documents
HowtoInstallDevC++andtheGLUTLibraries
forCompilingOpenGLProgramswithANSIC
(versionofJuly16,2009)
ThesenotesexplainhowtocompileprogramswritteninANSICwithOpenGLandGLUTusingtheDevC++compiler.
BloodshedDevC++isafreeC++compileranddevelopmentenvironmentforWindowsoperatingsystems.LikemostC++
compilers,italsocanbeusedtocompileANSIC.ByinstallingtheGLUTheaderandlibraryfiles,itcanbeusedtowrite
programsthatuseOpenGL.ThisisneededtorunprogramsforEdwardAngel'stextbook,InteractiveComputerGraphics
5theditionandpossiblyothercomputergraphicstexts.
ThesenotesdonotexplainhowtocompileOpenGLwithC++.The6theditionofAngel'sbookusesC++whichwillnot
workwiththesenotes.
TheseinstructionshavebeentestedonasmallvarietyofWindows2000andWindowsXPsystems.Thesesystemscome
withthefilesneededforOpenGL,butnotthefilesneededforGLUT.
DevC++doesnotworkwellwithMicrosoft'sVista.Theproblem,andapossiblefix,isdiscussedhere:
http://aresio.blogspot.com/2007/06/vistaanddevcpp.htmlbutIhavenottestedthisinformation.
I.DownloadDevC++fromhttp://www.bloodshed.net/dev/devcpp.htmlandinstallit.
Details:
GetDevC++5.0beta9.2(4.9.9.2)(9.0MB)withMingw/GCC3.4.2Althoughthisisa"beta"version,itworks
perfectlyfine.ClickonSourceForgetogotoalistofdownloadsitesandpickone.Thefilewillbesomethinglike
devcpp4.9.9.2_setup.exe.SavethisfileinaplacelikeC:\Temp.
Whenthedownloadiscomplete,clickonthe"open"buttontostarttheinstallationprocess.(OrgotoC:\Temp
andDoubleclickondevcpp4.9.9.2_setup.exe).Youwillseeafewscreensthataskyoutopickalanguage
(English)andtoagreetothelicenseterms.Choosea"typical"installation.
http://chortle.ccsu.edu/bloodshed/howtogl.html 1/13
8/6/2015 HowtoinstallDevC++andGLUT
Acceptthesuggesteddestinationfortheinstallation:
Manysubdirectoriesandfilesareextractedtothedestintion:
Answer"yes"whenitasksifyouwishtoinstallDevcppforallusers.Note:iftheinstallationfails,reinstalland
try"no"forthis.
Ascreensaystheinstallationiscomplete:
http://chortle.ccsu.edu/bloodshed/howtogl.html 2/13
8/6/2015 HowtoinstallDevC++andGLUT
Keepthecheckmarkinthebox.Clickon"Finish".Afirsttimeconfigurationscreenappears:
Pick"English"and"NewLook".Inthenextseveralscreens,hit"Yes"foritssuggestions.
Eventuallyyouaredone.Click"OK".
http://chortle.ccsu.edu/bloodshed/howtogl.html 3/13
8/6/2015 HowtoinstallDevC++andGLUT
II.DEVC++startsup.TryouttheinstallationwithasimpleCprogram.
Details:
Theprogramstartsupautomatically.
ClickFile/New/Project.Pickanamefortheproject(suchas"myProject").Click"CProject".Clickon"Empty
Project".Click"OK".
In"CreateNewProject",click"save"(lateronyouwillprobablywanttocreateseparatesubdirectoriesforyour
variousprojects.).
http://chortle.ccsu.edu/bloodshed/howtogl.html 4/13
8/6/2015 HowtoinstallDevC++andGLUT
Click"File/New/SourceFile"andin"Addsourcefiletocurrentproject"click"Yes".Younowgetascreenwhere
youcaneditthesourcefile.
TypeinasimpleCprogram,asbelow.Nowclick"File/SaveAs"andsavethefileas"hello.c"(orothername.)
Important:besurethatthefileextensionis.c.Withanyotherextension(suchasthesuggested.cpp)youwill
haveproblemscompiling.
Nowclick"Execute/CompileandRun"
Theprogramwill(hopefully)compile,run,andwriteitsoutputtoaDOSwindow.Ifyouhavethesystem("pause")
statementinyourprogram,theoutputwillstayinthewindowuntilyouhitakey.Anotherwaytoruntheprogram
(afterithasbeencompiled)istostartaDOSwindowoutsideoftheDevCppsystem,thennavigatetothe
subdirectorythatholdsyourproject,andtypehello.exe.
Atthispoint,thecompileranddevelopmentenvironmenthasbeeninstalled.YoushouldfindDevC++listed
under"Programs"onthe"Start"menuandwillnowbeabletowrite,compile,andrunC(andC++)programs.
Youwillhaveincludefiles,libraries,anddll'sforOpenGL(andallotherstandardpackages)butnotGLUT.
GLUTmanagesthewindowsandotheruserinterfacecomponentsneededforOpenGLprogramming,and
needstobeseparatelyinstalled.
http://chortle.ccsu.edu/bloodshed/howtogl.html 5/13
8/6/2015 HowtoinstallDevC++andGLUT
IfyoudonotneedGLUT,youcanquitnow.
III.DownloadandinstallGLUT
TorunOpenGLwithGLUT(whichiswhattheprogramsinAngel'sbookuse),youneedtogetthreefilesandplaceeach
fileinitsproperdirectory.Allthefilesyouneed(andmore)arecontainedinonezipfile.
Details:
DownloadGLUTfilesfromhttp://chortle.ccsu.edu/Bloodshed/glutming.zipDownloadthefileglutming.zipSave
thezipfileinsomeconvenientlocation(perhapsC:\temp).
Doubleclickonglutming.zip(orotherwiseunzipit).Youwillseethefilesthatareintheziparchive.(Yourun
zippingprogramwillprobablybediferentthantheoneshownhere,butshouldworkaboutthesame.)
Clickon"Extract"toextractallthesubdirectoriesandfiles.Picksomeconvenientdirectorytoextractthemto
(perhapsC:\temp\glutming).Youonlyneedthreefiles,butextractallofthemanyway.
http://chortle.ccsu.edu/bloodshed/howtogl.html 6/13
8/6/2015 HowtoinstallDevC++andGLUT
Onlythreeofthefilesinthevarioussubdirectoriesareneeded.Eachofthethreefilesshouldbeputina
subdirectorywithotherfilesofitstype.UseExplorertomovethefilestowheretheyareneeded.
Note:IfyouonlyseesomeofthesefileslistedinExplorer,clickon"View/Options/View"andthenselectthe
radiobutton"ShowallFiles".
glut.hcopythisfiletoC:\DevCpp\include\GL
Copyfromyour"unzipped"subdirectories(wherevertheyare):
Tohere:
libglut32.acopythisfilefromyourunzippeddirectoriestoC:\DevCpp\lib
Theremaybeanewerversionofthisfilethere,already.Replacethatversionwiththeoneyou
unzipped(ifyoukeepthenewerversionyourprogramswillnotlinkcorrectly.)
Copyfromyour"unzipped"subdirectories:
http://chortle.ccsu.edu/bloodshed/howtogl.html 7/13
8/6/2015 HowtoinstallDevC++andGLUT
Tohere:
glut32.dllmovethisfiletoC:\WINNT\System32,orsimilarlocation.
Thelocationforthisfiledependsonyouroperatingsystem.Thedirectorywhereitgoesisthe
directorythatholdsthedynamicloadlibraries(*.dll).Aneasywaytofindwhereitshouldgoisto
lookforglu32.dll(use"Search"fromthestartmenu).
Thedirectorytouseshouldalsohavethefilesglu32.dllandopengl32.dll.Theseshouldhavecome
withyouroperatingsystem.
IV.TestDevcppwithGLUT
TheessentialstepincompilingandrunningaCprogramthatcontainsOpenGLandGLUTfunctionsistotellthelinker
wherethelibrariesare.ThisisdonebyclickingProject/ProjectOptions/Parameters/AddLibraryorOptionsandthen
navigatingtothelibrariesyouneedtoinclude:libopengl32.a,libglu32.a,andlibglut32.a.Thelibrariesshouldbeaddedin
thatorder.
Details:
a.Createasubdirectoryforaproject.Dothisfirst,beforeyoustartDevCpp.Createanewsubdirectorywith
"Explorer"byclicking"File/New/Folder".
http://chortle.ccsu.edu/bloodshed/howtogl.html 8/13
8/6/2015 HowtoinstallDevC++andGLUT
Forexample,createafolderC:\GLproject.
b.StartDevcpp:
c.StartanewprojectbyclickingFile/New/Project.Inthepanelthatpopsup,nametheprojectsomethinglike
"rectangle",clickon"emptyproject"and"C":ClickOK.
Note:ForcompilingwithOpenGLyoumustcreateaproject.Youneedtohaveaproject(notjustasingleCfile)
inordertolinkintheOpenGLlibraries.
d.Inthenextpanel,navigatetoyourfolderC:\GLproject,andclick"Save".
http://chortle.ccsu.edu/bloodshed/howtogl.html 9/13
8/6/2015 HowtoinstallDevC++andGLUT
e.InDevC++,click"File/New/SourceFile"andtheninthenextpanel"AddtoProject"click"yes".Click
"File/SaveAs"andthengivethefileaname.Navigatetoyourprojectsubdirectorytosavethefileinit.Name
thefilesomethinglike"rectangle.c"
Besurethatthefilenamesendswith".c"anythingelsewillcausebigproblems.
f.Clickanddragyourmouseoverthefollowingprogramsothatitishighlighted,thenclick"Edit/Copy"fromthe
browser'smenubar.
#include<GL/glut.h>
constintA=500;/*lengthofasideofthemonitorwindow*/
constfloatB=500;/*lengthofasideoftheclippingrectangle*/
constfloatC=200;/*lengthofasideofthesquaretheprogramdraws*/
voidmyinit(void)
{
glClearColor(0.7,0.7,0.7,0.0);/*graybackground*/
glMatrixMode(GL_PROJECTION);/*InWorldcoordinates:*/
glLoadIdentity();/*positionthe"clippingrectangle"*/
gluOrtho2D(B/2,B/2,B/2,B/2);/*atB/2,itsrightedgeat+B/2,itsbottom*/
glMatrixMode(GL_MODELVIEW);/*edgeatB/2anditstopedgeat+B/2*/
}
voiddisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);/*clearthewindow*/
glMatrixMode(GL_MODELVIEW);/*Thefollowingcoordinatesareexpressed*/
glLoadIdentity();/*intermsofWorldcoordinates*/
glBegin(GL_POLYGON);/*drawafilledpolygon*/
glColor3f(1.0,0.3,0.2);/*drawinlightred*/
glVertex2f(C/2,C/2);/*(x,y)*/
glVertex2f(C/2,C/2);/*(x,y)*/
glVertex2f(C/2,C/2);/*(x,y)*/
glVertex2f(C/2,C/2);/*(x,y)*/
glEnd();
http://chortle.ccsu.edu/bloodshed/howtogl.html 10/13
8/6/2015 HowtoinstallDevC++andGLUT
glFlush();/*sendallcommands*/
}
voidmain(intargc,char**argv)
{
glutInit(&argc,argv);
glutInitWindowSize(A,A);/*AxApixelscreenwindow*/
glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
glutCreateWindow("MyRectangle");/*windowtitle*/
glutDisplayFunc(display);/*tellOpenGLmainloopwhat*/
myinit();/*setattributes*/
glutMainLoop();/*passcontroltothemainloop*/
}
g.NowclickintheeditingwindowofDevcppandthenclick"Edit/Paste"initsmenubar.Theprogramwill
appearintheeditingwindow.
h.Click"File/Save".ThefileinyourprojectdirectoryshouldnowcontainanOpenGLprogram.
i.TellDevcppwhatlibrariesneedtobelinked.Click"Project/ProjectOptions".
j.Nowclick"Parameters".Clickthe"AddLibraryorObject"buttonandnavigatetothelibrariesthatshouldbe
added,foundunderC:\Devcpp\lib
../lib/libopengl32.a
http://chortle.ccsu.edu/bloodshed/howtogl.html 11/13
8/6/2015 HowtoinstallDevC++andGLUT
../lib/libglu32.a
../lib/libglut32.a
Addtheminthatorder(only).NoticethattheslasheswillappearinUnixstyle"/"ratherthanDOSstyle"\".
Whenyouaredoneaddingthethreelibaries,youshouldsee:
Theexactpatternof"../../.."youseedependsonhowdeepinthedirectorystructureyoursourcefilelies.
Click"OK".
k.Click"Execute/CompileandRun".Theprogramshouldcompile,link,andrun:
Ifthingsdon'twork(verycommon)clickonthe"CompileLog"tabforsomeconfusingerrormessages.Ifyou
http://chortle.ccsu.edu/bloodshed/howtogl.html 12/13
8/6/2015 HowtoinstallDevC++andGLUT
seesomethinglikethefollowing,itmeansthatyoumadeamistakeinaddingthelibrariestotheproject:
Trytofixthelistoflibraries,orperhapsstartoverfromscratch.
Younowarefinished,orhavegivenup.
http://chortle.ccsu.edu/bloodshed/howtogl.html 13/13