SDL Programming Introduction. Initialization 2  The first thing you must do is initialize SDL  int SDL_Init( SDL_INIT_EVERYTHING )  This will return.

Slides:



Advertisements
Similar presentations
Games in Python – the easy way
Advertisements

Working with Tables for Page Design – Lesson 41 Working with Tables for Page Design Lesson 4.
Chapter 3 Creating a Business Letter with a Letterhead and Table
The GIMP Simple features tutorial By Mary A White.
How to PRODUCE an newsletter in HTML using Visual Outcomes and then DISTRIBUTE it PURPOSE - to create a newsletter or message to to all practice.
© by Pearson Education, Inc. All Rights Reserved. continued …
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Reporting Aesthetics An ACEware Webinar 1:00-2:00 pm February 14 th, 2008.
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
2 What is pyGame? A set of Python modules to make it easier to write games. –home page: –documentation:
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 3 Working with Symbols and Interactivity.
Microsoft Word 2010 Chapter 1 Creating, Formatting, and Editing a Word Document with Pictures.
Microsoft Office 2007 Word Chapter 1 Creating and Editing a Word Document.
Lecture 02: Intro to SDL Topics: Downloading / Installing SDL Linking (in general and for SDL) SDL basics References:
IE 411/511: Visual Programming for Industrial Applications
© 2011 Delmar, Cengage Learning Chapter 3 Working with Symbols and Interactivity.
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
Working with Symbols and Interactivity
Visual Basic .NET BASICS
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Chapter 3 Creating a Business Letter with a Letterhead and Table
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
© 2010 Delmar, Cengage Learning Chapter 3: Working with Symbols and Interactivity.
Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
BIL528 – Bilgisayar Programlama II Introduction 1.
XP New Perspectives on Windows 2000 Professional Windows 2000 Tutorial 2 1 Microsoft Windows 2000 Professional Tutorial 2 – Working With Files.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
MAEK GAEM III: SDL ● Simple DirectMedia Layer ● Input/Graphics/Audio using OpenGL ● Not nearly as difficult as OpenGL ● Cross Platform and Open Sauce ●
Chapter 2 – Introduction to the Visual Studio .NET IDE
Game Maker – Getting Started What is Game Maker?.
Build-A-Button Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, October 8, 2003.
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
Making Billboards By Deborah Nelson Duke University, Under the direction of Professor Susan Rodger, July 14, 2008.
Macromedia Flash 8 Revealed WORKING WITH SYMBOLS AND INTERACTIVITY.
CHAPTER 3 (P.49-53) Importing modules + pygame intro.
Presented By: Weidong WU, Ph.D. Date: Part I Creating a drawing format for the paper size A (11 x 8.5) 1. Start Pro/E wildfire. 2. File  set.
Lesson: 2 Common Features and Commands After completing this lesson, you will be able to: Identify the main components of the user interface. Identify.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 4 Designing the Inventory Application Introducing TextBox es and Button s.
Introducing Dreamweaver. Dreamweaver The web development application used to create web pages Part of the Adobe creative suite.
GAM666 – Introduction To Game Programming ● DirectDraw, the 2D component of DirectX, uses the term “surface” to mean an area of memory in which pixel data.
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
MS WORD INFORMATION TECHNOLOGY MANAGEMENT SERVICE Training & Research Division.
Excel Chapter 1 Creating a Worksheet and an Embedded Chart
3. Drawing Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
 You won’t write a single line of program code.  Instead, you’ll use visual programming techniques.  Visual Studio processes your actions (such as mouse.
Variables. Something to mention… void setup(){ size(200, 200); background(255); smooth(); } void draw() { stroke(0); strokeWeight(abs(mouseX-pmouseX));
2D Graphics CMT3311. This covers... How to make a transparent sprite How to add a sprite to your project and draw it Properties of sprites and how to.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
●Cross-platform multimedia devlopment library for games (thats what we talk about), demos, MPEG players.... anything multimedia you can think of. ●SDL.
MOM! Phineas and Ferb are … Aims:
Scratch for Interactivity
PYGAME.
9. Drawing.
Chapter 2 – Introduction to the Visual Studio .NET IDE
9. Drawing Let's Learn Python and Pygame
Chapter 7 Advanced Form Techniques
Importing modules + pygame intro
Working with Symbols and Interactivity
Presentation transcript:

SDL Programming Introduction

Initialization 2  The first thing you must do is initialize SDL  int SDL_Init( SDL_INIT_EVERYTHING )  This will return -1 if it fails  Various flags can be OR’ed together to enable various features  In this case, we enable all features

Surfaces 3  A surface is an area where you can draw  The screen is one such surface  You can create other surfaces to hold images or to draw on  You can copy one surface to another  Surfaces have properties  Height  Width  Number of bits per pixel

Creating the Screen 4  After initializing SDL, you create the screen  SDL_Surface *screen;  screen = SDL_SetVideoMode( winWidth, winHeight, screenDepth, SDL_HWSURFACE | SDL_DOUBLEBUF);  The screen depth is usually 32  If the screen cannot be created, NULL will be returned  When a surface is no longer needed it should be freed  SDL_FreeSurface(surface);

Setting a Window Title 5  You can set the title in the top of the window  SDL_WM_SetCaption( “Title", NULL );  The title will be displayed in the window decoration area, usually at the top of the window

SDL Coordinates 6 (0, 0) (100, 0) (0, 100)(100, 100) The origin of a window is the top-left corner Y coordinates increase as we go down The origin of a window is the top-left corner Y coordinates increase as we go down

Loading Images 7  SDL can load images in the BMP format  There are extensions which can load other formats  These extensions must be downloaded and installed into your SDL directories  Loaded images are stored on surfaces  Remember, the screen itself is a surface  You can then copy them from one surface to another to make them appear on the screen

Loading Images 8  To load an image  SDL_Surface *image = SDL_LoadBMP(“file.bmp”);  This will either load the image or return NULL if it cannot be loaded  The trouble is that the image might not have the same format as the screen you want to display it on  You can convert it to the correct format as follows  SDL_Surface *displayImage = SDL_DisplayFormat(image);

Loading Images 9  These steps are done often enough to warrant creating a function or method for loading an image SDL_Surface* loadImage(const char* fileName) { SDL_Surface *tmp = NULL, *image = NULL; tmp = SDL_LoadBMP(fileName); if(tmp) { image = SDL_DisplayFormat(tmp); SDL_FreeSurface(tmp); } return image; }

Rendering Images 10  When you load an image  It is stored on a surface  This does not make the image visible  The image must be copied to the screen to be visible  We move an image using bit blitting  Bit block image transfer  This is done with the function SDL_BlitSurface

SDL_BlitSurface 11  int SDL_BlitSurface( SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)  Src – source surface  Srcrect – rectangle delimiting areas to copy or NULL for entire image  Dst – the destination surface  Dstrect – position to place on destination surface. If NULL image will be placed at top-left corner  Returns 0 on success

SDL_Rect 12  This is a common structure used to indicate the size and position of rectangular areas typedef struct{ Sint16 x, y; Uint16 w, h; } SDL_Rect;

Event Handling 13  Many events happen while a program is running  Key presses  Mouse movement  Window resizing  Window closing  Games are interested in these events and need to be able to find out when they occur  This can be done using  SDL_PollEvent(& event)

SDL_Event 14 typedef union{ Uint8 type; SDL_ActiveEvent active; SDL_KeyboardEvent key; SDL_MouseMotionEvent motion; SDL_MouseButtonEvent button; SDL_JoyAxisEvent jaxis; SDL_JoyBallEvent jball; SDL_JoyHatEvent jhat; SDL_JoyButtonEvent jbutton; SDL_ResizeEvent resize; SDL_ExposeEvent expose; SDL_QuitEvent quit; SDL_UserEvent user; SDL_SysWMEvent syswm; } SDL_Event; This is used for all event types Note that it is a union The type field indicates which member of the union is to be used This is used for all event types Note that it is a union The type field indicates which member of the union is to be used

SDL Event Types & Structures 15 Event typeEvent Structure SDL_ACTIVEEVENTSDL_ActiveEvent SDL_KEYDOWN/UPSDL_KeyboardEvent SDL_MOUSEMOTIONSDL_MouseMotionEvent SDL_MOUSEBUTTONDOWN/UPSDL_MouseButtonEvent SDL_JOYAXISMOTIONSDL_JoyAxisEvent SDL_JOYBALLMOTIONSDL_JoyBallEvent SDL_JOYHATMOTIONSDL_JoyHatEvent SDL_JOYBUTTONDOWN/UPSDL_JoyButtonEvent SDL_VIDEORESIZESDL_ResizeEvent SDL_VIDEOEXPOSESDL_ExposeEvent SDL_QUITSDL_QuitEvent SDL_USEREVENTSDL_UserEvent SDL_SYSWMEVENTSDL_SysWMEvent

SDL_KeyboardEvent 16 typedef struct{ Uint8 type; Uint8 state; SDL_keysym keysym; } SDL_KeyboardEvent; typedef struct{ Uint8 type; Uint8 state; SDL_keysym keysym; } SDL_KeyboardEvent; FieldValuesDescription typeSDL_KEYDOWN SDL_KEYUP Type of key event StateSDL_KEYPRESSED SDL_KEYRELEASED Same as type keysymStructureThe key pressed

SDL_keysym 17 typedef struct{ Uint8 scancode; SDLKey sym; SDLMod mod; Uint16 unicode; } SDL_keysym; FieldValuesDescription scancodeHardware scan code symSee tableSDL virtual key code modKey modifiers unicodeTranslated character

SDL Key Symbols 18 SDL keyASCIIName SDLK_BACKSPACE'\b'backspace SDLK_TAB'\t'tab SDLK_CLEARclear SDLK_RETURN'\r'return SDLK_PAUSEpause SDLK_ESCAPE'^['escape SDLK_SPACE' space SDLK_EXCLAIM'!'exclamation SDLK_QUOTEDBL'"' double quote SDLK_HASH'#'hash SDLK_DOLLAR'$'dollar SDLK_AMPERSAND'&'ampersand

SDL Key Symbols 19 SDL keyASCIIName SDLK_QUOTE'\''single quote SDLK_LEFTPAREN'('left parenthesis SDLK_RIGHTPARE N ')'right parenthesis SDLK_ASTERISK'*'asterisk SDLK_PLUS'+'plus sign SDLK_COMMA','comma SDLK_MINUS'-'minus sign SDLK_PERIOD'.'period / full stop SDLK_SLASH'/'forward slash SDLK_COLON':'colon SDLK_SEMICOLON';'semicolon SDLK_LESS'<'less-than sign

SDL Key Symbols 20 SDL keyASCI I Name SDLK_EQUALS'='equals sign SDLK_GREATER'>'greater-than sign SDLK_QUESTION'?'question mark SDLK_LEFTBRACKET'['left bracket SDLK_BACKSLASH'\\'backslash SDLK_RIGHTBRACKE T ']'right bracket SDLK_CARET'^'caret SDLK_UNDERSCORE'_'underscore SDLK_DELETE'^?'delete SDLK_UPup arrow SDLK_DOWNdown arrow

SDL Key Symbols 21 SDL keyASCIIName SDLK_RIGHTright arrow SDLK_LEFTleft arrow SDLK_INSERTinsert SDLK_HOMEhome SDLK_ENDend SDLK_PAGEUPpage up SDLK_PAGEDOWNpage down SDLK_F1...F1 SDLK_F15F15 SDLK_PRINTprint-screen SDLK_SYSREQSysRq SDLK_BREAKbreak

SDL Key Symbols 22 SDL keyASCIIName SDLK_0'0'0 SDLK_1'1'1 SDLK_2'2'2 SDLK_3'3'3 SDLK_4'4'4 SDLK_5'5'5 SDLK_6'6'6 SDLK_7'7'7 SDLK_8'8'8 SDLK_9'9'9

SDL Key Symbols 23 SDL keyASCII SDLK_a'a' SDLK_b'b' SDLK_c'c' SDLK_d'd' SDLK_e'e' SDLK_f'f' SDLK_g'g' SDLK_h'h' SDLK_i'i' SDLK_j'j' SDLK_k'k' SDLK_l'l' SDLK_m'm' SDL keyASCII SDLK_n'n' SDLK_o'o' SDLK_p'p' SDLK_q'q' SDLK_r'r' SDLK_s's' SDLK_t't' SDLK_u'u' SDLK_v'v' SDLK_w'w' SDLK_x'x' SDLK_y'y' SDLK_z'z'

Event Processing Loop 24 while(SDL_PollEvent(&event)){ switch(event.type){ case SDL_KEYDOWN: if(event.key.keysym.sym==SDLK_LEFT) move_left(); break;... } } Poll for events and process each of the events

The Game Loop 25 bool quit = false; SDL_Event event; while( quit == false ) { if( SDL_PollEvent( &event ) ) { if( event.type == SDL_QUIT ) { quit = true; } if( SDL_Flip( screen ) == -1 ) { //return 1; } bool quit = false; SDL_Event event; while( quit == false ) { if( SDL_PollEvent( &event ) ) { if( event.type == SDL_QUIT ) { quit = true; } if( SDL_Flip( screen ) == -1 ) { //return 1; } This processes events and keeps the window on the screen until the X in the top right of the window is clicked.

Drawing Text 26  SDL does not support TTF fonts as distributed  You can download the extension from   Get the file  SDL_ttf-devel VC.zip SDL_ttf-devel VC.zip  Open the zip file and  Copy the file in include to the include directory for your SDL  Copy the files in lib to the lib directory for your SDL  You will need to copy the new DLLs to any project that wants to use text

Preparing to Use Text 27  Set the text color SDL_Color textColor; textColor.r = textColor.g = textColor.b = 255;  Initialize the TTF extension if( TTF_Init() == -1 ) { return false; }  Load the font if( NULL == (font = TTF_OpenFont( "lazy.ttf", 28 )) ) { return false; }

Rendering the Text 28  text is rendered to a newly created surface  You then copy this surface onto the surface where the text should appear textSurface = TTF_RenderText_Solid( font, "A-Maze-ing", textColor );  This surface is then blitted onto the destination surface

Colors 29  Colors are specified as  RGB with each value from 0 – 255  There are two different structures  An unsigned 32 bit int  An SDL_Color structure  SDL_Color has members  r, g, b  To create the 32 bit int unsigned int color = SD_MapRGB(screen->format, 255, 255, 255);

Drawing Lines & Rectangles 30 int SDL_DrawLine(SDL_Surface* dst, int x1, int y1, int x2, int y2, Uint32 color) int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)  Both functions return 0 on success