Game Programming Algorithms and Techniques

Slides:



Advertisements
Similar presentations
2D Platform Games: Tiles & Scrolling
Advertisements

Hidden Surface Removal Why make the effort?  Realistic models.  Wasted time drawing. OpenGL and HSR  OpenGL does handle HSR using the depth buffer.
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
3.1. G RAPHICS I The use of images within games. Reflections and advice on the games proposed in the Week 2 Hand-in.
Output Primitives Computer Graphics.
Display of Objects on Screen. COUNTERS b A horizontal counter represents the horizontal position of the monitor’s electron beam. b A vertical counter.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphicsIntroduction Dr. Eng. Farag Elnagahy
Ch 1 Intro to Graphics page 1CS 367 First Day Agenda Best course you have ever had (survey) Info Cards Name, , Nickname C / C++ experience, EOS experience.
Introduction to Computer Graphics
Perspective, Scene Design, and Basic Animation
IE433 CAD/CAM Computer Aided Design and Computer Aided Manufacturing Part-2 CAD Systems Industrial Engineering Department King Saud University.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 19 Other Graphics Considerations Review.
Polygon Scan Conversion and Z-Buffering
COMP Bitmapped and Vector Graphics Pages Using Qwizdom.
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
Lecture No. 3.  Screen resolution  Color  Blank space between the pixels  Intentional image degradation  Brightness  Contrast  Refresh rate  Sensitivity.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 14 Introduction to Computer Graphics.
Objectives Differentiate between raster scan display and random scan display.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
 PLASMA DISPLAY MONITOR  RASTOR VS RANDOM SCAN  INTERLACING AND NON- INTERLACING.
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.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 2 Graphics Programming with C++ and the Dark GDK Library Starting.
Introduction to Graphical Hardware Display Technologies
Game Maker Terminology
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
PowerPoint Basics Tutorial 3: Graphics In this tutorial we’ll be looking at graphics, and the various types of illustrations that can be included in a.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
 Objective Objective  Basic Techniques Basic Techniques - Beam Penetration methodBeam Penetration method - The Shadow - Mask method.The Shadow - Mask.
Beam Penetration & Shadow Mask Method
Lesson 3: Arrays and Loops. Arrays Arrays are like collections of variables Picture mailboxes all lined up in a row, or storage holes in a shelf – You.
Computer Graphics & Multimedia
1 Perception and VR MONT 104S, Fall 2008 Lecture 20 Computer Graphics and VR.
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
Lecture 11 Text mode video
Computer Graphics CC416 Lecture 02: Overview of Graphics Systems: Raster & Random Displays – Chapter 2 Dr. Manal Helal – Fall 2014.
DISPLAY DEVICES CIS 10, Group #1 April 01, 2006 C. X. A. L. K. H. A. V. ((( L. C.
Image and Sound Representation
Computer Graphics: An Introduction
CSS Layouts CH 13.
David Meredith Aalborg University
Computer Graphics Lecture 3 Computer Graphics Hardware
Discrete Techniques.
Computer Graphics Raster Devices Transformations
Pixel, Resolution, Image Size
Flash Interface, Commands and Functions
CS 134 More Graphics.
Frame Update, Level Representation & Graphics
Basic Rendering Techniques
An Introduction to Spritesheet Animation
IMAGES.
Perspective, Scene Design, and Basic Animation
Chapter I Digital Imaging Fundamentals
Basic Rendering Techniques
Microprocessor and Assembly Language
Chapter 5 Working with Images
Introduction to Computer Graphics
Animation Scrolling Screens.
Data Representation.
Representing Images 2.6 – Data Representation.
Chapter 2 Graphics Programming with C++ and the Dark GDK Library
Lecture 13 Clipping & Scan Conversion
Graphics Systems SUBJECT: COMPUTER GRAPHICS LECTURE NO: 02 BATCH: 16BS(INFORMATION TECHNOLOGY) 1/4/
Lesson 7: Video, Audio and Image Techniques
Graphics Systems Lecture-2
Chapter 2 Overview of Graphics Systems
VISUAL COMMUNICATION USING ADOBE PHOTOSHOP CREATIVE SUITE 5
Lecture 4 - Introduction to Computer Graphics
GPAT – Chapter 2, 4, and 8 Graphics and Cameras
Chapter 7 The Game Loop and Animation
Presentation transcript:

Game Programming Algorithms and Techniques Chapter 2 2D Graphics

Chapter 2 Objectives 2D Rendering Foundations Learn the basics how monitors work Cover color buffers, vertical sync, and screen tearing Sprites Learn about both basic and animated sprites Learn how sprite sheets can save space Scrolling Single-axis and infinite scrolling Using the parallax effect to give an illusion of depth Implementing four-direction scrolling Tile Maps Learn how to use basic tile maps Using isometric tile maps

