SlideShare ist ein Scribd-Unternehmen logo
1 von 38
Game Development With SDL2
Who Am I ?
● Eric Basile
– Engineer at Hitpoint Studios.
● Worked On Win8 & iOS titles
– Graduated From Champlain College in Burlington VT
● Game Programming BS
– SDL has been my side project for the last year.
– Website
● Portfolio : EricBasile.com
● Blog : FaceKeyboard.com
– Contact
● Email : eric@ericbasile.com
● Twitter : @Samurai336
What Is SDL ?
● SDL stands for Simple Directmedia Layer
– Multimedia library that provides access to :
● Graphics, Sound, and Input devices.
– Cross Platform
● Set up to be a layer for interfacing with platform &
operating-system-specific functions.
– Written in C
● Supported Platforms include :
– Windows, Linux, OSX, Android, iOS
– Open Source
● SDL2 uses zlib license
History of SDL
● Created by Sam Lantinga at Loki Games 1998
– Used to port Doom to BeOS
– SMPEG and OpenAL developed to work along side.
● SDL 1.3 Announced in 2008 (This would become
2.0)
– Would use zlib license
● 1.2 and older use GNU LGPL
● SDL 2.0 officially announced July 14 2012
– Sam also announces he is joining valve software
Whats new in 2
● SDL v2.0.0 stable Released in August 11 2013
– Not backwards compatible with SDL 1.2
● Most repos only have 1.2 right now
– SDL2 Hardware accelerated
● 2D rendering using Direct3D, OpenGL or OpenGL ES
or software rendering in background.
– Official Android and iOS support
– Support for multiple windows
– Much Much more.
● Over view at: http://wiki.libsdl.org/MigrationGuide
Who's Using It ?
And Tons of Indie developers !!
Whats using it
AND SO MUCH MORE !!
Talk About Build Systems
● Cmake great for cross platform build systems
– Allows people to more or less use development
environment of choice.
– Cross Platform (Duh!)
– Fairly straightforward scripting.
Basic cmake syntax
file(GLOB game_files src/*.c src/*.cpp src/*.h src/*.hpp)
SOURCE_GROUP(Game FILES ${game_files})
add_executable(${App_Name}
${game_files}
)
find_package(SDL2)
include_directories(
${SDL2_INCLUDE_DIR}
${INCLUDE_DIRECTORIES}
)
target_link_libraries(${App_Name}
${SDL2_LIBRARY})
Complete cmake available at :
https://github.com/Samurai336/SDL2_PONG/blob/master/CMakeLists.txt
set (App_Name "SDL2_PONG")
Using Cmake
● Create Directory for your Project Build
– Avoid creating folder in Source Directory
● Run cmake
– Run cmake with path to directory containing
CmakeLists.txt
– $ cmake Path/to/folder/With/Cmake/List/
Cmake gui
Basic SDL Application
Initialize SDL
Handle Events
Draw
Clean up
Handle logic
Initializing SDL
● SDL_Init(uint32 flags) ;
– We can pick and choose what parts of SDL we want to
use (IE just Audio or just input).
● Available flags
– SDL_INIT_TIMER, SDL_INIT_AUDIO, SDL_INIT_VIDEO,
SDL_INIT_JOYSTICK, SDL_INIT_HAPTIC,
SDL_INIT_GAMECONTROLLER, SDL_INIT_EVENTS,
SDL_INIT_EVERYTHING.
● Use or for multiple flags (SDL_INIT_TIMER|SDL_INIT_AUDIO)
● We will use SDL_INIT_EVERYTHING.
– Check things Started ok.
if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
printf("failed to initin");
}
Create a window
● SDL_Window * MainWindow ;
– Pointer to what will be our main window
● SDL_Window* SDL_CreateWindow(const char* title, int x,int y,int
w,int h,Uint32 flags)
– Will give us a pointer to a created window at with specified
width, height, positon and title.
– Flags for windows include: SDL_WINDOW_FULLSCREEN,
SDL_WINDOW_BORDERLESS, SDL_WINDOW_RESIZABLE
and more.
MainWindow = SDL_CreateWindow("SDL2_PONG",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
800, 600,
SDL_WINDOW_RESIZABLE );
Create Render Context
● SDL_Renderer* Renderer ;
– Pointer to our Renderer
● SDL_Renderer* SDL_CreateRenderer(SDL_Window*
window, int index, Uint32 flags);
– Creates a 2D rendering context for a windows
● Pointer to the window
● the index of the rendering driver to initialize (-1 to
initialize the first one supporting the requested
flags)
● Enumerated flags to specify rendering context.
– Example : SDL_RENDERER_ACCELERATED
for hardware accelerated
SDL_CreateRenderer(MainWindow , -1, SDL_RENDERER_ACCELERATED );
Extensions
● SDL Has Several Extensions Libraries
– Used to Abstract lower level but common SDL
functionality (Ex : Loading Compressed Image
formats)
– Extension Libraries Available: SDL_image,
SDL_mixer,SDL_net, SDL_rtf, SDL_ttf.
– We will be Covering: SDL_image & SDL_mixer.
Starting Extensions
● Initializing Extensions
– Image
● IMG_Init(int flags)
– What format libs to load for Decoding Ex : IMG_INIT_JPG for jpg
● We will be using png
– Mixer
● Mix_OpenAudio(int frequency, Uint16 format, int channels, int
chunksize);
– We will use 44100 for frequency
– MIX_DEFAULT_FORMAT for our format
– 2 channels
– Chunk size of 4096
● More or less whats Default in the Documentation :P
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096)
IMG_Init(IMG_INIT_PNG);
SDL Event Handling
SDL_Event
● SDL_Event Handling
– Popular for abstracting input and other system
messages across OS's and platforms
● Can Be used independently
– SDL_Init(SDL_INIT_EVENTS);
● Used for :
– SDL_KeyboardEvent SDL_MouseButtonEvent
SDL_MouseMotionEvent SDL_WindowEvent
SDL_TouchFingerEvent and more...
Getting Events
● Use SDL_PollEvent(SDL_Event* event) to get
currently pending event.
– Works nicely with while loops in the main loop.
while (SDL_PollEvent(&event)) {
// handle your event here
}
Check Event Type
● Get event type
– Event->type
● Will tell you what this event is.
– Ex: SDL_CommonEvent,SDL_QuitEvent,
SDL_MouseButtonEvent, SDL_TouchEvent
● Works great in a Switch Statement
switch(test_event->type) {
case SDL_MOUSEMOTION:
printf("We got a motion event.n");
printf("Current mouse position is: (%d, %d)n",
test_event.motion.x, test_event.motion.y);
break;
default:
printf("Unhandled Event!n");
break;
}
}
Handling Event
● Use data from event Based on type
– Event->key.keysym.sym == SDLK_DOWN
● Handles down arrow.
– Keysym A structure that contains key information and sym is an
SDL virtual key code.
if(sym == SDLK_DOWN)
{
Player2.SetY(Player2.GetY() + 25);
}
else if(sym == SDLK_UP)
{
Player2.SetY(Player2.GetY() - 25);
}
2D Drawing
Cartesian plane in SDL
+Y
+X{0,0}
Loading an Image as a texture
● SDL_texture*
– Is a structure that contains an efficient, driver-specific
representation of pixel data.
● Using SDL_image
– SDL_Texture* IMG_LoadTexture(SDL_Renderer
*renderer, const char *file)
● Pointer to the render context where we will display our image.
● Path to our file.
● 1.2 used SDL_Surface*
OurTexture = IMG_LoadTexture(Renderer, "./ImageFile.png");
Drawing Images With
SDL_Renderer
● Will copy a portion of the texture to the
current rendering target
SDL_RenderCopyEx(Renderer, OurTexture, NULL, &DestR, 0.0, NULL,
SDL_FLIP_NONE);
DestR = {128,128,128,128}
Sprite Sheet Animated Image
Drawing
● Two SDL Rects
● SDL_Rects are just struct's with int's for X, Y Width and
Height.
– One for where on the sprite sheet and one for
where to display in the windows render context.
Here's our source rect parameter
would be {128,128,128,128}
SDL_RenderCopyEx(Renderer, OurTexture, &SrcR, &DestR, 0.0, NULL,
SDL_FLIP_NONE);
Sprite Sheet Animated Image
DrawingDestR = {128,128,128,128}
Drawing to The Screen
● SDL_RenderPresent(SDL_Renderer*
renderer)
– update the screen with rendering performed.
● SDL_RenderClear(SDL_Renderer* renderer)
– clear the current rendering target with the drawing
color.
● These Need to be done every frame to see
what we have drawn on screen.
SDL_RenderPresent(Renderer);
SDL_RenderClear(Renderer);
Drawing Simple shapes
● SDL_SetRenderDrawColor(SDL_Renderer*
renderer,Uint8 r,Uint8 g,Uint8 b,Uint8 a)
– Set our renderer's rgb draw color.
● SDL_RenderFillRect(SDL_Renderer* renderer,const
SDL_Rect* rect)
– Draws a rect in the passed render context
● Also Available in SDL are :
– SDL_RenderDrawLine, SDL_RenderDrawLines,
SDL_RenderDrawPoint, SDL_RenderDrawPoints,
SDL_RenderDrawRect, SDL_RenderDrawRects.
SDL_RenderFillRect(Renderer, &DestR);
Sound
Loading A sound File
● Using SDL_mixer
– Mix_Chunk* SoundFile;
● Pointer to Audio Data in memory
– Mix_Chunk *Mix_LoadWAV(const char *fname);
● Will load fname file into memory and return a pointer to
it.
Mix_Chunk* SoundFile = Mix_LoadWAV("./SoundFIle.wav") ;
Playing Sounds
● Mix_PlayChannel (int channel, Mix_Chunk
*chunk, int loops);
– Channel we want to play on
● -1 to let SDL choose it for you
– Pointer to our sound file
– How many times to loop
● 0 for once and -1 for infinite.
Mix_PlayChannel(-1, SoundFile, 0);
Clean up
● Its Important to Clean all the assets you have
loaded into memory.
● Assets
– images
● SDL_DestroyTexture(OurTexture);
– Sounds
● Mix_FreeChunk(SoundFile) ;
Shutting Down SDL
● Renderer
– SDL_DestroyRenderer(Renderer) ;
● Window
– SDL_DestroyWindow(MainWindow) ;
● Image Extension
– IMG_Quit();
● Audio
– Mix_CloseAudio() ;
● SDL
– SDL_Quit() ;
SDL2 Demo using Everything
Discussed.
Get It NOW !!
$ git clone https://github.com/Samurai336/SDL2_PONG.git
Reasons to use SDL beyond 2D
games.
● Able to pick and choose parts of SDL to use
– Input handler, Audio handler.. etc
● Used for 3D games
– Great for creating OpenGL OpenGLes 1.0 & 2.0 and
DirectX render contexts
– Now you have a way to handle cross platform input
● Works on just about anything
– Open source can compile it anywhere and add support
yourself
– Works on Windows, Linux, Mac OS X, iOS, Android
– Sorta works on PSP and Raspberry Pi
Resources
● Official website
– http://www.libsdl.org/
– Documentation → http://wiki.libsdl.org/
● SDL 1.2 tutorials and information
– http://lazyfoo.net/SDL_tutorials/index.php
– http://www.sdltutorials.com/
● History
– http://en.wikipedia.org/wiki/Simple_DirectMedia_Layer
● Game and company logos from
– http://store.steampowered.com/

Weitere ähnliche Inhalte

Was ist angesagt?

Building beautiful apps with Google flutter
Building beautiful apps with Google flutterBuilding beautiful apps with Google flutter
Building beautiful apps with Google flutterAhmed Abu Eldahab
 
Dart and Flutter Basics.pptx
Dart and Flutter Basics.pptxDart and Flutter Basics.pptx
Dart and Flutter Basics.pptxDSCVSSUT
 
The magic of flutter
The magic of flutterThe magic of flutter
The magic of flutterShady Selim
 
Android Development in a Nutshell
Android Development in a NutshellAndroid Development in a Nutshell
Android Development in a NutshellAleix Solé
 
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveBin Chen
 
Android Multimedia Framework
Android Multimedia FrameworkAndroid Multimedia Framework
Android Multimedia FrameworkPicker Weng
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android WorkshopOpersys inc.
 
Mobile development with Flutter
Mobile development with FlutterMobile development with Flutter
Mobile development with FlutterAwok
 

Was ist angesagt? (20)

Building beautiful apps with Google flutter
Building beautiful apps with Google flutterBuilding beautiful apps with Google flutter
Building beautiful apps with Google flutter
 
Dart and Flutter Basics.pptx
Dart and Flutter Basics.pptxDart and Flutter Basics.pptx
Dart and Flutter Basics.pptx
 
flutter.school #HelloWorld
flutter.school #HelloWorldflutter.school #HelloWorld
flutter.school #HelloWorld
 
Android Binder: Deep Dive
Android Binder: Deep DiveAndroid Binder: Deep Dive
Android Binder: Deep Dive
 
Hello Flutter
Hello FlutterHello Flutter
Hello Flutter
 
Flutter
FlutterFlutter
Flutter
 
The magic of flutter
The magic of flutterThe magic of flutter
The magic of flutter
 
Design and Concepts of Android Graphics
Design and Concepts of Android GraphicsDesign and Concepts of Android Graphics
Design and Concepts of Android Graphics
 
Flutter
FlutterFlutter
Flutter
 
Android Development in a Nutshell
Android Development in a NutshellAndroid Development in a Nutshell
Android Development in a Nutshell
 
Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)
 
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
 
Flutter introduction
Flutter introductionFlutter introduction
Flutter introduction
 
Flutter
FlutterFlutter
Flutter
 
Android Multimedia Framework
Android Multimedia FrameworkAndroid Multimedia Framework
Android Multimedia Framework
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android Workshop
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Embedded Android : System Development - Part IV
Embedded Android : System Development - Part IVEmbedded Android : System Development - Part IV
Embedded Android : System Development - Part IV
 
Mobile development with Flutter
Mobile development with FlutterMobile development with Flutter
Mobile development with Flutter
 
Flutter
FlutterFlutter
Flutter
 

Ähnlich wie SDL2 Game Development VT Code Camp 2013

The Ring programming language version 1.5.2 book - Part 47 of 181
The Ring programming language version 1.5.2 book - Part 47 of 181The Ring programming language version 1.5.2 book - Part 47 of 181
The Ring programming language version 1.5.2 book - Part 47 of 181Mahmoud Samir Fayed
 
Iphone and Ipad development Game with Cocos2D
Iphone and Ipad development Game with Cocos2DIphone and Ipad development Game with Cocos2D
Iphone and Ipad development Game with Cocos2Dcreagamers
 
The Ring programming language version 1.6 book - Part 50 of 189
The Ring programming language version 1.6 book - Part 50 of 189The Ring programming language version 1.6 book - Part 50 of 189
The Ring programming language version 1.6 book - Part 50 of 189Mahmoud Samir Fayed
 
Castle Game Engine and the joy of making and using a custom game engine
Castle Game Engine and the joy  of making and using a custom game engineCastle Game Engine and the joy  of making and using a custom game engine
Castle Game Engine and the joy of making and using a custom game engineMichalis Kamburelis
 
BitSquid Tech: Benefits of a data-driven renderer
BitSquid Tech: Benefits of a data-driven rendererBitSquid Tech: Benefits of a data-driven renderer
BitSquid Tech: Benefits of a data-driven renderertobias_persson
 
The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185Mahmoud Samir Fayed
 
International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)ijceronline
 
Game Programming I - Introduction
Game Programming I - IntroductionGame Programming I - Introduction
Game Programming I - IntroductionFrancis Seriña
 
Cross-platform game engine development with SDL 2.0
Cross-platform game engine development with SDL 2.0Cross-platform game engine development with SDL 2.0
Cross-platform game engine development with SDL 2.0Leszek Godlewski
 
Linux as a gaming platform - Errata
Linux as a gaming platform - ErrataLinux as a gaming platform - Errata
Linux as a gaming platform - ErrataLeszek Godlewski
 
Unity advanced computer graphics week 02
Unity advanced computer graphics week 02Unity advanced computer graphics week 02
Unity advanced computer graphics week 02Tri Thanh
 
Example uses of gpu compute models
Example uses of gpu compute modelsExample uses of gpu compute models
Example uses of gpu compute modelsPedram Mazloom
 
Embedded Linux Multimedia
Embedded Linux MultimediaEmbedded Linux Multimedia
Embedded Linux MultimediaCaglar Dursun
 
Gdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glGdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glchangehee lee
 
Pacman game computer investigatory project
Pacman game computer investigatory projectPacman game computer investigatory project
Pacman game computer investigatory projectmeenaloshiniG
 
Developing games and graphic visualizations in Pascal
Developing games and graphic visualizations in PascalDeveloping games and graphic visualizations in Pascal
Developing games and graphic visualizations in PascalMichalis Kamburelis
 

Ähnlich wie SDL2 Game Development VT Code Camp 2013 (20)

The Ring programming language version 1.5.2 book - Part 47 of 181
The Ring programming language version 1.5.2 book - Part 47 of 181The Ring programming language version 1.5.2 book - Part 47 of 181
The Ring programming language version 1.5.2 book - Part 47 of 181
 
Iphone and Ipad development Game with Cocos2D
Iphone and Ipad development Game with Cocos2DIphone and Ipad development Game with Cocos2D
Iphone and Ipad development Game with Cocos2D
 
SDAccel Design Contest: Xilinx SDAccel
SDAccel Design Contest: Xilinx SDAccel SDAccel Design Contest: Xilinx SDAccel
SDAccel Design Contest: Xilinx SDAccel
 
The Ring programming language version 1.6 book - Part 50 of 189
The Ring programming language version 1.6 book - Part 50 of 189The Ring programming language version 1.6 book - Part 50 of 189
The Ring programming language version 1.6 book - Part 50 of 189
 
Castle Game Engine and the joy of making and using a custom game engine
Castle Game Engine and the joy  of making and using a custom game engineCastle Game Engine and the joy  of making and using a custom game engine
Castle Game Engine and the joy of making and using a custom game engine
 
BitSquid Tech: Benefits of a data-driven renderer
BitSquid Tech: Benefits of a data-driven rendererBitSquid Tech: Benefits of a data-driven renderer
BitSquid Tech: Benefits of a data-driven renderer
 
The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185
 
Gtug
GtugGtug
Gtug
 
International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)
 
Game Programming I - Introduction
Game Programming I - IntroductionGame Programming I - Introduction
Game Programming I - Introduction
 
Cross-platform game engine development with SDL 2.0
Cross-platform game engine development with SDL 2.0Cross-platform game engine development with SDL 2.0
Cross-platform game engine development with SDL 2.0
 
Linux as a gaming platform - Errata
Linux as a gaming platform - ErrataLinux as a gaming platform - Errata
Linux as a gaming platform - Errata
 
Shaders in Unity
Shaders in UnityShaders in Unity
Shaders in Unity
 
Unity advanced computer graphics week 02
Unity advanced computer graphics week 02Unity advanced computer graphics week 02
Unity advanced computer graphics week 02
 
Example uses of gpu compute models
Example uses of gpu compute modelsExample uses of gpu compute models
Example uses of gpu compute models
 
Embedded Linux Multimedia
Embedded Linux MultimediaEmbedded Linux Multimedia
Embedded Linux Multimedia
 
Gdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glGdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_gl
 
Pacman game computer investigatory project
Pacman game computer investigatory projectPacman game computer investigatory project
Pacman game computer investigatory project
 
There is more to C
There is more to CThere is more to C
There is more to C
 
Developing games and graphic visualizations in Pascal
Developing games and graphic visualizations in PascalDeveloping games and graphic visualizations in Pascal
Developing games and graphic visualizations in Pascal
 

Kürzlich hochgeladen

JORNADA 2 LIGA MUROBASQUETBOL1 2024.docx
JORNADA 2 LIGA MUROBASQUETBOL1 2024.docxJORNADA 2 LIGA MUROBASQUETBOL1 2024.docx
JORNADA 2 LIGA MUROBASQUETBOL1 2024.docxArturo Pacheco Alvarez
 
DONAL88 >LINK SLOT PG SOFT TERGACOR 2024
DONAL88 >LINK SLOT PG SOFT TERGACOR 2024DONAL88 >LINK SLOT PG SOFT TERGACOR 2024
DONAL88 >LINK SLOT PG SOFT TERGACOR 2024DONAL88 GACOR
 
Introduction to Basketball-PowerPoint Presentation
Introduction to Basketball-PowerPoint PresentationIntroduction to Basketball-PowerPoint Presentation
Introduction to Basketball-PowerPoint PresentationJuliusMacaballug
 
Italy Vs Albania Euro Cup 2024 Italy's Strategy for Success.docx
Italy Vs Albania Euro Cup 2024 Italy's Strategy for Success.docxItaly Vs Albania Euro Cup 2024 Italy's Strategy for Success.docx
Italy Vs Albania Euro Cup 2024 Italy's Strategy for Success.docxWorld Wide Tickets And Hospitality
 
Clash of Titans_ PSG vs Barcelona (1).pdf
Clash of Titans_ PSG vs Barcelona (1).pdfClash of Titans_ PSG vs Barcelona (1).pdf
Clash of Titans_ PSG vs Barcelona (1).pdfMuhammad Hashim
 
Benifits of Individual And Team Sports-Group 7.pptx
Benifits of Individual And Team Sports-Group 7.pptxBenifits of Individual And Team Sports-Group 7.pptx
Benifits of Individual And Team Sports-Group 7.pptxsherrymieg19
 
JORNADA 3 LIGA MURO 2024GHGHGHGHGHGH.pdf
JORNADA 3 LIGA MURO 2024GHGHGHGHGHGH.pdfJORNADA 3 LIGA MURO 2024GHGHGHGHGHGH.pdf
JORNADA 3 LIGA MURO 2024GHGHGHGHGHGH.pdfArturo Pacheco Alvarez
 
Spain Vs Italy Showdown Between Italy and Spain Could Determine UEFA Euro 202...
Spain Vs Italy Showdown Between Italy and Spain Could Determine UEFA Euro 202...Spain Vs Italy Showdown Between Italy and Spain Could Determine UEFA Euro 202...
Spain Vs Italy Showdown Between Italy and Spain Could Determine UEFA Euro 202...World Wide Tickets And Hospitality
 
PPT on INDIA VS PAKISTAN - A Sports Rivalry
PPT on INDIA VS PAKISTAN - A Sports RivalryPPT on INDIA VS PAKISTAN - A Sports Rivalry
PPT on INDIA VS PAKISTAN - A Sports Rivalryanirbannath184
 
Project & Portfolio, Market Analysis: WWE
Project & Portfolio, Market Analysis: WWEProject & Portfolio, Market Analysis: WWE
Project & Portfolio, Market Analysis: WWEDeShawn Ellis
 

Kürzlich hochgeladen (11)

JORNADA 2 LIGA MUROBASQUETBOL1 2024.docx
JORNADA 2 LIGA MUROBASQUETBOL1 2024.docxJORNADA 2 LIGA MUROBASQUETBOL1 2024.docx
JORNADA 2 LIGA MUROBASQUETBOL1 2024.docx
 
NATIONAL SPORTS DAY WRITTEN QUIZ by QUI9
NATIONAL SPORTS DAY WRITTEN QUIZ by QUI9NATIONAL SPORTS DAY WRITTEN QUIZ by QUI9
NATIONAL SPORTS DAY WRITTEN QUIZ by QUI9
 
DONAL88 >LINK SLOT PG SOFT TERGACOR 2024
DONAL88 >LINK SLOT PG SOFT TERGACOR 2024DONAL88 >LINK SLOT PG SOFT TERGACOR 2024
DONAL88 >LINK SLOT PG SOFT TERGACOR 2024
 
Introduction to Basketball-PowerPoint Presentation
Introduction to Basketball-PowerPoint PresentationIntroduction to Basketball-PowerPoint Presentation
Introduction to Basketball-PowerPoint Presentation
 
Italy Vs Albania Euro Cup 2024 Italy's Strategy for Success.docx
Italy Vs Albania Euro Cup 2024 Italy's Strategy for Success.docxItaly Vs Albania Euro Cup 2024 Italy's Strategy for Success.docx
Italy Vs Albania Euro Cup 2024 Italy's Strategy for Success.docx
 
Clash of Titans_ PSG vs Barcelona (1).pdf
Clash of Titans_ PSG vs Barcelona (1).pdfClash of Titans_ PSG vs Barcelona (1).pdf
Clash of Titans_ PSG vs Barcelona (1).pdf
 
Benifits of Individual And Team Sports-Group 7.pptx
Benifits of Individual And Team Sports-Group 7.pptxBenifits of Individual And Team Sports-Group 7.pptx
Benifits of Individual And Team Sports-Group 7.pptx
 
JORNADA 3 LIGA MURO 2024GHGHGHGHGHGH.pdf
JORNADA 3 LIGA MURO 2024GHGHGHGHGHGH.pdfJORNADA 3 LIGA MURO 2024GHGHGHGHGHGH.pdf
JORNADA 3 LIGA MURO 2024GHGHGHGHGHGH.pdf
 
Spain Vs Italy Showdown Between Italy and Spain Could Determine UEFA Euro 202...
Spain Vs Italy Showdown Between Italy and Spain Could Determine UEFA Euro 202...Spain Vs Italy Showdown Between Italy and Spain Could Determine UEFA Euro 202...
Spain Vs Italy Showdown Between Italy and Spain Could Determine UEFA Euro 202...
 
PPT on INDIA VS PAKISTAN - A Sports Rivalry
PPT on INDIA VS PAKISTAN - A Sports RivalryPPT on INDIA VS PAKISTAN - A Sports Rivalry
PPT on INDIA VS PAKISTAN - A Sports Rivalry
 
Project & Portfolio, Market Analysis: WWE
Project & Portfolio, Market Analysis: WWEProject & Portfolio, Market Analysis: WWE
Project & Portfolio, Market Analysis: WWE
 

SDL2 Game Development VT Code Camp 2013

  • 2. Who Am I ? ● Eric Basile – Engineer at Hitpoint Studios. ● Worked On Win8 & iOS titles – Graduated From Champlain College in Burlington VT ● Game Programming BS – SDL has been my side project for the last year. – Website ● Portfolio : EricBasile.com ● Blog : FaceKeyboard.com – Contact ● Email : eric@ericbasile.com ● Twitter : @Samurai336
  • 3. What Is SDL ? ● SDL stands for Simple Directmedia Layer – Multimedia library that provides access to : ● Graphics, Sound, and Input devices. – Cross Platform ● Set up to be a layer for interfacing with platform & operating-system-specific functions. – Written in C ● Supported Platforms include : – Windows, Linux, OSX, Android, iOS – Open Source ● SDL2 uses zlib license
  • 4. History of SDL ● Created by Sam Lantinga at Loki Games 1998 – Used to port Doom to BeOS – SMPEG and OpenAL developed to work along side. ● SDL 1.3 Announced in 2008 (This would become 2.0) – Would use zlib license ● 1.2 and older use GNU LGPL ● SDL 2.0 officially announced July 14 2012 – Sam also announces he is joining valve software
  • 5. Whats new in 2 ● SDL v2.0.0 stable Released in August 11 2013 – Not backwards compatible with SDL 1.2 ● Most repos only have 1.2 right now – SDL2 Hardware accelerated ● 2D rendering using Direct3D, OpenGL or OpenGL ES or software rendering in background. – Official Android and iOS support – Support for multiple windows – Much Much more. ● Over view at: http://wiki.libsdl.org/MigrationGuide
  • 6. Who's Using It ? And Tons of Indie developers !!
  • 7. Whats using it AND SO MUCH MORE !!
  • 8. Talk About Build Systems ● Cmake great for cross platform build systems – Allows people to more or less use development environment of choice. – Cross Platform (Duh!) – Fairly straightforward scripting.
  • 9. Basic cmake syntax file(GLOB game_files src/*.c src/*.cpp src/*.h src/*.hpp) SOURCE_GROUP(Game FILES ${game_files}) add_executable(${App_Name} ${game_files} ) find_package(SDL2) include_directories( ${SDL2_INCLUDE_DIR} ${INCLUDE_DIRECTORIES} ) target_link_libraries(${App_Name} ${SDL2_LIBRARY}) Complete cmake available at : https://github.com/Samurai336/SDL2_PONG/blob/master/CMakeLists.txt set (App_Name "SDL2_PONG")
  • 10. Using Cmake ● Create Directory for your Project Build – Avoid creating folder in Source Directory ● Run cmake – Run cmake with path to directory containing CmakeLists.txt – $ cmake Path/to/folder/With/Cmake/List/
  • 12. Basic SDL Application Initialize SDL Handle Events Draw Clean up Handle logic
  • 13. Initializing SDL ● SDL_Init(uint32 flags) ; – We can pick and choose what parts of SDL we want to use (IE just Audio or just input). ● Available flags – SDL_INIT_TIMER, SDL_INIT_AUDIO, SDL_INIT_VIDEO, SDL_INIT_JOYSTICK, SDL_INIT_HAPTIC, SDL_INIT_GAMECONTROLLER, SDL_INIT_EVENTS, SDL_INIT_EVERYTHING. ● Use or for multiple flags (SDL_INIT_TIMER|SDL_INIT_AUDIO) ● We will use SDL_INIT_EVERYTHING. – Check things Started ok. if(SDL_Init(SDL_INIT_EVERYTHING) < 0) { printf("failed to initin"); }
  • 14. Create a window ● SDL_Window * MainWindow ; – Pointer to what will be our main window ● SDL_Window* SDL_CreateWindow(const char* title, int x,int y,int w,int h,Uint32 flags) – Will give us a pointer to a created window at with specified width, height, positon and title. – Flags for windows include: SDL_WINDOW_FULLSCREEN, SDL_WINDOW_BORDERLESS, SDL_WINDOW_RESIZABLE and more. MainWindow = SDL_CreateWindow("SDL2_PONG", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_RESIZABLE );
  • 15. Create Render Context ● SDL_Renderer* Renderer ; – Pointer to our Renderer ● SDL_Renderer* SDL_CreateRenderer(SDL_Window* window, int index, Uint32 flags); – Creates a 2D rendering context for a windows ● Pointer to the window ● the index of the rendering driver to initialize (-1 to initialize the first one supporting the requested flags) ● Enumerated flags to specify rendering context. – Example : SDL_RENDERER_ACCELERATED for hardware accelerated SDL_CreateRenderer(MainWindow , -1, SDL_RENDERER_ACCELERATED );
  • 16. Extensions ● SDL Has Several Extensions Libraries – Used to Abstract lower level but common SDL functionality (Ex : Loading Compressed Image formats) – Extension Libraries Available: SDL_image, SDL_mixer,SDL_net, SDL_rtf, SDL_ttf. – We will be Covering: SDL_image & SDL_mixer.
  • 17. Starting Extensions ● Initializing Extensions – Image ● IMG_Init(int flags) – What format libs to load for Decoding Ex : IMG_INIT_JPG for jpg ● We will be using png – Mixer ● Mix_OpenAudio(int frequency, Uint16 format, int channels, int chunksize); – We will use 44100 for frequency – MIX_DEFAULT_FORMAT for our format – 2 channels – Chunk size of 4096 ● More or less whats Default in the Documentation :P Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) IMG_Init(IMG_INIT_PNG);
  • 19. SDL_Event ● SDL_Event Handling – Popular for abstracting input and other system messages across OS's and platforms ● Can Be used independently – SDL_Init(SDL_INIT_EVENTS); ● Used for : – SDL_KeyboardEvent SDL_MouseButtonEvent SDL_MouseMotionEvent SDL_WindowEvent SDL_TouchFingerEvent and more...
  • 20. Getting Events ● Use SDL_PollEvent(SDL_Event* event) to get currently pending event. – Works nicely with while loops in the main loop. while (SDL_PollEvent(&event)) { // handle your event here }
  • 21. Check Event Type ● Get event type – Event->type ● Will tell you what this event is. – Ex: SDL_CommonEvent,SDL_QuitEvent, SDL_MouseButtonEvent, SDL_TouchEvent ● Works great in a Switch Statement switch(test_event->type) { case SDL_MOUSEMOTION: printf("We got a motion event.n"); printf("Current mouse position is: (%d, %d)n", test_event.motion.x, test_event.motion.y); break; default: printf("Unhandled Event!n"); break; } }
  • 22. Handling Event ● Use data from event Based on type – Event->key.keysym.sym == SDLK_DOWN ● Handles down arrow. – Keysym A structure that contains key information and sym is an SDL virtual key code. if(sym == SDLK_DOWN) { Player2.SetY(Player2.GetY() + 25); } else if(sym == SDLK_UP) { Player2.SetY(Player2.GetY() - 25); }
  • 24. Cartesian plane in SDL +Y +X{0,0}
  • 25. Loading an Image as a texture ● SDL_texture* – Is a structure that contains an efficient, driver-specific representation of pixel data. ● Using SDL_image – SDL_Texture* IMG_LoadTexture(SDL_Renderer *renderer, const char *file) ● Pointer to the render context where we will display our image. ● Path to our file. ● 1.2 used SDL_Surface* OurTexture = IMG_LoadTexture(Renderer, "./ImageFile.png");
  • 26. Drawing Images With SDL_Renderer ● Will copy a portion of the texture to the current rendering target SDL_RenderCopyEx(Renderer, OurTexture, NULL, &DestR, 0.0, NULL, SDL_FLIP_NONE); DestR = {128,128,128,128}
  • 27. Sprite Sheet Animated Image Drawing ● Two SDL Rects ● SDL_Rects are just struct's with int's for X, Y Width and Height. – One for where on the sprite sheet and one for where to display in the windows render context. Here's our source rect parameter would be {128,128,128,128} SDL_RenderCopyEx(Renderer, OurTexture, &SrcR, &DestR, 0.0, NULL, SDL_FLIP_NONE);
  • 28. Sprite Sheet Animated Image DrawingDestR = {128,128,128,128}
  • 29. Drawing to The Screen ● SDL_RenderPresent(SDL_Renderer* renderer) – update the screen with rendering performed. ● SDL_RenderClear(SDL_Renderer* renderer) – clear the current rendering target with the drawing color. ● These Need to be done every frame to see what we have drawn on screen. SDL_RenderPresent(Renderer); SDL_RenderClear(Renderer);
  • 30. Drawing Simple shapes ● SDL_SetRenderDrawColor(SDL_Renderer* renderer,Uint8 r,Uint8 g,Uint8 b,Uint8 a) – Set our renderer's rgb draw color. ● SDL_RenderFillRect(SDL_Renderer* renderer,const SDL_Rect* rect) – Draws a rect in the passed render context ● Also Available in SDL are : – SDL_RenderDrawLine, SDL_RenderDrawLines, SDL_RenderDrawPoint, SDL_RenderDrawPoints, SDL_RenderDrawRect, SDL_RenderDrawRects. SDL_RenderFillRect(Renderer, &DestR);
  • 31. Sound
  • 32. Loading A sound File ● Using SDL_mixer – Mix_Chunk* SoundFile; ● Pointer to Audio Data in memory – Mix_Chunk *Mix_LoadWAV(const char *fname); ● Will load fname file into memory and return a pointer to it. Mix_Chunk* SoundFile = Mix_LoadWAV("./SoundFIle.wav") ;
  • 33. Playing Sounds ● Mix_PlayChannel (int channel, Mix_Chunk *chunk, int loops); – Channel we want to play on ● -1 to let SDL choose it for you – Pointer to our sound file – How many times to loop ● 0 for once and -1 for infinite. Mix_PlayChannel(-1, SoundFile, 0);
  • 34. Clean up ● Its Important to Clean all the assets you have loaded into memory. ● Assets – images ● SDL_DestroyTexture(OurTexture); – Sounds ● Mix_FreeChunk(SoundFile) ;
  • 35. Shutting Down SDL ● Renderer – SDL_DestroyRenderer(Renderer) ; ● Window – SDL_DestroyWindow(MainWindow) ; ● Image Extension – IMG_Quit(); ● Audio – Mix_CloseAudio() ; ● SDL – SDL_Quit() ;
  • 36. SDL2 Demo using Everything Discussed. Get It NOW !! $ git clone https://github.com/Samurai336/SDL2_PONG.git
  • 37. Reasons to use SDL beyond 2D games. ● Able to pick and choose parts of SDL to use – Input handler, Audio handler.. etc ● Used for 3D games – Great for creating OpenGL OpenGLes 1.0 & 2.0 and DirectX render contexts – Now you have a way to handle cross platform input ● Works on just about anything – Open source can compile it anywhere and add support yourself – Works on Windows, Linux, Mac OS X, iOS, Android – Sorta works on PSP and Raspberry Pi
  • 38. Resources ● Official website – http://www.libsdl.org/ – Documentation → http://wiki.libsdl.org/ ● SDL 1.2 tutorials and information – http://lazyfoo.net/SDL_tutorials/index.php – http://www.sdltutorials.com/ ● History – http://en.wikipedia.org/wiki/Simple_DirectMedia_Layer ● Game and company logos from – http://store.steampowered.com/