1 DirectDraw Basics CIS 487/587 Bruce R. Maxim UM-Dearborn.

Slides:



Advertisements
Similar presentations
Presented by: Stacy C. Lovell. How do we perceive color? Our eyes contain only 3 types of photosentitive cells tuned to three frequencies Red, Green,
Advertisements

OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Understanding an Apps Architecture ASFA Computer Science: Principles Fall 2013.
DirectDraw Technology CML Training Course 2001/07/24 Alex Ma.
Lecture 2 Concepts, Terms and Definitions. Display Devices They are divided into a lot of small squares called pixels (“PICture ELements”). Each pixel.
1 2D Graphics CIS 487/587 Bruce R. Maxim UM-Dearborn.
Graphics Pipeline.
GAM666 – Introduction To Game Programming ● As of DirectX 8, DirectDraw (2D) and Direct3D (3D) have been combined into DirectX Graphics (still often called.
Random access memory Sequential circuits all depend upon the presence of memory. A flip-flop can store one bit of information. A register can store 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.
1 DirectDraw and Bitmaps Part 1 CIS 487/587 Bruce R. Maxim UM-Dearborn.
Chapter 7 Interupts DMA Channels Context Switching.
1 DirectDraw and Bitmaps Part 2 CIS 487/587 Bruce R. Maxim UM-Dearborn.
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.
Java2D Graphics Summary Images,. Full-Screen Exclusive Mode -Full-screen exclusive mode is a powerful feature of J2SE TM version 1.4 that allows the programmer.
How the World Wide Web Works
1 Internet Graphics. 2 Representing Images  Raster Image: Images consist of “dots” of color, not lines  Pixel: Picture element-tiny rectangle  Resolution:
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 19 Other Graphics Considerations Review.
Digital Images The digital representation of visual information.
1 LiveViz – What is it? Charm++ library Visualization tool Inspect your program’s current state Client runs on any machine (java) You code the image generation.
Basics of a Computer Graphics System Introduction to Computer Graphics CSE 470/598 Arizona State University Dianne Hansford.
1 Scrolling and Panning CIS 487/587 Bruce R. Maxim UM-Dearborn.
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
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.
Welcome Topic: Pixels A.M.Meshkatur Rahman Class: vii Roll: 07.
CMPE 421 Parallel Computer Architecture
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
Video Monitor Uses raster scanning to display images –Beam of electrons illuminates phosphorus dots on the screen called pixels. Starting at the top of.
Tennis for Two, 1958, by William Higinbotham, Brookhaven National Lab CSE 380 – Computer Game Programming Graphics Device Management.
 The World Wide Web is a collection of electronic documents linked together like a spider web.  These documents are stored on computers called servers.
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.
Lab 8 Bit-Mapped Graphics Moving from text-based graphics to bit- mapped graphics. Easy to draw graphic points and lines using INT 10h, Function 0Ch (write.
BZUPAGES.COM Visual Programming Lecture – 2 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
3D Graphics for Game Programming Chapter IV Fragment Processing and Output Merging.
1 Windows GDI Programming CIS 487/587 Bruce R. Maxim UM-Dearborn.
1 Computer Graphics Week2 –Creating a Picture. Steps for creating a picture Creating a model Perform necessary transformation Lighting and rendering the.
The Vesta Parallel File System Peter F. Corbett Dror G. Feithlson.
ECE291 Computer Engineering II Lecture 15 Josh Potts University of Illinois at Urbana- Champaign.
“The perfect project plan is possible if one first documents a list of all the unknowns.” Bill Langley.
Chapter 9 DirectDraw 크래용 사용하기
Lecture 7: Intro to Computer Graphics. Remember…… DIGITAL - Digital means discrete. DIGITAL - Digital means discrete. Digital representation is comprised.
Chapter 13 DirectSound 로 잡음 만들기. 2 History of Sound Programming Sound programming always gets put off until the end DOS –Third party sound libraries:
Program 2 due 02/01  Be sure to document your program  program level doc  your name  what the program does  each function  describe the arguments.
12/5/2015 EEC492/693/793 - iPhone Application Development 1 EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 4 Wenbing Zhao
GAM666 – Introduction To Game Programming ● DirectX is implemented as a collection of COM objects ● To use a DirectX program, the user must have the correct.
Color Web Design Professor Frank. Color Displays Based on cathode ray tubes (CRTs) or back- lighted flat-screen Monitors transmit light - displays use.
COMPUTER GRAPHICS. Can refer to the number of pixels in a bitmapped image Can refer to the number of pixels in a bitmapped image The amount of space it.
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
Multilevel Caches Microprocessors are getting faster and including a small high speed cache on the same chip.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
CSCI 156: Lab 11 Paging. Our Simple Architecture Logical memory space for a process consists of 16 pages of 4k bytes each. Your program thinks it has.
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.
2/16/2016 EEC492/693/793 - iPhone Application Development 1 EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 4 Wenbing Zhao
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
Graphics and Image Data Representations 1. Q1 How images are represented in a computer system? 2.
Lecture 11 Text mode video
A user interface, like the one created by the DOS operating system, that makes use of typed commands.
Computer Graphics Lecture 03 Graphics Systems Cont… Taqdees A. Siddiqi
1 Chapter 6: Creating Oracle Data Block Forms. 2 Forms  Application with a graphical user interface that looks like a paper form  Used to insert, update,
Reference: What is it? A multimedia python library – Window Management – Graphics geometric shapes bitmaps (sprites) – Input Mouse Keyboard.
Computer Graphics Lecture 04 Point Taqdees A. Siddiqi
MOM! Phineas and Ferb are … Aims:
Pixels, Colors and Shapes
Animations.
Random access memory Sequential circuits all depend upon the presence of memory. A flip-flop can store one bit of information. A register can store a single.
Basic Graphics Drawing Shapes 1.
Game Loop Update & Draw.
HW for Computer Graphics
Desktop Window Manager
02 | What DirectX Can Do and Creating the Main Game Loop
Presentation transcript:

1 DirectDraw Basics CIS 487/587 Bruce R. Maxim UM-Dearborn

2 What is the process? You need to ensure that Ddraw.lib and Ddraw.h are included in your project 1.Create and DirectDraw object and obtain access to it (IDirectDraw is main COM object interface 2.Set video mode and cooperation level and create one or more DirectDraw surfaces (IDirectDrawSurface)

3 What is the process? 3.You may need to create a color pallete (IDirectDrawPalette) 4.Create a clipper (IDirectDrawClipper)

4 LaMothe Examples

5 Game Programs The way LaMothe does things in WinMain once the window is opened and registered // initialize game here Game_Init(); // enter main event loop while(TRUE) { // the usual message stuff goes here // main game processing goes here Game_Main(); } // end while // closedown game here Game_Shutdown();

6 Game_Init() int Game_Init(void *parms = NULL, int num_parms = 0) { // create IDirectDraw interface 7.0 object and test for error if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, ID_IDirectDraw7, NULL))) return(0); // set cooperation to normal since this will be a windowed app lpdd->SetCooperativeLevel(main_window_handle, DDSCL_NORMAL); // return success or failure return(1); } // end Game_Init

7 Game_Main( ) int Game_Main(void *parms = NULL, int num_parms = 0) { // main loop of the game, do all your processing here // if user is hitting ESC and send WM_CLOSE if (KEYDOWN(VK_ESCAPE)) SendMessage(main_window_handle,WM_CLOSE,0,0); // return success or failure return(1); } // end Game_Main

8 Game_ShutDown( ) int Game_Shutdown(void *parms = NULL, int num_parms = 0) { // simply blow away the IDirectDraw7 interface if (lpdd) { lpdd->Release(); lpdd = NULL; } // end if // return success return(1); } // end Game_Shutdown

9 Cooperation Level This allows you to specify the type of application –Windowed or full-screen –ModeX video modes (320x200, 320x240) –Allow ctl-atl-del to get out of game

10 Cooperation Level In a windowed application you might use lpdd->SetCooperativeLevel(main_window_handle, DDSCL_NORMAL); In a full-screen application you might use lpdd->SetCooperativeLevel(main_window_handle, DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT);

11 Selecting Video Mode One of the most important features of DirectX The function to use if SetDisplayMode( ) This will be done in GameInit( ) after setting the cooperation level // set display mode to 640x480x8 if (FAILED(lpdd->SetDisplayMode(640,480,8,0,0))) { // error return(0); } // end if

12 Full Screen Popup Sometimes it is good to create a popup window that appears to be full screen To get this to work on any computer yo need to use GetSystemMetrics( ) to get the current screen size and use the returned values when the popup window is created

13 Surfaces In DirectDraw displayable memory is referred to as a surface The primary surface represents the visible video screen and is mapped to the video memory on the video card (VRAM)

14 Surfaces A surface can be any size, but the primary surface must match the current screen resolution Surfaces can be created in video memory of system memory All surfaces have the same properties with respect to bit depth and color space

15 Game Surfaces Games typically have –Primary display surface (visible video screen) –Secondary display surface for animation (aka “backbuffer”) –Off screen surfaces (for bit maps, sprites, screen items, etc)

16 Creating Surfaces // You create a primary surface after setting display mode // clear ddsd and set size memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); // enable valid fields ddsd.dwFlags = DDSD_CAPS; // request primary surface when create ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; // create the primary surface if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL))) { return(0); // error } // end if

17 Building Pallete Array for (int color=1; color < 255; color++) { // fill with random RGB values palette[color].peRed = rand()%256; palette[color].peGreen = rand()%256; palette[color].peBlue = rand()%256; palette[color].peFlags = PC_NOCOLLAPSE; } // end for color // now fill in entry 0 and 255 with black and white palette[0].peRed = 0; palette[0].peGreen = 0; palette[0].peBlue = 0; palette[0].peFlags = PC_NOCOLLAPSE; palette[255].peRed = 255; palette[255].peGreen = 255; palette[255].peBlue = 255; palette[255].peFlags = PC_NOCOLLAPSE;

18 Using Pallete // create the palette object after surface created if (FAILED(lpdd->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE, palette,&lpddpal, NULL))) { return(0); // error } // end if // attach the palette to the primary surface if (FAILED(lpddsprimary->SetPalette(lpddpal))) { return(0); // error } // end if

19 Game_Shutdown( ) // cleanup in reverse of object creation order // first the palette if (lpddpal) { lpddpal->Release(); lpddpal = NULL; } // end if // now the primary surface if (lpddsprimary) { lpddsprimary->Release(); lpddsprimary = NULL; } // end if // now blow away the IDirectDraw7 interface if (lpdd) { lpdd->Release(); lpdd = NULL; } // end if

20 Linear vs Non-Linear Memory In an ideal world your video card has a horizontal pixel memory pitch that matches the way pixels are stored in system memory If that were true and you have 640 pixels with 8 bit color there would be 640 bytes of memory per video line With non-linear memory they won’t always match (so you will to think about pixel placement in light of this and changing video resolutions)

21 Plotting 8 Bit Pixels If you are using 640x480x8 mode and you have 640 bytes per line To access any screen pixel using (x,y) you could do it as follows UCHAR *video_buffer = (UCHAR *)ddsd.lpSurface; video_buffer[x+y*640] = color;

22 Plotting Pixels If you are using 640x480x16 mode and you have 640 words per line To access any screen pixel using (x,y) you could do it as follows USHORT *video_buffer = (USHORT *)ddsd.lpSurface; video_buffer[x+y*640] = color;

23 Drawing in DirectX Drawing (rendering) in DirectX is different than drawing use GDI GDI has lots of very slow drawing functions DirectX has a small number of very fast drawing functions (programmers use their own libraries and engines) In DirectX it is very important to lock a surface before you draw and unlock it when you are done

24 Initial Surface Parameters // Set the global drawing surface description LPDIRECTDRAW7 lpdd = NULL; // dd object LPDIRECTDRAWSURFACE7 lpddsprimary = NULL; // dd primary surface LPDIRECTDRAWSURFACE7 lpddsback = NULL; // dd back surface LPDIRECTDRAWPALETTE lpddpal = NULL; // a pointer to dd palette LPDIRECTDRAWCLIPPER lpddclipper = NULL; // dd clipper PALETTEENTRY palette[256]; // color palette PALETTEENTRY save_palette[256]; // used to save palettes DDSURFACEDESC2 ddsd; // surface description DDBLTFX ddbltfx; // used to fill DDSCAPS2 ddscaps; // surface capabilities HRESULT ddrval; // result from dd calls

25 Plotting Pixels // clear ddsd and set size, never assume it's clean memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); // lock surface if (FAILED(lpddsprimary->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL))) { return(0); // error } // end if // now ddsd.lPitch is valid and so is ddsd.lpSurface int mempitch = (int)ddsd.lPitch; UCHAR *video_buffer = (UCHAR *)ddsd.lpSurface; video_buffer[x+y*mempitch] = color; // now unlock the primary surface if (FAILED(lpddsprimary->Unlock(NULL))) return(0)