Tennis for Two, 1958, by William Higinbotham, Brookhaven National Lab CSE 380 – Computer Game Programming Graphics Device Management.

Slides:



Advertisements
Similar presentations
2000 Prentice Hall, Inc. All rights reserved. 1 Outline 3.1Introduction 3.2Game Loop Components 3.3How to Implement in C# 3.4Adding Image to XNA Project.
Advertisements

CSE 380 – Computer Game Programming Tile Based Graphics Legend of Zelda, by Nintendo, released 1987.
Using 2D sprite with OpenGL 2003 team Koguyue. Overview Motivation and basic concepts Advantages with using OpenGL Basic requirements of implementation.
Images Images are a key component of any multimedia presentation.
Lecture 2 Concepts, Terms and Definitions. Display Devices They are divided into a lot of small squares called pixels (“PICture ELements”). Each pixel.
Lesson 15 Presentation Programs.
Creating Games For Windows, Xbox 360, and Windows Phone 7 Ryan Plemons
Status – Week 257 Victor Moya. Summary GPU interface. GPU interface. GPU state. GPU state. API/Driver State. API/Driver State. Driver/CPU Proxy. Driver/CPU.
Video Game Design Lesson 1. Game Designer Person involved in the development of a video game Person involved in the development of a video game Usually.
GAM666 – Introduction To Game Programming ● As of DirectX 8, DirectDraw (2D) and Direct3D (3D) have been combined into DirectX Graphics (still often called.
AUTOMATIC ORGANIZING AND FORMATTING FOR LECTURE NOTES SHIQING (LICIA) HE ADIVISOR: PROF.KRISTINA STRIEGNITZ SPRING 2014 STRUCTURING THE UNSTRUCTURED NOTE:
Una DooneyMultimediaSlide 1 What is Multimedia? A combination of different media types such as text, graphics, audio, video and animation etc in a single.
Game Design and Programming. Objectives Classify the games How games are design How games are implemented What are the main components of a game engine.
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.
Video for Mobile Device Mark Green School of Creative Media.
Introduction to Computer Graphics
 A complete presentation graphics program that allows you to produce professional looking presentations.  A presentation is also referred to as a slide.
AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.
TERMS TO KNOW. Programming Language A vocabulary and set of grammatical rules for instructing a computer to perform specific tasks. Each language has.
Unit 30 P1 – Hardware & Software Required For Use In Digital Graphics
CS 1308 Computer Literacy and the Internet. Creating Digital Pictures  A traditional photograph is an analog representation of an image.  Digitizing.
MULTIMEDIA M U A T H H U M A I D R a s h A t a l l a h.
Basics of a Computer Graphics System Introduction to Computer Graphics CSE 470/598 Arizona State University Dianne Hansford.
Unit 1 – Improving Productivity Instructions ~ 100 words per box.
CHAPTER 4 Images XNA Game Studio 4.0. Objectives Find out how the Content Manager lets you add pictures to Microsoft XNA games. Discover how pictures.
CHAPTER 4 Window Creation and Control © 2008 Cengage Learning EMEA.
Practical PC, 7th Edition Chapter 17: Looking Under the Hood
Module Code: CU0001NI Technical Information on Digital Images Week -2.
CSE 381 – Advanced Game Programming Basic 3D Graphics
Objective Understand concepts used to create digital graphics. Course Weight : 15% Part Three : Concepts of Digital Graphics.
11 A First Game Program Session Session Overview  Begin the creation of an arcade game  Learn software design techniques that apply to any form.
Getting Started. XNA Game Studio 4.0 To download XNA Game Studio 4.0 itself, go to XNA Game.
VIDEO GAME PROGRAMMING Video Game Programming Level One – Breakout INSTRUCTOR Big Dan Teague TEACHER’S ASSISTANT Delmar O'Donnell.
1 ETC. 2 Sounds FX Sounds FX –WAV audio files –Load into memory and play it »Load »Play »Stop »Pause –2D or 3D »3D should be integrated into scene management.
Today’s lecture 2-Dimensional indexing Color Format Thread Synchronization within for- loops Shared Memory Tiling Review example programs Using Printf.
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
 A complete presentation graphics program that allows you to produce professional looking presentations.
By Courtney Field Creative digital graphics. Types of graphics and examples There are a number of different types of graphics file formats. Each type.
3D Programming and DirectX API. Content Mathematics Mathematics Prepare to Write a 3D program Prepare to Write a 3D program Program Structure Program.
High Performance Java Swing Animation David Wallace Croft Presented to the Plano Java Users Group Plano, TX Copyright 2004 David Wallace Croft.
Introduction to Multimedia Review 1 - Lecture Notes Semester 1.
“The perfect project plan is possible if one first documents a list of all the unknowns.” Bill Langley.
CSE 380 – Computer Game Programming GUIs for Games.
Georgia Institute of Technology Movies Barb Ericson Georgia Institute of Technology April 2006.
Why program retro machines? Aren't they obsolete? Why not do something more constructive?
1 Contents  Audio  Sprite  Input devices  Game production milestones  Course summary.
CSE 380 – Computer Game Programming Tile Based Graphics & Scrolling Legend of Zelda, by Nintendo, released 1987.
CSCI-100 Introduction to Computing Hardware Part II.
Overview of Graphics System
GAM666 – Introduction To Game Programming ● Programmer's perspective of Game Industry ● Introduction to Windows Programming ● 2D animation using DirectX.
Introduction to Game Programming Pertemuan 11 Matakuliah: T0944-Game Design and Programming Tahun: 2010.
XNA Tutorial 1 For CS134 Lecture. Overview Some of the hard work has already been done for you. If you build and run your game now, the GraphicsDeviceManager.
Computer Science I Animations. Bouncing ball. The if statement. Classwork/homework: bouncing something. Compress and upload work to Moodle.
PyGame - Unit 2 PyGame Unit – – Animation.
Efficient Game Graphics From Flash MX 2004 Game Design Demystified.
Reference: What is it? A multimedia python library – Window Management – Graphics geometric shapes bitmaps (sprites) – Input Mouse Keyboard.
From VIC (VRVS) to ViEVO (EVO) 3 years of experiences with developing of video application VIC for VRVS allowed us to develop a new video application.
2D Graphics Optimizations
What is DirectX? DirectX is built by Microsoft as a collection of API’s (Application Programming Interfaces) for the purpose of multimedia processing.
Microsoft PowerPoint This is the introduction to PowerPoint.
Textures, Sprites, and Fonts
Frame Update, Level Representation & Graphics
Unit 3, Lesson 8 Making Presentations That Get Attention
Build /24/2018 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
A lap around DirectX game development tools
Introduction to Computers
AN INTRODUCTION TO COMPUTER GRAPHICS Subject: Computer Graphics Lecture No: 01 Batch: 16BS(Information Technology)
HW for Computer Graphics
Presentation transcript:

Tennis for Two, 1958, by William Higinbotham, Brookhaven National Lab CSE 380 – Computer Game Programming Graphics Device Management

What is a 2D game graphically speaking? Basically 2 things: –Texture rendering (images) –Text rendering Rendering textures & text is easy Efficiently managing the data of the game is not

DirectX Windows API for making games Microsoft says “The power of multimedia in Windows, DirectX gives you the best possible experience with graphics, sound, music, and 3-D animation.” API in MSDN: –

DirectX Architecture Windows Win32 Application Direct3DXAudio… Hardware: Audio, Video, Input, Storage … HEL: Hardware Emulation Layer HAL: Hardware Abstraction Layer Software emulation

DirectX Devices Represent hardware Direct3D device is the graphics processor Graphics cards can render fast So, we call DirectX methods –they are implemented on the GPU What if you don’t have a GPU? –you can’t play

Challenge to PC game programmers Every gamer has a different machine Different graphics cards, which means: –different available screen resolutions –different available color models You want to reach a broad audience What’s the end result? –a headache –a lot of code devoted to dealing with these differences

What’s a color model? A format for storing color on the graphics card Many different formats Ex: –32 ARGB 8 bits for Alpha 8 bits for Red 8 bits for Green 8 bits for Blue

What does a GPU have? A grid of pixels –match the current screen resolution –when we force to screen it ends up on monitor Memory for additional visual data –ex: textures Implementations of efficient graphics processing algorithms

Strategy for creating graphics devices Pick a common resolution, ex: 1024 X 768 Pick a common color model, ex: 32 XRGB When the application starts: –check to make sure the player’s graphics card has these capabilities –What if the player doesn’t have our desired format? have backup choices tell the player to come back when they have a better computer

Creating a D3D Graphics Device 1.Make a Direct3D object (LPDIRECT3D9) 2.Get all the available GPU display modes (D3DDISPLAYMODE) 3.Pick one and use it to fill in the setup parameters (D3DPRESENT_PARAMETERS) 4.Use parameters to create a graphics device (LPDIRECT3DDEVICE9) 5.Use the graphics device to make a sprite handler (LPD3DXSPRITE) –More on using this in a minute

Setup Direct3D Methods CreateDevice Direct3DCreate9 EnumAdapterModes GetAdapterModeCount … These can tell us about the capabilities of the GPU

Making a Direct3D Object Let’s us make other stuff LPDIRECT3D9 d3d; … d3d = Direct3DCreate9(D3D_SDK_VERSION); How about getting the available modes? –each color mode is numbered –lets look for all modes in range (way overkill)

vector *displayOptions = new vector (); int adapterCounter = 1; D3DFORMAT format; while (adapterCounter < 1000) { format = D3DFORMAT(adapterCounter); int numAdapters = d3d->GetAdapterModeCount( D3DADAPTER_DEFAULT, format); D3DDISPLAYMODE *displayModes = new D3DDISPLAYMODE[numAdapters]; for (int i = 0; i < numAdapters; i++) { d3d->EnumAdapterModes(D3DADAPTER_DEFAULT, format, i, &displayModes[i]); displayOptions->push_back(&displayModes[i]); } adapterCounter++; } Getting all display modes

Does it have our desired format? bool hasMode = false; vector ::iterator iterator; iterator = displayOptions->begin(); while ((iterator != displayOptions->end()) && !hasMode) {D3DDISPLAYMODE *testMode = (*iterator); if ((testMode->Format == DEFAULT_COLOR_MODE) && (testMode->Width == DEFAULT_SCREEN_WIDTH) && (testMode->Height == DEFAULT_SCREEN_HEIGHT)) hasMode = true; iterator++; } Now we can make our graphics device & sprite handler

LPDIRECT3DDEVICE9graphicsDevice; D3DPRESENT_PARAMETERSpresentParameters; LPD3DXSPRITEspriteHandler; … ZeroMemory(&presentParameters,sizeof(presentParameters)); presentParameters.Windowed = true; presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; presentParameters.hDeviceWindow = hWnd; presentParameters.BackBufferFormat= formatToUse; presentParameters.BackBufferWidth= screenWidthToUse; presentParameters.BackBufferHeight= screenHeightToUse; HRESULT result = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, presentParameters.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &presentParameters, &graphicsDevice); result = D3DXCreateSprite(graphicsDevice, &spriteHandler);

