Learning SDL – A BegINNER’S GUIDE

December 15, 2011 [LEARNING SDL ? A BEGINNER'S GUIDE]

sdlsimpledirectmedialayergraphicslibrary crossplatform2dsamlantimgaportvideoeve nthandlingjoystickfileioaudiocdromtimer wxdevcppruthfigueroalivesmp3wavrawau diosamplesBoeggginvnoerrb`sisGcuriedaetitoveSmDLusicboxga meloopsetcBaupildtiinog nGafmreesewsituhrSfDaLcaendpCo+l+leventuser templateinitializesd1l1r/1e1/l1e1 aseresourcespixel sinittimersdlconylgouerrridllaigrirle@cbrtaixnyocopde.econm glpixelforma tlocksurfacesetcliprectvideoinfoloadbmpb litsurfacesetcolorkeyframespersecondgetti cksdoublebufferingpageflippinggifpngjpe gpcxtiffalphablendingtransparentopaques pritesprocessingeventskeyboardsystemarti ficalintelligencepointatexitrectwhilenoteof randommaskpalettepitchvideoaccelerators

1

December 15, 2011 [LEARNING SDL ? A BEGINNER'S GUIDE] Copyright ? 2011

Permission is granted to copy and distribute an electronic version of this document. Permission is NOT granted for commercial use.

2

December 15, 2011 [LEARNING SDL ? A BEGINNER'S GUIDE]

Dedication to those learning C++ ................................................................................................................. 6 Chapter 0: Introduction ................................................................................................................................. 7

Purpose...................................................................................................................................................... 7 Prerequisite ............................................................................................................................................... 8 What is out there now on SDL? ................................................................................................................ 8 Why SDL? ................................................................................................................................................ 9 A Bit of History ........................................................................................................................................ 9 The Components of SDL ........................................................................................................................ 10 Chapter 1 ? Installing SDL ......................................................................................................................... 14 Obtaining copies of all the libraries ........................................................................................................ 14 Installing to work with Code::Blocks ..................................................................................................... 17 Using the Code::Blocks SDL wizard ...................................................................................................... 28 Creating your own SDL Custom Template............................................................................................. 28 Installing to work with WxDev-C++ ...................................................................................................... 29 Creating a WxDev-Cpp SDL template file ............................................................................................. 39

Installing and Testing SDL_Image ..................................................................................................... 41 Installing and Testing SDL_tff ........................................................................................................... 44 Installing and Testing SDL_mixer ...................................................................................................... 47 Installing and Testing SDL_net .......................................................................................................... 48 Summary ................................................................................................................................................. 48 Chapter 2 - Getting started with SDL ........................................................................................................ 49 Initializing SDL ...................................................................................................................................... 49 Initializing and Closing SDL Subsystems .............................................................................................. 53 The Video Component ............................................................................................................................ 58 SDL Video Structures ............................................................................................................................. 59 Making Improvements to our Video Programs....................................................................................... 64 How the display screen is organized....................................................................................................... 66 Understanding how to write to the Display ............................................................................................ 67 Drawing a Line ....................................................................................................................................... 78 A Little History on Drawing Lines ..................................................................................................... 78 A Simple Algorithm ? Slope-Intercept Algorithm.............................................................................. 79 A Simple Algorithm #2 ? Using Symmetry........................................................................................ 83 SDL_Rect................................................................................................................................................ 84

3

December 15, 2011 [LEARNING SDL ? A BEGINNER'S GUIDE]

Clipping .................................................................................................................................................. 87 SDL_VideoInfo....................................................................................................................................... 89 Loading Images....................................................................................................................................... 91 Moving a Ball around on the screen.................................................................................................... 94 Double Buffering and Page Flipping .................................................................................................... 101

Double Buffering .............................................................................................................................. 101 Page Flipping .................................................................................................................................... 102 Displaying Other Types of Images ....................................................................................................... 104 Alpha Blending ..................................................................................................................................... 109 Other Topics.......................................................................................................................................... 114 Summary ............................................................................................................................................... 114 Review Questions ................................................................................................................................. 115 Programming Exercises ........................................................................................................................ 116 Circle-Drawing Algorithms .............................................................................................................. 117 Chapter 3 - Sprites, A Simple View......................................................................................................... 123 Chapter 4 - Processing Events ................................................................................................................. 124 Keyboard Events ................................................................................................................................... 126 Joystick Events...................................................................................................................................... 130 System Events ....................................................................................................................................... 131 Mouse Events........................................................................................................................................ 131 Chapter 5 ? How to organize a game ........................................................................................................ 131 Creating a Game Template ................................................................................................................... 131 Sample Games ...................................................................................................................................... 131 Chapter 6 ? Creating Pong ........................................................................................................................ 131 Using SDL_TTF ................................................................................................................................... 131 SDL Audio ............................................................................................................................................ 131 Some Audio Basics ........................................................................................................................... 132 Using SDL primitive functions ......................................................................................................... 134 SDL Joystick......................................................................................................................................... 136 Chapter 7 ? Creating MindSweeper.......................................................................................................... 136 Chapter 8 ? Creating Breakout.................................................................................................................. 136 Chapter 9 ? Creating Tetris....................................................................................................................... 136 Chapter 10 ? SDL Threads and Timers .................................................................................................... 136

4

December 15, 2011 [LEARNING SDL ? A BEGINNER'S GUIDE]

Chapter 11 ? Building a multiplayer online game .................................................................................... 136 SDL_NET ............................................................................................................................................. 136 SDL_MIXER ........................................................................................................................................ 136

Chapter 12 ? Building a Platform Game................................................................................................... 136 Why I love Crisis Mountain! ................................................................................................................ 136 Why I love Mario!! ............................................................................................................................... 136

Chapter 13 ? Other libraries and tools to build games.............................................................................. 137 Chapter 14 ? What comes next? ............................................................................................................... 137 Last Chapter .............................................................................................................................................. 137 Bibliography ............................................................................................................................................. 138 Appendix A: Places to visit on the Web ................................................................................................... 139 Appendix B ? Microsoft Visual C++ 2010 Express ................................................................................. 140 Appendix C ? Pong, Breakout and MindSweeper .................................................................................... 141

Pong ...................................................................................................................................................... 141 Breakout................................................................................................................................................ 141 MindSweeper ........................................................................................................................................ 142 Appendix D ? Unzipping files .................................................................................................................. 145 Appendix E ? Structs ................................................................................................................................ 150 What are structs?................................................................................................................................... 150 Why use structs? ................................................................................................................................... 150 In summary ........................................................................................................................................... 154 Things you can do with structs ............................................................................................................. 155 Things you can`t do with structs ........................................................................................................... 156 Using typedef with structs .................................................................................................................... 156 Appendix F ? Pointers .............................................................................................................................. 158

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download