/* * Helpers. */ static LPDIRECTDRAW7 getDDRAW (void) { LPDIRECTDRAW7 pDDRAW = NULL; LPDIRECTDRAW iface = NULL; HRESULT rc = DirectDrawCreate (NULL, &iface, NULL); if (rc != DD_OK) { LOGDDRAW(("DDRAW: Could not create DirectDraw interface rc= 0x%08X\n", rc)); } else { rc = iface->QueryInterface (IID_IDirectDraw7, (void**)&pDDRAW); if (rc != DD_OK) { LOGDDRAW(("DDRAW: Could not query DirectDraw 7 interface rc = 0x%08X\n", rc)); } else { rc = pDDRAW->SetCooperativeLevel (NULL, DDSCL_NORMAL); if (rc != DD_OK) { LOGDDRAW(("DDRAW: Could not set the DirectDraw cooperative level rc = 0x%08X\n", rc)); pDDRAW->Release (); } } iface->Release(); } return rc == DD_OK? pDDRAW: NULL; }
//----------------------------------------------------------------------------- // Name: DDEnumCallbackEx() // Desc: This callback gets the information for each device enumerated //----------------------------------------------------------------------------- BOOL WINAPI DDEnumCallbackEx( GUID *pGUID, LPSTR pDescription, LPSTR strName, LPVOID pContext, HMONITOR hm ) { LPDIRECTDRAW7 pDD = NULL; HRESULT hr; // Create a DirectDraw object using the enumerated GUID if( FAILED( hr = DirectDrawCreateEx( pGUID, (VOID**)&pDD, IID_IDirectDraw7, NULL ) ) ) return DDENUMRET_CANCEL; // Get the device information and save it pDD->GetDeviceIdentifier( &g_DeviceIdent[g_iMaxDevices].DeviceInfo, 0 ); pDD->GetDeviceIdentifier( &g_DeviceIdent[g_iMaxDevices].DeviceInfoHost, DDGDI_GETHOSTIDENTIFIER ); // Finished with the DirectDraw object, so release it SAFE_RELEASE( pDD ); // Bump to the next open slot or finish the callbacks if full if( g_iMaxDevices < MAX_DEVICES ) g_iMaxDevices++; else return DDENUMRET_CANCEL; return DDENUMRET_OK; }
/** * vdraw_ddraw_set_cooperative_level(): Sets the DirectDraw cooperative level. * @return 0 on success; non-zero on error. */ int WINAPI vdraw_ddraw_set_cooperative_level(void) { if (!gens_window || !lpDD) return -1; HRESULT rval; #ifdef DISABLE_EXCLUSIVE_FULLSCREEN_LOCK Video.VSync_FS = 0; rval = lpDD->SetCooperativeLevel(gens_window, DDSCL_NORMAL); #else if (vdraw_get_fullscreen()) rval = lpDD->SetCooperativeLevel(gens_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); else rval = lpDD->SetCooperativeLevel(gens_window, DDSCL_NORMAL); #endif if (FAILED(rval)) { LOG_MSG(video, LOG_MSG_LEVEL_WARNING, "lpDD->SetCooperativeLevel() failed."); // TODO: Error handling code. } else { LOG_MSG(video, LOG_MSG_LEVEL_INFO, "lpDD->SetCooperativeLevel() succeeded."); } return 0; }
BOOL WINAPI DDEnumCallback( GUID *pGUID, LPSTR pDescription, LPSTR strName, LPVOID pContext ) { LPDIRECTDRAW7 pDD = NULL; HRESULT hr; if( FAILED( hr = DirectDrawCreateEx( pGUID, (VOID**)&pDD, IID_IDirectDraw7, NULL ) ) ) return DDENUMRET_CANCEL; pDD->GetDeviceIdentifier( &DeviceInfo[g_iMaxDevices], 0 ); if(pDD) { pDD->Release(); pDD = NULL; } if( g_iMaxDevices < MAX_DEVICES ) g_iMaxDevices++; else return DDENUMRET_CANCEL; return DDENUMRET_OK; }
int Game_Init(void *parms = NULL, int num_parms = 0) { // this is called once after the initial window is created and // before the main event loop is entered, do all your initialization // here // create IDirectDraw interface 7.0 object and test for error if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL))) return(0); // set cooperation to full screen if (FAILED(lpdd->SetCooperativeLevel(main_window_handle, DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT))) { // error return(0); } // end if // set display mode to 640x480x8 if (FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,0,0))) { // error return(0); } // end if // return success or failure or your own return code here return(1); } // end Game_Init
/*****************************Private*Routine******************************\ * OnSetDDrawDevice * \**************************************************************************/ HRESULT CMpegMovie::OnSetDDrawDevice( LPDIRECTDRAW7 pDD, HMONITOR hMon ) { HRESULT hr = S_OK; RELEASE(m_pddsRenderT); RELEASE(m_pddsPriText); RELEASE(m_pddsPrimary); __try { DDSURFACEDESC2 ddsd; // A surface description structure INITDDSTRUCT(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; CHECK_HR(hr = pDD->EnumSurfaces(DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, &ddsd, &m_pddsPrimary, DDSurfEnumFunc)); if(!m_pddsPrimary) { hr = E_FAIL; __leave; } MONITORINFOEX miInfoEx; miInfoEx.cbSize = sizeof(miInfoEx); GetMonitorInfo(hMon, &miInfoEx); INITDDSTRUCT(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = (miInfoEx.rcMonitor.right - miInfoEx.rcMonitor.left); ddsd.dwHeight = (miInfoEx.rcMonitor.bottom - miInfoEx.rcMonitor.top); CHECK_HR(hr = pDD->CreateSurface(&ddsd, &m_pddsPriText, NULL)); CHECK_HR(hr = pDD->CreateSurface(&ddsd, &m_pddsRenderT, NULL)); } __finally { if(FAILED(hr)) { RELEASE(m_pddsRenderT); RELEASE(m_pddsPriText); RELEASE(m_pddsPrimary); } } return hr; }
int DD_Shutdown(void) { // this function release all the resources directdraw // allocated, mainly to com objects // release the clipper first if (lpddclipper) lpddclipper->Release(); // release the palette if (lpddpal) lpddpal->Release(); // release the secondary surface if (lpddsback) lpddsback->Release(); // release the primary surface if (lpddsprimary) lpddsprimary->Release(); // finally, the main dd object if (lpdd) lpdd->Release(); // return success return(1); } // end DD_Shutdown
BOOL jcdd_createOffscreenSurface( LPDIRECTDRAW7 lpdd, LPDIRECTDRAWSURFACE7* lplpdds, INT width, INT height, UINT colorKey, BOOL useColorKey) { if(lpdd == NULL) { return FALSE; } DDSURFACEDESC2 ddsd; jcdd_initStruct(&ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.dwWidth = width; ddsd.dwHeight = height; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; if(FAILED(lpdd->CreateSurface(&ddsd, lplpdds, NULL))) { return FALSE; } if(useColorKey) { DDCOLORKEY ck; ck.dwColorSpaceHighValue = colorKey; ck.dwColorSpaceLowValue = colorKey; if(FAILED((*lplpdds)->SetColorKey(DDCKEY_SRCBLT, &ck))) { return FALSE; } } return TRUE; }
void DirectDrawDisplay::cleanup() { if(pDirectDraw != NULL) { if(ddsClipper != NULL) { ddsClipper->Release(); ddsClipper = NULL; } if(ddsFlip != NULL) { ddsFlip->Release(); ddsFlip = NULL; } if(ddsOffscreen != NULL) { ddsOffscreen->Release(); ddsOffscreen = NULL; } if(ddsPrimary != NULL) { ddsPrimary->Release(); ddsPrimary = NULL; } pDirectDraw->Release(); pDirectDraw = NULL; } if(ddrawDLL != NULL) { AfxFreeLibrary(ddrawDLL); ddrawDLL = NULL; } width = 0; height = 0; }
int Game_Shutdown(void *parms = NULL, int num_parms = 0) { // this is called after the game is exited and the main event // loop while is exited, do all you cleanup and shutdown here // kill all the surfaces // 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 IDirectDraw4 interface if (lpdd) { lpdd->Release(); lpdd = NULL; } // end if // return success or failure or your own return code here return(1); } // end Game_Shutdown
//----------------------------------------------------------------------------- // Name: dx_Restaure() // Desc: Restaure les objets perdus (s'ils sont perdus) //----------------------------------------------------------------------------- void dx_Restaure () { if (SurfacePrimaire->IsLost () != DD_OK) { DirectDraw7->RestoreAllSurfaces (); (*Restaure)(); } }
int InitDirectDraw() { DDSURFACEDESC2 ddsd; DDSCAPS2 ddscaps; HRESULT hRet; // Create the main DirectDraw object. hRet = DirectDrawCreateEx(NULL, (VOID**)&g_pDD, IID_IDirectDraw7, NULL); if( hRet != DD_OK ) return -1; // Get exclusive mode. hRet = g_pDD->SetCooperativeLevel(g_hMainWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); if( hRet != DD_OK ) return -2; // Set the video mode to 640x480x16. hRet = g_pDD->SetDisplayMode(640, 480, 16, 0, 0); if( hRet != DD_OK ) return -3; // Prepare to create the primary surface by initializing // the fields of a DDSURFACEDESC2 structure. ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; // Create the primary surface. hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSFront, NULL); if( hRet != DD_OK ) return -1; // Get a pointer to the back buffer. ZeroMemory(&ddscaps, sizeof(ddscaps)); ddscaps.dwCaps = DDSCAPS_BACKBUFFER; hRet = g_pDDSFront->GetAttachedSurface(&ddscaps, &g_pDDSBack); if( hRet != DD_OK ) return -1; return 0; }
//! Setup the overlay object bool DDOverlayInit() { // Get hardware's CAPabilitieS memset(&g_DDCaps, 0, sizeof(g_DDCaps)); g_DDCaps.dwSize = sizeof(g_DDCaps); if (g_pDD->GetCaps(&g_DDCaps, 0)) return DisplayError("Can't get capabilities"); // Make sure it supports overlays if (!(g_DDCaps.dwCaps & DDCAPS_OVERLAY)) return DisplayError("Hardware doesn't support overlays"); //DO NOT Make sure it supports stretching (scaling) //if (!(g_DDCaps.dwCaps & DDCAPS_OVERLAYSTRETCH)) return false; DDSURFACEDESC2 ddsd; // DirectDraw surface descriptor HRESULT hRet; // I'm not even going to try... // The pixel formats that we want the surface to be in DDPIXELFORMAT ddpfOverlayFormats[] = { {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0xFF0000, 0x0FF00, 0x0000FF, 0}, // 32-bit RGB {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x007C00, 0x003e0, 0x00001F, 0}, // 16-bit RGB 5:5:5 {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x00F800, 0x007e0, 0x00001F, 0}, // 16-bit RGB 5:6:5 {sizeof(DDPIXELFORMAT), DDPF_FOURCC, mmioFOURCC('U','Y','V','Y'), 16, 0, 0, 0, 0}, // UYVY {sizeof(DDPIXELFORMAT), DDPF_FOURCC, mmioFOURCC('Y','4','2','2'), 16, 0, 0, 0, 0}, // the same as UYVY {sizeof(DDPIXELFORMAT), DDPF_FOURCC, mmioFOURCC('Y','U','Y','2'), 16, 0, 0, 0, 0}, // YUY2 is unsupported color-space here {0}}; // Setup the overlay surface's attributes in the surface descriptor memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY | g_DDCaps.ddsCaps.dwCaps&DDSCAPS_VIDEOMEMORY; ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd.dwBackBufferCount = 0; ddsd.dwWidth = g_sizex; ddsd.dwHeight = g_sizey; for(int format = 0; ddpfOverlayFormats[format].dwSize; format++) { ddsd.ddpfPixelFormat = ddpfOverlayFormats[format]; // Attempt to create the surface with theses settings hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSOverlay, NULL); if(hRet == DD_OK) break; } if (hRet != DD_OK) return DisplayError("Can't create appropriate overlay surface", hRet); return true; }
//----------------------------------------------------------------------------- // Name: CreateSurface() // Desc: creates a offscreen plain surface //----------------------------------------------------------------------------- LPDIRECTDRAWSURFACE7 CreateSurface(int width, int height, SCCOLOR TransparentColor) {// this function creates an offscreen plain surface //DDSURFACEDESC2 ddsd; // working description LPDIRECTDRAWSURFACE7 lpdds; // temporary surface // set to access caps, width, and height memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; // set dimensions of the new bitmap surface ddsd.dwWidth = width; ddsd.dwHeight = height; // set surface to offscreen plain ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;//default is video memory VRAM // create the surface ddReturnVal = lpddObj->CreateSurface(&ddsd,&lpdds,NULL); if(ddReturnVal == DDERR_OUTOFVIDEOMEMORY)//out of vram { // set surface to offscreen plain system memory ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; ddReturnVal = lpddObj->CreateSurface(&ddsd,&lpdds,NULL); } if (DDFailedCheck(ddReturnVal, "CreateSurface() failed", cpErrorBuf ))//DDERR_OUTOFVIDEOMEMORY DDSCAPS_SYSTEMMEMORY { MessageBox(main_window_handle, cpErrorBuf, "CreateSurface()", MB_ICONEXCLAMATION); return(NULL); } // set color key to TransparentColor DDCOLORKEY color_key; // used to set color key color_key.dwColorSpaceLowValue = BIULDCOLOR(TransparentColor.r,TransparentColor.g,TransparentColor.b); color_key.dwColorSpaceHighValue = BIULDCOLOR(TransparentColor.r,TransparentColor.g,TransparentColor.b); // now set the color key for source blitting ddReturnVal = lpdds->SetColorKey(DDCKEY_SRCBLT, &color_key); if (DDFailedCheck(ddReturnVal, "SetColorKey() failed", cpErrorBuf )) { MessageBox(main_window_handle, cpErrorBuf, "CreateSurface()", MB_ICONEXCLAMATION); return(NULL); } // return surface return(lpdds); } // end CreateSurface()
int Game_Init(void *parms = NULL, int num_parms = 0) { // this is called once after the initial window is created and // before the main event loop is entered, do all your initialization // here // create IDirectDraw interface 7.0 object and test for error if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL))) return(0); // set cooperation to full screen if (FAILED(lpdd->SetCooperativeLevel(main_window_handle, DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT))) return(0); // set display mode to 640x480x8 if (FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,0,0))) return(0); // clear ddsd and set size DDRAW_INIT_STRUCT(ddsd); // enable valid fields ddsd.dwFlags = DDSD_CAPS; // request primary surface ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; // create the primary surface if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL))) return(0); // load the 24-bit image if (!Load_Bitmap_File(&bitmap,"bitmap24.bmp")) return(0); // return success or failure or your own return code here return(1); } // end Game_Init
//----------------------------------------------------------------------------- // Name: ShutDown() // Desc: cleans up evreything. releases mem used //----------------------------------------------------------------------------- int ShutDown() { // now release the primary surface if (lpddsPrimary!=NULL) lpddsPrimary->Release(); // release the directdraw object if (lpddObj!=NULL) lpddObj->Release(); return(1); }
/** * vdraw_ddraw_restore_primary(): Restore the primary DirectDraw surface. * @return 0 on success; non-zero on error. */ int WINAPI vdraw_ddraw_restore_primary(void) { if (!lpDD) return -1; if (vdraw_get_fullscreen() && Video.VSync_FS) { while (lpDDS_Primary->GetFlipStatus(DDGFS_ISFLIPDONE) == DDERR_SURFACEBUSY) { } lpDD->FlipToGDISurface(); } return 0; }
void CleanUp() { g_surfCar.Destroy(); if(g_pDDSBack) g_pDDSBack->Release(); if(g_pDDSFront) g_pDDSFront->Release(); if(g_pDD) g_pDD->Release(); }
int Game_Shutdown(void *parms = NULL, int num_parms = 0) { // this is called after the game is exited and the main event // loop while is exited, do all you cleanup and shutdown here // first the palette if (lpddpal) { lpddpal->Release(); lpddpal = NULL; } // end if // now the lpddsbackground surface if (lpddsbackground) { lpddsbackground->Release(); lpddsbackground = NULL; } // end if // now the lpddsback surface if (lpddsback) { lpddsback->Release(); lpddsback = NULL; } // end if // now the primary surface if (lpddsprimary) { lpddsprimary->Release(); lpddsprimary = NULL; } // end if // now blow away the IDirectDraw4 interface if (lpdd) { lpdd->Release(); lpdd = NULL; } // end if // unload the bitmap file, we no longer need it Unload_Bitmap_File(&bitmap); // return success or failure or your own return code here return(1); } // end Game_Shutdown
/** * vdraw_ddraw_free_all(): Free all DirectDraw objects. * @param scl If true, sets the cooperative level of lpDD before freeing it. */ static void WINAPI vdraw_ddraw_free_all(bool scl) { if (lpDDC_Clipper) { lpDDC_Clipper->Release(); lpDDC_Clipper = NULL; } if (lpDDS_Back) { lpDDS_Back->Release(); lpDDS_Back = NULL; } if (lpDDS_Flip) { lpDDS_Flip->Release(); lpDDS_Flip = NULL; } if (lpDDS_Primary) { lpDDS_Primary->Release(); lpDDS_Primary = NULL; } if (lpDD) { if (scl) lpDD->SetCooperativeLevel(gens_window, DDSCL_NORMAL); lpDD->Release(); lpDD = NULL; } lpDDS_Blit = NULL; }
//----------------------------------------------------------------------------- // Name: dx_CreerSurface(...) // Desc: Créé une des surfaces à disposition //----------------------------------------------------------------------------- bool dx_CreerSurface (uint8 pNoSurface, uint16 pTailleX, uint16 pTailleY) { DDSURFACEDESC2 ddsd; if (pNoSurface >= NombreSurfaces) return false; ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = pTailleX; ddsd.dwHeight = pTailleY; ErrDd = DirectDraw7->CreateSurface (&ddsd, &Surfaces[pNoSurface], NULL); return ErrDd == DD_OK; }
//----------------------------------------------------------------------------- // Name: // Desc: //----------------------------------------------------------------------------- HRESULT CSurface::Create( LPDIRECTDRAW7 pDD, DDSURFACEDESC2* pddsd ) { HRESULT hr; // Create the DDraw surface if( FAILED( hr = pDD->CreateSurface( pddsd, &m_pdds, NULL ) ) ) return hr; // Prepare the DDSURFACEDESC structure m_ddsd.dwSize = sizeof(m_ddsd); // Get the DDSURFACEDESC structure for this surface m_pdds->GetSurfaceDesc( &m_ddsd ); return S_OK; }
int Game_Shutdown(void *parms = NULL, int num_parms = 0) { // this is called after the game is exited and the main event // loop while is exited, do all you cleanup and shutdown here // simply blow away the IDirectDraw4 interface if (lpdd) { lpdd->Release(); lpdd = NULL; } // end if // return success or failure or your own return code here return(1); } // end Game_Shutdown
//! Init the primary surface bool DDPrimaryInit() { HRESULT hRet; DDSURFACEDESC2 ddsd; // A surface description structure // Create the primary surface. The primary surface is the full screen - // since we're a windowed app - we'll just write to the portion of the // screen within our window. memset(&ddsd, 0, sizeof(ddsd)); // Set all fields of struct to 0 and set .dwSize to ddsd.dwSize = sizeof(ddsd); // Sizeof the variable - these two steps required for most DDraw structs ddsd.dwFlags = DDSD_CAPS; // Set flags for variables we're using... ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; // Set the variables we said we would in dwFlags hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSPrimary, NULL); if (hRet != DD_OK) return DisplayError("Can't create primary surface", hRet); return true; }
int Game_Init(void *parms = NULL, int num_parms = 0) { // this is called once after the initial window is created and // before the main event loop is entered, do all your initialization // here // create IDirectDraw interface 7.0 object and test for error if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_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 or your own return code here return(1); } // end Game_Init
//! Init DirectDraw Stuff bool DDInit() { HRESULT hRet; g_rcSrc.right = g_sizex; g_rcSrc.bottom = g_sizey; hRet = DirectDrawCreateEx(NULL, (VOID**)&g_pDD, IID_IDirectDraw7, NULL); if (hRet != DD_OK) return DisplayError("Can't create DirectDraw7 instance", hRet); // Set cooperation level with other windows to be normal (ie. not full screen) // You MUST set the cooperation level to be SOMETHING, for windowed apps use // DDSCL_NORMAL, for full screen use: DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. hRet = g_pDD->SetCooperativeLevel(g_hAppWnd, DDSCL_NORMAL); if (hRet != DD_OK) return DisplayError("Can't set cooperative level", hRet); return DDPrimaryInit(); }
void DDEnd(void) { if (m_pDD) { if (m_pddsFrontBuffer != NULL) { if (m_pddsFrame) m_pddsFrame->Release(); m_pddsFrame = NULL; if (pcClipper) pcClipper->Release(); pcClipper = NULL; if (m_pddsFrontBuffer) m_pddsFrontBuffer->Release(); m_pddsFrontBuffer = NULL; } m_pDD->Release(); m_pDD = NULL; } }
//! Load the bitmap and copy it to the overlay surface bool DrawOverlay() { HRESULT hRet; // This is where we put return values from DirectDraw. DDSURFACEDESC2 surfDesc; // Setup structure memset(&surfDesc, 0, sizeof(surfDesc)); surfDesc.dwSize = sizeof(surfDesc); hRet = g_pDDSOverlay->Lock(NULL, &surfDesc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_NOSYSLOCK | DDLOCK_WRITEONLY, NULL); if (hRet != DD_OK || surfDesc.lpSurface == NULL) return DisplayError("Can't lock overlay surface", hRet); else { g_pImg = (unsigned int *)surfDesc.lpSurface; //g_pDDSOverlay->Unlock(NULL); is not needed? } // Setup effects structure memset(&g_OverlayFX, 0, sizeof(g_OverlayFX)); g_OverlayFX.dwSize = sizeof(g_OverlayFX); // Setup overlay flags. g_OverlayFlags = DDOVER_SHOW; // Check for destination color keying capability if ((g_DDCaps.dwCKeyCaps & DDCKEYCAPS_DESTOVERLAY) && ((g_DDCaps.dwCaps & DDCAPS_OVERLAYCANTCLIP) || (g_DDCaps.dwCKeyCaps & DDCKEYCAPS_NOCOSTOVERLAY) )) { // If so, we'll use it to clip the bitmap when other windows go on top // of us. Just for the record - this color range for color keying (the // high/low values) are not heavily supported right now, so for almost // all cards, just use the same color for both. g_OverlayFX.dckDestColorkey.dwColorSpaceLowValue = g_OverlayFX.dckDestColorkey.dwColorSpaceHighValue = DDColorMatch(g_pDDSPrimary, RGBKEY); g_OverlayFlags |= DDOVER_DDFX | DDOVER_KEYDESTOVERRIDE; } else { // If not, we'll setup a clipper for the window. This will fix the // problem on a few video cards - but the ones that don't shouldn't care. hRet = g_pDD->CreateClipper(0, &g_pClipper, NULL); if (hRet != DD_OK) return DisplayError("Can't create clipper", hRet); hRet = g_pClipper->SetHWnd(0, g_hAppWnd); if (hRet != DD_OK) return DisplayError("Can't attach clipper", hRet); hRet = g_pDDSPrimary->SetClipper(g_pClipper); if (hRet != DD_OK) return DisplayError("Can't set clipper", hRet); } return true; }
/* 07/16/2000 Wendell Buckner Convert to Directx7... geBoolean TPage_CreateSurfaces(TPage *Page, LPDIRECTDRAW4 lpDD, const DDSURFACEDESC2 *SurfDesc) */ geBoolean TPage_CreateSurfaces(TPage *Page, LPDIRECTDRAW7 lpDD, const DDSURFACEDESC2 *SurfDesc) { HRESULT Hr; DDSURFACEDESC2 ddsd; assert(Page); memcpy(&ddsd, SurfDesc, sizeof(DDSURFACEDESC2)); ddsd.dwSize = sizeof(DDSURFACEDESC2); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE; ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC; ddsd.ddsCaps.dwCaps3 = 0; ddsd.ddsCaps.dwCaps4 = 0; ddsd.dwWidth = TPAGE_WIDTH; ddsd.dwHeight = TPAGE_HEIGHT; Hr = lpDD->CreateSurface(&ddsd, &Page->Surface, NULL); if (Hr != DD_OK) return GE_FALSE; /* 02/25/2001 Wendell Buckner /* This texture pointer is no longer valid under directx 7. Set it to TRUE so there is /* something there when the code does assert checks. Hr = Page->Surface->QueryInterface(IID_IDirect3DTexture2, (void**)&Page->Texture); if(Hr != DD_OK) { Page->Surface->Release(); Page->Surface = NULL; Page->Texture = NULL; return GE_FALSE; }*/ Page->Texture = Page->Surface; return GE_TRUE; // All good dude }
LPDIRECTDRAWSURFACE7 DDraw_Create_Surface(int width, int height, int mem_flags, int color_key = 0) { // this function creates an offscreen plain surface DDSURFACEDESC2 ddsd; // working description LPDIRECTDRAWSURFACE7 lpdds; // temporary surface // 清空ddsd然后再设置width, and height来创建离屏表面 memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; // set dimensions of the new bitmap surface ddsd.dwWidth = width; ddsd.dwHeight = height; // set surface to offscreen plain ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | mem_flags; // create the surface if (FAILED(lpdd->CreateSurface(&ddsd,&lpdds,NULL))) return(NULL); // 设置色彩键、也就是透明色、默认设置为黑色 // test if user wants a color key if (color_key >= 0) { // set color key to color 0 DDCOLORKEY color_key; // used to set color key color_key.dwColorSpaceLowValue = 0; color_key.dwColorSpaceHighValue = 0; // now set the color key for source blitting lpdds->SetColorKey(DDCKEY_SRCBLT, &color_key); } // end if // return surface return(lpdds); // return surface return(lpdds); } // end DDraw_Create_Surface