So what? LPD3DXSPRITE can draw 2D images LPDIRECT3DDEVICE9 can draw text To draw text we need a LPD3DXFONT

Making a font object LPD3DXFONT textFont; … HRESULT result = D3DXCreateFont( graphicsDevice, 20, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_MODERN, TEXT(""), &textFont );

Oh, and we need to load images For this, we need a color key. What’s that? –color ignored while loading an image Why would this be useful? –game shapes aren’t all rectangular Important methods: –D3DXGetImageInfoFromFile –D3DXCreateTextureFromFileEx Let’s use them:

D3DXIMAGE_INFO info; HRESULT result = D3DXGetImageInfoFromFile(fileName, &info); if (result == S_OK) {D3DCOLOR colorKey = D3DCOLOR_XRGB(96, 128, 224); LPDIRECT3DTEXTURE9 textureToLoad; result = D3DXCreateTextureFromFileEx( graphicsDevice,fileName, info.Width,info.Height, 1,D3DPOOL_DEFAULT, D3DFMT_UNKNOWN,D3DPOOL_DEFAULT, texture, D3DX_DEFAULT, colorKey, &info, NULL, &textureToLoad );

Now we want to draw them There is a bit of overhead in rendering a single texture Solution? –pool that overhead –called batch texture rendering

Each Frame 1.clear screen 2.reserve the GPU for rendering 3.start sprite batch 4.render all textures 5.render text 6.end sprite batch 7.unreserve the GPU 8.force the GPU to the screen

Rendering a frame graphicsDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(96, 96, 96), 1.0f, 0); graphicsDevice->BeginScene(); spriteHandler->Begin(D3DXSPRITE_ALPHABLEND); result = spriteHandler->Draw(texture, imageRect, NULL, &position, alphaColor); result = textFont->DrawText (spriteHandler, L"Render this Text", -1, &textRect, DT_LEFT, D3DCOLOR_XRGB(96, 96, 96) ); spriteHandler->End(); graphicsDevice->EndScene(); graphicsDevice->Present(NULL, NULL, NULL, NULL);