CRT Monitor Basics CRTs contain an array of picture elements known as pixels: For color displays, each pixel contains a red, green, and blue sub-pixel. Resolution determines the total number of pixels: 300x200 means each row or scan line has 300 pixels and there's a total of 200 rows. CRTs use an electron gun to activate the various pixels.

CRT Monitor Basics, Cont'd Electron gun draws one scan line at a time. When it gets to bottom-right corner, it takes some time to get the aim back to top left (vertical blank interval or VBLANK). Basic CRT drawing

Screen tearing caused by updating video data while the CRT is drawing Color Buffer A buffer is memory that stores the color data for all the pixels on the screen. With only a single color buffer, writing to it outside of VBLANK will result in screen tearing. Screen tearing caused by updating video data while the CRT is drawing

Double Buffering Use two color buffers: While buffer A is written to, display buffer B. Then next frame, write to B and display A. As long as the swap occurs during VBLANK, there is no screen tearing: This corresponds to the VSYNC setting in many games. Triple buffering is when there are three color buffers.

Sprites 2D visual objects used to represent: Characters Other dynamic objects For simple games, backgrounds The corresponding image format can vary depending on the platform (PNG, TGA, and PVR are all potential options).

Basic Sprite Object class Sprite ImageFile image int drawOrder int x, y function Draw() // Draw the image at the correct (x,y) ... end

Painter’s algorithm applied to a 2D space scene Sprites are drawn from back to front. Painter’s algorithm applied to a 2D space scene

Animating Sprites Like flipbook animations. Animation FPS can vary (24 is a common rate). Animated run cycle

AnimatedSprite Implementation AnimFrameData struct stores: Starting frame of animation Total number of frames of animation AnimData struct stores: Array of images used for all the frames Array of AnimFrameData

AnimatedSprite Members class AnimatedSprite inherits Sprite // All of the animation data (includes ImageFiles and FrameData) AnimData animData // The particular animation that is active int animNum // The frame number of the active animation that's being displayed int frameNum // Amount of time the current frame has been displayed float frameTime // The FPS the animation is running at (24FPS by default). float animFPS = 24.0f function Initialize(AnimData myData, int startingAnimNum) function UpdateAnim(float deltaTime) function ChangeAnim(int num) end

Updating the Animation If animation FPS is higher than game FPS, we may need to skip frames in the animation, so: frameNum += frameTime * animFPS If frameNum > the number of frames: Use modulus to figure out new frame number. Similarly, use fmod to determine what amount to reset frameTime.

Sprite Sheets Rather than separate image files per sprite, pack them all into a single image file. Can greatly reduce empty space, thus reducing size. Individual sprites (a), and those sprites packed in a sprite sheet (b)

Single-Axis Scrolling Game scrolls in a single direction, like Jetpack Joyride. Single-direction scrolling in Jetpack Joyride. The dotted line demonstrates a boundary.

Single-Axis Scrolling, Cont'd Easiest with screen-sized background sprites. Create a list of background sprites with their x-positions set as appropriate. While scrolling, change the camera position based on the player's position: camera.x = clamp(player.x, screenWidth / 2, hCount * screenWidth – screenWidth / 2)

Single-Axis Scrolling, Cont'd Once the appropriate background image is determined, offset the position based on the camera: draw s at (s.x – camera.x + screenWidth/2, 0) Then draw the subsequent image, in case it, too, is visible.

Infinite Scrolling When the game continues to scroll until the player loses. There can't be an infinite number of background segments, so segments must be repeated. Increasing the unique images increases variety, as does randomizing sequences of images.

Space scene broken into three layers to facilitate parallax scrolling Separate the background into layers, and then scroll them at different speeds. This gives the illusion of depth. Space scene broken into three layers to facilitate parallax scrolling

Scene broken up into four segments to support four-way scrolling When the game world scrolls horizontally and vertically. Code is similar to single-axis, just in two directions. Scene broken up into four segments to support four-way scrolling

Tile Maps Partition world into squares (or other polygon). Size of a tile is game-specific. Each square references a particular image in the tile set. Scene from the classic platformer Jazz Jackrabbit 2, which uses tile maps for its levels

Basic Level Format Represent each tile onscreen with a number specifying the index into the tile set: 0,0,1,0,0 0,1,1,1,0 1,1,2,1,1

Sample isometric scene Isometric Tile Map Can create a greater sense of depth. Used in games like Diablo II. Tiles are usually parallelograms or hexagons. Sample isometric scene © denis_pc/fotolia