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?

(Big) Data Serialization with Avro and Protobuf
(Big) Data Serialization with Avro and Protobuf(Big) Data Serialization with Avro and Protobuf
(Big) Data Serialization with Avro and ProtobufGuido Schmutz
 
AWS Solution Architect Associate Report
AWS Solution Architect Associate ReportAWS Solution Architect Associate Report
AWS Solution Architect Associate ReportSHIVJIprasad2
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The BasicsJeff Fox
 
Introduction to WSO2 ESB
Introduction to WSO2 ESB Introduction to WSO2 ESB
Introduction to WSO2 ESB WSO2
 
Build and Manage Your APIs with Amazon API Gateway
Build and Manage Your APIs with Amazon API GatewayBuild and Manage Your APIs with Amazon API Gateway
Build and Manage Your APIs with Amazon API GatewayAmazon Web Services
 
Introduction to Amazon Web Services - How to Scale your Next Idea on AWS : A ...
Introduction to Amazon Web Services - How to Scale your Next Idea on AWS : A ...Introduction to Amazon Web Services - How to Scale your Next Idea on AWS : A ...
Introduction to Amazon Web Services - How to Scale your Next Idea on AWS : A ...Amazon Web Services
 
Oracle Service Bus 12c (12.2.1) What You Always Wanted to Know
Oracle Service Bus 12c (12.2.1) What You Always Wanted to KnowOracle Service Bus 12c (12.2.1) What You Always Wanted to Know
Oracle Service Bus 12c (12.2.1) What You Always Wanted to KnowFrank Munz
 
Kakao Cloud Native Platform, 9rum
Kakao Cloud Native Platform, 9rumKakao Cloud Native Platform, 9rum
Kakao Cloud Native Platform, 9rumif kakao
 
AWS Route53 Fundamentals
AWS Route53 FundamentalsAWS Route53 Fundamentals
AWS Route53 FundamentalsPiyush Agrawal
 
Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018
 Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018 Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018
Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018Amazon Web Services Korea
 
AWS 마켓플레이스 성공 런칭을 위한 핵심 기술 (이경수, AWS 솔루션즈아키텍트) :: AWS TechShift 2018
AWS 마켓플레이스 성공 런칭을 위한 핵심 기술 (이경수, AWS 솔루션즈아키텍트) :: AWS TechShift 2018AWS 마켓플레이스 성공 런칭을 위한 핵심 기술 (이경수, AWS 솔루션즈아키텍트) :: AWS TechShift 2018
AWS 마켓플레이스 성공 런칭을 위한 핵심 기술 (이경수, AWS 솔루션즈아키텍트) :: AWS TechShift 2018Amazon Web Services Korea
 
Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017
Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017
Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017Amazon Web Services Korea
 
마이크로서비스 아키텍처로 개발하기
마이크로서비스 아키텍처로 개발하기마이크로서비스 아키텍처로 개발하기
마이크로서비스 아키텍처로 개발하기Jaewoo Ahn
 
모놀리스에서 마이크로서비스 아키텍처로의 전환 전략::박선용::AWS Summit Seoul 2018
모놀리스에서 마이크로서비스 아키텍처로의 전환 전략::박선용::AWS Summit Seoul 2018모놀리스에서 마이크로서비스 아키텍처로의 전환 전략::박선용::AWS Summit Seoul 2018
모놀리스에서 마이크로서비스 아키텍처로의 전환 전략::박선용::AWS Summit Seoul 2018Amazon Web Services Korea
 
API Integration For Building Software Applications Powerpoint Presentation Sl...
API Integration For Building Software Applications Powerpoint Presentation Sl...API Integration For Building Software Applications Powerpoint Presentation Sl...
API Integration For Building Software Applications Powerpoint Presentation Sl...SlideTeam
 
Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservicesAnil Allewar
 

Was ist angesagt? (20)

(Big) Data Serialization with Avro and Protobuf
(Big) Data Serialization with Avro and Protobuf(Big) Data Serialization with Avro and Protobuf
(Big) Data Serialization with Avro and Protobuf
 
AWS Solution Architect Associate Report
AWS Solution Architect Associate ReportAWS Solution Architect Associate Report
AWS Solution Architect Associate Report
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
 
Introduction to WSO2 ESB
Introduction to WSO2 ESB Introduction to WSO2 ESB
Introduction to WSO2 ESB
 
Build and Manage Your APIs with Amazon API Gateway
Build and Manage Your APIs with Amazon API GatewayBuild and Manage Your APIs with Amazon API Gateway
Build and Manage Your APIs with Amazon API Gateway
 
Introduction to Amazon Web Services - How to Scale your Next Idea on AWS : A ...
Introduction to Amazon Web Services - How to Scale your Next Idea on AWS : A ...Introduction to Amazon Web Services - How to Scale your Next Idea on AWS : A ...
Introduction to Amazon Web Services - How to Scale your Next Idea on AWS : A ...
 
Oracle Service Bus 12c (12.2.1) What You Always Wanted to Know
Oracle Service Bus 12c (12.2.1) What You Always Wanted to KnowOracle Service Bus 12c (12.2.1) What You Always Wanted to Know
Oracle Service Bus 12c (12.2.1) What You Always Wanted to Know
 
