DOC PREVIEW
U-M CIS 487 - Lecture - Direct Draw and Bitmaps

This preview shows page 1-2-15-16-17-32-33 out of 33 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

DirectDraw and Bitmaps Part 2Page FlippingCreating Primary Surface with Back BufferLaMothe ExamplesInside Game_Init( )Inside Game_Shutdown( )Inside Game_Main( )Using the BlitterBlitting to do Simple 8 Bit FillsSlide 10Slide 11Slide 12Slide 13Copying Bitmaps Between SurfacesGame_Main( )Slide 16ClippingClipping Bitmaps the HardwayBlit_Clipped( )Slide 20Slide 21Slide 22Creating Happy FaceGame_Init( )Slide 25Slide 26Slide 27DirectDraw ClippingCreating Clipper ObjectCreating Clipping ListSlide 31Set the Clipping ListAttach Clipper and Clean Up1DirectDraw and BitmapsPart 2CIS 487/587Bruce R. MaximUM-Dearborn2Page Flipping1. Clear back buffer2. Render scene to back buffer surface3. Flip primary surface with back buffer surface4. Lock to frame rate (e.g. 30 fps)5. Repeat step 13Creating Primary Surface with Back Buffer•Add DDSD_BACKBUFFERCOUNT to the dwFlags field so DirectDraw can check number surfaces at creation•Add DFDSCAPS_COMPLEX and DDSCAPS_FLIP to capabilities word of DDSURFACE2 contained in ddsCaps.dwCaps filed•Create primary surface as usual and request attached buffer using GetAttachedSurface( )4LaMothe Examples5Inside Game_Init( )// enable valid fieldsddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;// set the backbuffer count field for double bufferingddsd.dwBackBufferCount = 1;// request a complex, flippableddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;// create the primary surfaceif (FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL))) return(0);// now query for attached surface from the primary surface// this line is needed by the callddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;// get the attached back buffer surfaceif (FAILED(lpddsprimary->GetAttachedSurface(&ddsd.ddsCaps, &lpddsback))) return(0);6Inside Game_Shutdown( )// first the paletteif (lpddpal){ lpddpal->Release(); lpddpal = NULL;} // end if // now the back buffer surfaceif (lpddsback){ lpddsback->Release(); lpddsback = NULL;} // end if // now the primary surfaceif (lpddsprimary){ lpddsprimary->Release(); lpddsprimary = NULL;} // end if// then the DirectDrawInterface7Inside Game_Main( )// draw the next frame into the back buffer, notice that we// must use the lpitch since it's a surface and may not be linear // plot 5000 random pixelsfor (int index=0; index < 5000; index++){ int x = rand()%SCREEN_WIDTH; int y = rand()%SCREEN_HEIGHT; UCHAR col = rand()%256; back_buffer[x+y*ddsd.lPitch] = col;} // end for index // unlock the back bufferif (FAILED(lpddsback->Unlock(NULL))) return(0); // perform the flip (both primary and back buffer must be unlockedwhile (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));8Using the Blitter•The blitter can be used to paste bit images from off screen surfaces to the primary surface•The function Blt( ) does blitting using DirectDraw clippers•The function BltFast( ) does not do clipping and runs faster9Blitting to do Simple 8 Bit Fills•Place the color index or RGB color you want to use to fill the surface in the dwFillColor field of a DDBLTFX struct•Define a RECT in the area you want to fill on the destination surface•Call Blt( ) from destination surface interface pointer using control falgs DDBT_COLORFILL | DDBLT_WAIT10Inside Game_Init( )// create IDirectDraw interface 7.0 object// set cooperation to full screen// set display mode // clear ddsd and set sizeDDRAW_INIT_STRUCT(ddsd); // enable valid fieldsddsd.dwFlags = DDSD_CAPS;// request a complex, flippableddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; // create the primary surface11Inside Game_Main( )DDBLTFX ddbltfx; // the blitter fx structureRECT dest_rect; // used to hold the destination RECT// first initialize the DDBLTFX structureDDRAW_INIT_STRUCT(ddbltfx); // now set the color word info to the color we desire// in this case, we are assuming an 8-bit mode, hence,// well use a color index from 0-255ddbltfx.dwFillColor = _RGB16BIT565(rand()%256, rand()%256, rand()%256);12Inside Game_Main( )// now set up the RECT structure to fill the region from// (x1,y1) to (x2,y2) on the destination surfacedest_rect.left = x1;dest_rect.top = y1;dest_rect.right = x2;dest_rect.bottom = y2; // make the blitter callif (FAILED(lpddsprimary->Blt(&dest_rect, // pointer to dest RECT NULL, // pointer to source surface NULL, // pointer to source RECT DDBLT_COLORFILL | DDBLT_WAIT, // do color fill wait if you have to &ddbltfx))) // pointer to DDBLTFX info return(0);13Inside Game_Main( )•Please note, in this example the call to Blt( ) has NULL pointers to both the surface and the source rectangle•The reason for this is that the color fills are handled by the blitter hardware support (or emulation if needed)14Copying Bitmaps Between Surfaces•When using the Blt( ) function you are sending both a source and destination rectangle to use in performing the blit•Blitting when the source and destination surfaces are different is the basis for most sprite engines•A sprite is a bitmap the seems to move on the screen15Game_Main( )RECT source_rect, // used to hold the destination RECT dest_rect; // used to hold the destination RECT// now set up the RECT structure to fill the region from// (x1,y1) to (x2,y2) on the source surfacesource_rect.left = x1;source_rect.top = y1;source_rect.right = x2;source_rect.bottom = y2; // now set up the RECT structure to fill the region from// (x3,y3) to (x4,y4) on the destination surfacedest_rect.left = x3;dest_rect.top = y3;dest_rect.right = x4;dest_rect.bottom = y4;16Game_Main( )// make the blitter callif (FAILED(lpddsprimary->Blt(&dest_rect, // pointer to dest RECT lpddsback, // source surface &source_rect,// pointer source RECT DDBLT_WAIT, // control flags NULL))) // pointer to DDBLTFX info return(0);17Clipping•Suppose you want to clip a pixel with coordinates (x,y) to a viewport from (x1,y1) to (x2,y2)void Plot_Pixel_Clip8(int x, int y, UCHAR color, UCHAR *video_buffer){ // test for coordinates in range if (x >= x1 && x <<= x2 && y >= y && y <= y2) video_buffer[x + y * 640] = color;}18Clipping Bitmaps the Hardway•Method 1 (image space clipping)–Clip each pixel of the bitmap individually as each is generated (simple but


View Full Document

U-M CIS 487 - Lecture - Direct Draw and Bitmaps

Documents in this Course
Mad Maxim

Mad Maxim

10 pages

DirectX

DirectX

10 pages

Load more
Download Lecture - Direct Draw and Bitmaps
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture - Direct Draw and Bitmaps and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture - Direct Draw and Bitmaps 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?