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
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
//----------------------------------------------------------------------------- // Name: CleanupGraphics() // Desc: //----------------------------------------------------------------------------- VOID CleanupGraphics() { for( DWORD i=0; i<4; i++ ) if( g_pddsShip[i] ) g_pddsShip[i]->Release(); if( g_pddsNumbers ) g_pddsNumbers->Release(); if( g_pddsFrontBuffer ) g_pddsFrontBuffer->Release(); if( g_pArtPalette ) g_pArtPalette->Release(); if( g_pSplashPalette ) g_pSplashPalette->Release(); if( !g_bFullscreen && g_pddsBackBuffer ) g_pddsBackBuffer->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
int PisteDraw_Lopeta() { if (!PD_unload) { int i; for (i=0; i<MAX_FONTTEJA; i++) { if (PD_fontit[i] != NULL ) delete PD_fontit[i]; PD_fontit[i] = NULL; } for (i=2;i<MAX_BUFFEREITA;i++) // 0 ja 1 on varattu taustapuskureille PisteDraw_Buffer_Tuhoa(i); if (PD_lpddpal) { PD_lpddpal->Release(); } PisteDraw_Buffer_Tuhoa(PD_TAUSTABUFFER); PisteDraw_Buffer_Tuhoa(PD_TAUSTABUFFER2); if (PD_lpddsprimary) { PD_lpddsprimary->Release(); } if (PD_lpdd) { PD_lpdd->Release(); } PD_unload = true; } return 0; }
/******************************************************************** * Function : WindowProc() * Purpose : Receive and handle windows messages. ********************************************************************/ long FAR PASCAL WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { DDSURFACEDESC ddsd; DDBLTFX BltFx; HRESULT ddreturn; switch (message) { case WM_ACTIVATEAPP : ActiveApp = wParam; break; case WM_CREATE : break; case WM_KEYDOWN : switch (wParam) { case VK_PAUSE : /* Start or Stop realtime. */ RealTime = !RealTime; break; case VK_SPACE : /* Flip a single frame. */ SimLoop(); break; case VK_ESCAPE : DestroyWindow(hwnd); break; case VK_LEFT : bLeftKey = TRUE; break; case VK_RIGHT : bRightKey = TRUE; break; case VK_UP : bForwardKey = TRUE; break; case VK_DOWN : bBackKey = TRUE; break; case VK_ADD : nGauge++; break; case VK_SUBTRACT : nGauge--; break; case VK_HOME : nGauge = 0; break; } break; case WM_KEYUP : switch (wParam) { case VK_F1 : nState = 1; break; case VK_F2 : nState = 2; break; case VK_F3 : nState = 3; break; case VK_F4 : nState = 4; break; case VK_F5 : nState = 5; break; case VK_F6 : nState = 6; break; case VK_F7 : nState = 7; break; case VK_F8 : nState = 8; break; case VK_F9 : nState = 9; break; case VK_F10 : nState = 0; break; case VK_LEFT : bLeftKey = FALSE; break; case VK_RIGHT : bRightKey = FALSE; break; case VK_UP : bForwardKey = FALSE; break; case VK_DOWN : bBackKey = FALSE; break; case 'S' : // Screen Snapshot. // This is not done very reliably, infact, it's more of a hack so // I can show some Chrome snapshots on my website. // Open a file named "Snapshot.tga" and write the current content // of the screen as a targa file. HANDLE hFile; hFile = CreateFile("Snapshot.tga", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != NULL) { // Write the Targa header, as appropriate for the current // screen type. DWORD dwWritten; /* Targa File Header : (Little Endian / Intel) * Offset Length Description * 0 1 ID field length * 1 1 Color map type. * 2 1 Image type. * 3 2 First color map entry. * 5 2 Color map length. * 7 1 Color map entry size. * 8 2 Image X origin. * 10 2 Image Y Origin. * 12 2 Image Width. * 14 2 Image Height. * 16 1 Bits per pixel. * 17 1 Image descriptor bits. * (from : "Graphics File Formats", David C. Kay and John R. Levine) */ # define OutB(b)\ { unsigned char b2;\ b2 = b;\ WriteFile(hFile, &b2, sizeof(b2), &dwWritten, NULL);\ } # define OutW(w)\ { unsigned short w2;\ w2 = w;\ WriteFile(hFile, &w2, sizeof(w2), &dwWritten, NULL);\ } OutB(0); // No message ID field length. OutB(0); // Colormap type = 0; true color. OutB(2); // Image type = 2, True color, uncompressed. OutW(0); // First colormap entry is 0, (Because Cmap type = 0). OutW(0); // Colormap length = 0, (CMap type = 0). OutB(0); // CMap entry size is 0 (because CMap type = 0) OutW(0); // OriginX = 0; OutW(0); // OriginY = 0; OutW(XRES); // Image Width is the value of the XRES constant. OutW(YRES); // Image Height is the value of the YRES constant. OutB(24); // Bits per pixel. OutB(0x20); // Image Descriptor Bits (0x20 = left to right, top to bottom). // Each pixel is written as a Blue Green Red triple. // Lock the surface & write each byte. DDSURFACEDESC ddsd; memset(&ddsd, 0, sizeof(DDSURFACEDESC)); ddsd.dwSize = sizeof(ddsd); ddreturn = lpBackbuffer->Lock(NULL, &ddsd, DDLOCK_READONLY | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL); if (ddreturn == DD_OK) { //DrawWorld((unsigned char *)ddsd.lpSurface, (int)ddsd.lPitch); int nX, nY; for (nY = 0; nY < YRES; nY++) { for (nX = 0; nX < XRES; nX++) { unsigned char ucByte; ucByte = *(((unsigned char *)ddsd.lpSurface) + ddsd.lPitch * nY + nX); // Index the colormap & write the BGR triple. OutB(WinColormap[ucByte].peBlue); OutB(WinColormap[ucByte].peGreen); OutB(WinColormap[ucByte].peRed); } } lpBackbuffer->Unlock(NULL); } // Close the file, we're done... CloseHandle(hFile); } } break; case WM_DESTROY : if (lpDirectDrawObject != NULL) { if (lpBackbuffer != NULL) lpBackbuffer->Release(); if (lpPrimary != NULL) lpPrimary->Release(); if (lpPalette != NULL) lpPalette->Release(); lpDirectDrawObject->Release(); } /* Free the world. */ EndWorld(); /* Free the font. */ if (AppFont != NULL) DeleteObject(AppFont); ShowCursor(TRUE); PostQuitMessage(0); break; default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0L; }