Express
ExpressExpress
Express
 
Kakao Cloud Native Platform, 9rum
Kakao Cloud Native Platform, 9rumKakao Cloud Native Platform, 9rum
Kakao Cloud Native Platform, 9rum
 
AWS Route53 Fundamentals
AWS Route53 FundamentalsAWS Route53 Fundamentals
AWS Route53 Fundamentals
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018
 Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018 Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018
Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018
 
AWS 마켓플레이스 성공 런칭을 위한 핵심 기술 (이경수, AWS 솔루션즈아키텍트) :: AWS TechShift 2018
AWS 마켓플레이스 성공 런칭을 위한 핵심 기술 (이경수, AWS 솔루션즈아키텍트) :: AWS TechShift 2018AWS 마켓플레이스 성공 런칭을 위한 핵심 기술 (이경수, AWS 솔루션즈아키텍트) :: AWS TechShift 2018
AWS 마켓플레이스 성공 런칭을 위한 핵심 기술 (이경수, AWS 솔루션즈아키텍트) :: AWS TechShift 2018
 
Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017
Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017
Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017
 
마이크로서비스 아키텍처로 개발하기
마이크로서비스 아키텍처로 개발하기마이크로서비스 아키텍처로 개발하기
마이크로서비스 아키텍처로 개발하기
 
REST API Basics
REST API BasicsREST API Basics
REST API Basics
 
모놀리스에서 마이크로서비스 아키텍처로의 전환 전략::박선용::AWS Summit Seoul 2018
모놀리스에서 마이크로서비스 아키텍처로의 전환 전략::박선용::AWS Summit Seoul 2018모놀리스에서 마이크로서비스 아키텍처로의 전환 전략::박선용::AWS Summit Seoul 2018
모놀리스에서 마이크로서비스 아키텍처로의 전환 전략::박선용::AWS Summit Seoul 2018
 
Scalability and Performance
Scalability and PerformanceScalability and Performance
Scalability and Performance
 
API Integration For Building Software Applications Powerpoint Presentation Sl...
API Integration For Building Software Applications Powerpoint Presentation Sl...API Integration For Building Software Applications Powerpoint Presentation Sl...
API Integration For Building Software Applications Powerpoint Presentation Sl...
 
Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservices
 

Ä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

Sports Writing (Rules,Tips, Examples, etc)
Sports Writing (Rules,Tips, Examples, etc)Sports Writing (Rules,Tips, Examples, etc)
Sports Writing (Rules,Tips, Examples, etc)CMBustamante
 
Sector 62, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 62, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Who Is Emmanuel Katto Uganda? His Career, personal life etc.
Who Is Emmanuel Katto Uganda? His Career, personal life etc.Who Is Emmanuel Katto Uganda? His Career, personal life etc.
Who Is Emmanuel Katto Uganda? His Career, personal life etc.Marina Costa
 
Cricket Api Solution.pdfCricket Api Solution.pdf
Cricket Api Solution.pdfCricket Api Solution.pdfCricket Api Solution.pdfCricket Api Solution.pdf
Cricket Api Solution.pdfCricket Api Solution.pdfLatiyalinfotech
 
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docx
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docxSlovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docx
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docxWorld Wide Tickets And Hospitality
 
European Football Icons that Missed Opportunities at UEFA Euro 2024.docx
European Football Icons that Missed Opportunities at UEFA Euro 2024.docxEuropean Football Icons that Missed Opportunities at UEFA Euro 2024.docx
European Football Icons that Missed Opportunities at UEFA Euro 2024.docxEuro Cup 2024 Tickets
 
UEFA Euro 2024 Squad Check-in Which team is Top favorite.docx
UEFA Euro 2024 Squad Check-in Which team is Top favorite.docxUEFA Euro 2024 Squad Check-in Which team is Top favorite.docx
UEFA Euro 2024 Squad Check-in Which team is Top favorite.docxEuro Cup 2024 Tickets
 
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdfJORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdfArturo Pacheco Alvarez
 
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics TradeTechnical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics TradeOptics-Trade
 
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...Eticketing.co
 
Spain Vs Italy Spain to be banned from participating in Euro 2024.docx
Spain Vs Italy Spain to be banned from participating in Euro 2024.docxSpain Vs Italy Spain to be banned from participating in Euro 2024.docx
Spain Vs Italy Spain to be banned from participating in Euro 2024.docxWorld Wide Tickets And Hospitality
 
Italy vs Albania Italy Euro 2024 squad Luciano Spalletti's full team ahead of...
Italy vs Albania Italy Euro 2024 squad Luciano Spalletti's full team ahead of...Italy vs Albania Italy Euro 2024 squad Luciano Spalletti's full team ahead of...
Italy vs Albania Italy Euro 2024 squad Luciano Spalletti's full team ahead of...Eticketing.co
 