Did you get all that? Believe me, you’ll get used to it

Texture Management Skilled game programmers recycle images Think of a tiled game background –the same images duplicated many times Efficient Solution: texture manager When you load a level: –load one of each needed image into a level texture manager –for rendering, refer to image indices in texture manager

What might a texture manager do? Store all textures Store all names of texture files & paths map textures; Provide methods for: –loading, accessing, reloading, etc.

We might also want a string table vector stringTable; Why? –int s take up less memory than wstring s So how do we use it? –when initializing game items use image index –game items store stringTable index to represent texture –when time to draw, ask stringTable for string at index –swap string for texture in texture manager

We’ll use 2 TextureManagers One for the GUI One for the Level Why use 2?

Windowed vs Fullscreen mode Windowed: –Can minimize, maximize, hit “x” to close, etc. –Share GPU –Share all resources Fullscreen –you get the resources –how do we get out? Game control (exit game for example) ALT-TAB

The Evil ALT-TAB When in Full-Screen mode: –What happens when someone ALT-TABS? We lose the graphics device How do we get it back? Someone needs to ALT-TAB back –How can we deal with this? Check to see if our game has the GPU every single frame

HRESULT result = graphicsDevice->TestCooperativeLevel(); if (SUCCEEDED(result)) { // RENDER THE GAME HERE } else if (result == D3DERR_DEVICELOST) { // SOME OTHER APPLICATION HAS THE GPU, MAYBE // AN ALT-TAB, WE JUST HAVE TO KEEP TRYING TO // GET IT BACK Sleep(100); } else if (result == D3DERR_DEVICENOTRESET) { // YAY! WE GOT THE GPU BACK, MAYBE SOMEONE ALT-TABBED BACK // RESET THE GRAPHICS CARD AND RELOAD ALL THE TEXTURES if (FAILED(graphicsDevice->Reset(&presentParameters))) // RELOAD ALL IMAGES }