Chapter 0: Introduction
Total Page:16
File Type:pdf, Size:1020Kb
Sdlsimpledirectmedialayergraphicslib arycrossplatform2dsamlantingaportvi deoeventhandlingjoystickfileioaudiocd romtimersthreadingimagemixermodm Beginner’s Guide to SDL p3wavoggvorbisttfdirectxopenglmaincBuilding Games with SDL and C++ 3/6/2011 odeblockssdl_Intdisplaysurfacegeterro n y g u e r r i l l a g i r l @ b r a i n y c o d e . c o m rscreenwidthanyformatsdlsurfacesetc aptionfre esurfacesdlquitpolleventupd aterecteventtypesdlprojectideuint32b ooleaninitlibaryatexitinitsubsystemga meloopintelligencecomputecollisiongr aphicssoundsplaywhilealphachannels dlcolorflagsrgbalphaacceleratorasyncd elaypixelsvideopitchcliprectformatma prgbbytesperpixelmaskpalettelocksurf aceunlockrandomplotdrawlinepointxd fghjklzxcvbnmqwertyuiopasdfghjklzxc March 6, 2011 BEGINNER’S GUIDE TO SDL Copyright (C) 2011 brainycode.com Permission is granted to copy and distribute an electronic version of this document. Permission is NOT granted for commercial use. 2 March 6, 2011 BEGINNER’S GUIDE TO SDL 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 ........................................................................................................15 Obtaining copies of all the libraries ........................................................................................15 Installing to work with Code::Blocks .......................................................................................18 Using the Code::Blocks SDL wizard ......................................................................................27 Creating your own SDL Custom Template .............................................................................28 Installing to work with WxDev-C++ ........................................................................................29 Creating a WxDev-Cpp SDL template file ..............................................................................38 Installing and Testing SDL_Image .....................................................................................40 Installing and Testing SDL_tff ............................................................................................43 Installing and Testing SDL_mixer .......................................................................................46 Installing and Testing SDL_net ..........................................................................................47 Chapter 2 - Getting started with SDL ........................................................................................48 Initializing SDL .......................................................................................................................48 Initializing and Closing SDL Subsystems ...............................................................................52 The Video Component ...........................................................................................................57 SDL Video Structures ............................................................................................................58 Making Improvements to our Video Programs .......................................................................63 How the display screen is organized .....................................................................................65 Understanding how to write to the Display .............................................................................67 Drawing a Line ......................................................................................................................77 A Little History on Drawing Lines .......................................................................................77 A Simple Algorithm – Slope-Intercept Algorithm .................................................................78 A Simple Algorithm #2 – Using Symmetry ..........................................................................82 SDL_Rect ..............................................................................................................................84 Clipping .................................................................................................................................87 3 March 6, 2011 BEGINNER’S GUIDE TO SDL SDL_VideoInfo ......................................................................................................................89 Loading Images .....................................................................................................................91 Moving a ―Ball‖ around on the screen ....................................................................................95 Double Buffering and Page Flipping .................................................................................... 102 Double Buffering .............................................................................................................. 102 Page Flipping ................................................................................................................... 103 Displaying Other Types of Images ....................................................................................... 105 Alpha Blending .................................................................................................................... 110 Other Topics ........................................................................................................................ 115 Summary ............................................................................................................................. 115 Questions ............................................................................................................................ 115 Programming Exercises .......................................................................................................... 116 Circle-Drawing Algorithms ....................................................................................................... 116 Chapter 3 – Sprites, A Simple View ........................................................................................ 127 Chapter 3 - Processing Events ............................................................................................... 127 Keyboard Events ................................................................................................................. 128 Joystick Events .................................................................................................................... 132 System Events .................................................................................................................... 133 Mouse Events ...................................................................................................................... 133 Chapter 4 – How to organize a game ...................................................................................... 133 Creating a Game Template ................................................................................................. 133 Sample Games .................................................................................................................... 133 Chapter 5 – Creating Pong ..................................................................................................... 133 Using SDL_TTF ................................................................................................................... 133 SDL Audio ........................................................................................................................... 133 SDL Joystick........................................................................................................................ 133 Chapter 6 – Creating MindSweeper ........................................................................................ 133 Chapter 7 – Creating Breakout ................................................................................................ 133 Chapter 8 – Creating Tetris ..................................................................................................... 133 Chapter 9 – SDL Threads and Timers ..................................................................................... 134 Chapter 10 – Building a multiplayer online game .................................................................... 134 SDL_NET ............................................................................................................................ 134 SDL_MIXER .......................................................................................................................