0 оценок0% нашли этот документ полезным (0 голосов)
52 просмотров12 страниц
1. The document provides instructions for installing the Allegro graphics library and creating a basic "Hello World" program using Allegro on Windows. It describes downloading and installing CodeBlocks with MinGW, setting environment variables, downloading and compiling Allegro and DirectX sources, creating a Hello World project, and running the demo program included with Allegro.
2. The Hello World program is created and run, displaying the text "Hello World" and the user's name on the screen.
3. The document includes screenshots showing successful compilation of Allegro, addition of the Allegro library to the linker settings, and the final output of the Hello World program displaying the text on screen.
1. The document provides instructions for installing the Allegro graphics library and creating a basic "Hello World" program using Allegro on Windows. It describes downloading and installing CodeBlocks with MinGW, setting environment variables, downloading and compiling Allegro and DirectX sources, creating a Hello World project, and running the demo program included with Allegro.
2. The Hello World program is created and run, displaying the text "Hello World" and the user's name on the screen.
3. The document includes screenshots showing successful compilation of Allegro, addition of the Allegro library to the linker settings, and the final output of the Hello World program displaying the text on screen.
1. The document provides instructions for installing the Allegro graphics library and creating a basic "Hello World" program using Allegro on Windows. It describes downloading and installing CodeBlocks with MinGW, setting environment variables, downloading and compiling Allegro and DirectX sources, creating a Hello World project, and running the demo program included with Allegro.
2. The Hello World program is created and run, displaying the text "Hello World" and the user's name on the screen.
3. The document includes screenshots showing successful compilation of Allegro, addition of the Allegro library to the linker settings, and the final output of the Hello World program displaying the text on screen.
Building and using the Allegro Graphics & Gaming Librar
Table of Contents !o"nload and install #odeBloc$s "ith %inG& compiler'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''2 (et En)ironment *ariables'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''+ ,nstalling -he Allegro Librar ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''. !o"nload and install Allegro .'2'2 (ource'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''. !o"nload and install direct/ sources'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''0 #on1irm that the paths and en)ironment )ariables are correct''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''2 Build (ources and install Allegro librar'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''3 #reate pro4ect 56ello &orld7 example''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''8 #ompile9 build9 and run the 6ello&orld pro4ect'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''8 Add liballeg'a to lin$er settings'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''8 #reate a ne" 6ello &orld pro4ect "ith 1ollo"ing source'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''10 :inal (creen output''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''11 ;unning the !emo program''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''12 EEL 2880 Exercise #1 Page 2 Download and install CodeBlocks with MinGW compiler !o"nload and install #odeBloc$s "ith %inG& compiler' #lic$ on lin$9 sa)e to a "or$ing director and then run codeblocks-8.02mingw-setup.exe' ,nstall supplies both #odeBloc$s and the %inG& gcc compiler in one pac$age' Illustration 1: Class web site selection Illustration 2: Installation EEL 2880 Exercise #1 Page + ,n1ormation< -he %inG& compiler is located in #<=Program :iles=#odeBloc$s=%inG&=bin' Set Environment Variables -he 1inal part o1 the installation in)ol)es en)ironment )ariables' XP: #lic$ on start9 then control panel9 then the sstem icon' #lic$ on the ad)anced tab and then on the en)ironment )ariables button' Vista:#lic$ start9 right clic$ #omputer9 select properties' >n the le1t side o1 the ne" "indo" select ?ad)anced sstem settings?' -hen on the ne"est "indo" press En)ironment *ariables' -"o )ariables "ill need to be added< 1@ %,AG!,; set to the path )alue to B,llustration .@ C:\Progra~1\CodeBlocks\MinGW 2@ PA-6 "ill add the )alue C:\Progra~1\CodeBlocks\MinGW\bin' Aote that Path alread exists and "ill then need to be editedCmodi1ied' -he ne" path is added a1ter a semicolon' B,llustration +@' C:\Program Files\CodeBlocks\MinGW\bin is the location o1 the compiler9 but path )alues cannot ha)e spaces included so nonD8dot+ notation is used as sho"n' -his notation is used to speci1 the Program :iles director "ithout spaces' Aote< An changes to en)ironment )ariables "ill not a11ect currentl opened console "indo"s' Eou "ill need to restart the console 1or the changes to ta$e e11ect' EEL 2880 Exercise #1 Page . Illustration 3: Modify Path environment variable Illustration 4: Add MIN!I" envirnment variable EEL 2880 Exercise #1 Page 0 Installing The Allegro Library Download and install Allegro .2.2 !ource !o"nload 1ile 5all.22'Fip7 1rom class "eb site and sa)e in a director' B,llustration 0@ GnFip all.22'Fip and allo"ing it to expand to its o"n 1older (tart and 1ollo" "iFard to unpac$ into 1older' Download and install directX sources !o"nload 1ile 5dx30Hmg"'Fip7 B,llustration 0@ 1rom class "eb site and sa)e in a director ' -he &indo"s )ersion o1 allegro uses this )ersion o1 direct/ Bthe standard &indo"s "a o1 inter1acing graphics@' Allegro "onIt compile "ithout it' "#$%: As sho"n in ,llustration 39 extract the contents to &:'Program (iles'&ode)locks'*in+, o)er"riting all 1iles' Illustration #: $n%i& all422'%i& to folder Illustration (: Class web site source EEL 2880 Exercise #1 Page 2 Confirm that the paths and environment variables are correct (tart a command "indo" "ith Start->Run Illustration ): *+tractin, direct- sources to Min. directory EEL 2880 Exercise #1 Page 3 #on1irm the gcc compiler is a)ailable and "or$ing' -pe 5gcc --7 and obser)e a correct response< Build Sources and install Allegro library -hen inside the command "indo"9 c.ange director/ to t.e un0ipped allegro director/' >n m computer this is the 1ollo"ing< cd #<=!ocuments and (ettings=>"ner'herman=% !ocuments=!o"nLoads=all.22=allegroJ Ao" allegro can be compiled' Aote that compilation "ill ta$e some time' (tart b tping in the command line< FIX mingw MINGW3!M"#$ MINGW3!M"#$ ins%all (ee ,llustration 8 and ,llustration 10 belo" 1or success1ul Allegro compile and install results' Illustration /: Confirm ,cc is wor0in, EEL 2880 Exercise #1 Page 8 Illustration 1: 2uccessful Alle,ro com&ile 3end screen4 Illustration 15: 2uccessful Alle,ro install EEL 2880 Exercise #1 Page 8 Create project Hello World example &ompile1 build1 and run t.e 2ello,orld pro3ect. Change line 51 in the source and insert your name. Run example and print screen to turn in as the endpoint of the assignment. Note also that the liballeg&a library has to be specified for the Linker as shown in the illustration following the example program. Turn in a screen capture of the output screen. Add liballeg.a to linker settings NT!" #n Code$locks% a reference to the allegro library has to be placed in the $uild instructions. &o to Project->Build Options->Linker Settings% and add liballeg.a as shown below by pressing the 'dd button. EEL 2880 Exercise #1 Page 10 &reate a new 2ello ,orld pro3ect wit. 4ollowing source. 1 () * ) !xample program for the 'llegro library% by +hawn ,argrea-es. . ) / ) This is a -ery simple program showing how to get into graphics 5 ) mode and draw text onto the screen. 0 )( 1 2 3include 4allegro.h5 6 17 int main8-oid9 11 : 1* 1. int height; 1/ 15 () you should always do this at the start of 'llegro programs )( 10 if 8allegro<init89 "= 79 11 return 1; 12 16 () set up the keyboard handler )( *7 install<keyboard89; *1 ** () set a graphics mode si>ed .*7x*77 )( *. if 8set<gfx<mode8&?@<'ATB!T!CT<C#NBC!B% 0/7% /77% 7% 79 "= 79 : */ if 8set<gfx<mode8&?@<+'?!% .*7% *77% 7% 79 "= 79 : *5 set<gfx<mode8&?@<T!@T% 7% 7% 7% 79; *0 allegro<message8DAnable to set any graphic modeEnFsEnD% allegro<error9; *1 return 1; *2 G *6 G .7 .1 () set the color palette )( .* set<palette8desktop<palette9; .. ./ () clear the screen to white )( .5 clear<to<color8screen% makecol8*55% *55% *5599; .0 .1 () you donHt need to do this% but on some platforms 8eg. Cindows9 things .2 ) will be drawn more Iuickly if you always acIuire the screen before .6 ) trying to draw onto it. /7 )( /1 acIuire<screen89; /* /. height = +CR!!N<,(*; // () write some text to the screen with black letters and transparent background )( /5 textout<centre<ex8screen% font% D,ello% world"D% +CR!!N<C(*% height% makecol87%7%79% J19; /0 /1 height K= *)text<height8font9; /2 textout<centre<ex8screen% font% DLy Name"D% +CR!!N<C(*% height% makecol87%7%79% J19; /6 57 () you must always release bitmaps before calling any input functions )( 51 release<screen89; 5* 5. () wait for a keypress )( 5/ readkey89; 55 50 return 7; 51 G 52 56 !NB<?<L'#N89 07 EEL 2880 Exercise #1 Page 11 (inal !creen output Illustration 11: 6inal ou&tut screen ca&ture EEL 2880 Exercise #1 Page 12 5unning t.e Demo program Allegro also includes a demonstration game program that is automaticall compiled and built "hen the librar is built' -his game resides in the demo director B,llustration 12@ "ithin the 1older "here all22 is unFipped' -his 1older is the same 1older "here all22 "as initiall unFipped as sho"n in ,llustration 2' Gse explorer to na)igate to the demo director and clic$ on the demo icon to run the program' Good luc$ K hope ou get a high score' Illustration 12: 7ocation of Alle,ro demo &ro,ram