Albania Vs Spain South American coaches lead Albania to Euro 2024 spot.docx
Albania Vs Spain South American coaches lead Albania to Euro 2024 spot.docxAlbania Vs Spain South American coaches lead Albania to Euro 2024 spot.docx
Albania Vs Spain South American coaches lead Albania to Euro 2024 spot.docxWorld Wide Tickets And Hospitality
 
JORNADA 5 LIGA MURO 2024INSUGURACION.pdf
JORNADA 5 LIGA MURO 2024INSUGURACION.pdfJORNADA 5 LIGA MURO 2024INSUGURACION.pdf
JORNADA 5 LIGA MURO 2024INSUGURACION.pdfArturo Pacheco Alvarez
 
Hire 💕 8617697112 Kasauli Call Girls Service Call Girls Agency
Hire 💕 8617697112 Kasauli Call Girls Service Call Girls AgencyHire 💕 8617697112 Kasauli Call Girls Service Call Girls Agency
Hire 💕 8617697112 Kasauli Call Girls Service Call Girls AgencyNitya salvi
 
Unveiling the Mystery of Main Bazar Chart
Unveiling the Mystery of Main Bazar ChartUnveiling the Mystery of Main Bazar Chart
Unveiling the Mystery of Main Bazar ChartChart Kalyan
 
2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)Delhi Call girls
 
Muzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Muzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMuzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Muzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docx
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docxNetherlands Players expected to miss UEFA Euro 2024 due to injury.docx
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docxEuro Cup 2024 Tickets
 

Kürzlich hochgeladen (20)

Sports Writing (Rules,Tips, Examples, etc)
Sports Writing (Rules,Tips, Examples, etc)Sports Writing (Rules,Tips, Examples, etc)
Sports Writing (Rules,Tips, Examples, etc)
 
Sector 62, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 62, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Model Escorts | 100% verified
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Who Is Emmanuel Katto Uganda? His Career, personal life etc.
Who Is Emmanuel Katto Uganda? His Career, personal life etc.Who Is Emmanuel Katto Uganda? His Career, personal life etc.
Who Is Emmanuel Katto Uganda? His Career, personal life etc.
 
Cricket Api Solution.pdfCricket Api Solution.pdf
Cricket Api Solution.pdfCricket Api Solution.pdfCricket Api Solution.pdfCricket Api Solution.pdf
Cricket Api Solution.pdfCricket Api Solution.pdf
 
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docx
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docxSlovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docx
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docx
 
European Football Icons that Missed Opportunities at UEFA Euro 2024.docx
European Football Icons that Missed Opportunities at UEFA Euro 2024.docxEuropean Football Icons that Missed Opportunities at UEFA Euro 2024.docx
European Football Icons that Missed Opportunities at UEFA Euro 2024.docx
 
UEFA Euro 2024 Squad Check-in Which team is Top favorite.docx
UEFA Euro 2024 Squad Check-in Which team is Top favorite.docxUEFA Euro 2024 Squad Check-in Which team is Top favorite.docx
UEFA Euro 2024 Squad Check-in Which team is Top favorite.docx
 
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdfJORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
 
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics TradeTechnical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
 
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...
 
Spain Vs Italy Spain to be banned from participating in Euro 2024.docx
Spain Vs Italy Spain to be banned from participating in Euro 2024.docxSpain Vs Italy Spain to be banned from participating in Euro 2024.docx
Spain Vs Italy Spain to be banned from participating in Euro 2024.docx
 
Italy vs Albania Italy Euro 2024 squad Luciano Spalletti's full team ahead of...
Italy vs Albania Italy Euro 2024 squad Luciano Spalletti's full team ahead of...Italy vs Albania Italy Euro 2024 squad Luciano Spalletti's full team ahead of...
Italy vs Albania Italy Euro 2024 squad Luciano Spalletti's full team ahead of...
 
Albania Vs Spain South American coaches lead Albania to Euro 2024 spot.docx
Albania Vs Spain South American coaches lead Albania to Euro 2024 spot.docxAlbania Vs Spain South American coaches lead Albania to Euro 2024 spot.docx
Albania Vs Spain South American coaches lead Albania to Euro 2024 spot.docx
 
JORNADA 5 LIGA MURO 2024INSUGURACION.pdf
JORNADA 5 LIGA MURO 2024INSUGURACION.pdfJORNADA 5 LIGA MURO 2024INSUGURACION.pdf
JORNADA 5 LIGA MURO 2024INSUGURACION.pdf
 
Hire 💕 8617697112 Kasauli Call Girls Service Call Girls Agency
Hire 💕 8617697112 Kasauli Call Girls Service Call Girls AgencyHire 💕 8617697112 Kasauli Call Girls Service Call Girls Agency
Hire 💕 8617697112 Kasauli Call Girls Service Call Girls Agency
 
Unveiling the Mystery of Main Bazar Chart
Unveiling the Mystery of Main Bazar ChartUnveiling the Mystery of Main Bazar Chart
Unveiling the Mystery of Main Bazar Chart
 
2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Sheikh Sarai (Delhi)
 
Muzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Muzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMuzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Muzaffarpur Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docx
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docxNetherlands Players expected to miss UEFA Euro 2024 due to injury.docx
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docx
 

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/