void cleanup() // it's a dirty job.. but some function has to do it... { if (myRect1) delete myRect1; if (myRect2) delete myRect2; if (myRect3) delete myRect3; if (myRect4) delete myRect4; if (myRect5) delete myRect5; if( lpD3DDevice8 != NULL ) lpD3DDevice8->Release(); if( lpD3D8 != NULL ) lpD3D8->Release(); if( lpD3DXFont != NULL ) lpD3DXFont->Release(); if( lpD3DTex1 != NULL ) lpD3DTex1->Release(); }
RageDisplay_D3D::~RageDisplay_D3D() { LOG->Trace( "RageDisplay_D3D::~RageDisplay()" ); GraphicsWindow::Shutdown(); if( g_pd3dDevice ) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; } if( g_pd3d ) { g_pd3d->Release(); g_pd3d = NULL; } /* Even after we call Release(), D3D may still affect our window. It seems * to subclass the window, and never release it. Free the DLL after * destroying the window. */ if( g_D3D8_Module ) { FreeLibrary( g_D3D8_Module ); g_D3D8_Module = NULL; } }
//----------------------------------------------------------------------------- // Name: Cleanup() // Desc: Releases all previously initialized objects //----------------------------------------------------------------------------- VOID Cleanup() { if( g_pd3dDevice != NULL) g_pd3dDevice->Release(); if( g_pD3D != NULL) g_pD3D->Release(); }
//----------------------------------------------------------------------------- // Name: Cleanup() // Desc: Releases all previously initialized objects //----------------------------------------------------------------------------- VOID Cleanup() { if( g_pTexture != NULL ) g_pTexture->Release(); if( g_pVB != NULL ) g_pVB->Release(); if( g_pd3dDevice != NULL ) g_pd3dDevice->Release(); if( g_pD3D != NULL ) g_pD3D->Release(); }
RageDisplay_D3D::~RageDisplay_D3D() { LOG->Trace( "RageDisplay_D3D::~RageDisplay()" ); if( g_pd3dDevice ) g_pd3dDevice->Release(); if( g_pd3d ) g_pd3d->Release(); #if !defined(XBOX) if( g_D3D8_Module ) { FreeLibrary( g_D3D8_Module ); g_D3D8_Module = NULL; } #endif GraphicsWindow::Shutdown(); }
LRESULT CALLBACK WindowProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam) { int i; switch ( uMsg ) { case WM_DESTROY: rendering = 0; FreeBrushes ( Brushes, BrushCount ); if ( FinalBSP ) delete FinalBSP; for ( i = 0; i < 3; i++ ) { lpTextureSurface [ i ]->Release ( ); } lpDevice->Release ( ); lpD3D->Release ( ); PostQuitMessage ( 0 ); break; case WM_MOUSEMOVE: SetCursor ( NULL ); break; case WM_KEYUP: switch ( wParam ) { case VK_ESCAPE: quit = 1; DestroyWindow ( hWnd ); break; } break; default: return DefWindowProc ( hWnd, uMsg, wParam, lParam ); } return 0L; }
//----------------------------------------------------------------------------- // Name: Cleanup() // Desc: Releases all previously initialized objects //----------------------------------------------------------------------------- VOID Cleanup() { if( g_pMeshMaterials != NULL ) delete[] g_pMeshMaterials; if( g_pMeshTextures ) { for( DWORD i = 0; i < g_dwNumMaterials; i++ ) { if( g_pMeshTextures[i] ) g_pMeshTextures[i]->Release(); } delete[] g_pMeshTextures; } if( g_pMesh != NULL ) g_pMesh->Release(); if( g_pd3dDevice != NULL ) g_pd3dDevice->Release(); if( g_pD3D != NULL ) g_pD3D->Release(); }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. HWND hwnd; MSG msg; char appname[6]; strcpy(appname,"test1"); WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = appname; RegisterClass(&wc); hwnd = CreateWindowEx(0/*WS_EX_TOPMOST*/,appname,NULL,WS_VISIBLE | WS_BORDER | WS_SYSMENU,0,0,800,600,NULL,NULL,hInstance,NULL); ShowWindow(hwnd,SW_SHOW); SetFocus(hwnd); if(NULL == (pd3d = Direct3DCreate8( D3D_SDK_VERSION ))) { MessageBox(hwnd,"Failed to create D3D object",ERROR,MB_ICONERROR | MB_OK | MB_SYSTEMMODAL); //PostQuitMessage(0); return false; } D3DPRESENT_PARAMETERS d3dpp; D3DDISPLAYMODE d3ddm; /*d3ddm.Width = 800; d3ddm.Height = 600; d3ddm.RefreshRate = 0; d3ddm.Format = D3DFMT_A8R8G8B8; */pd3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ); ZeroMemory( &d3dpp, sizeof(d3dpp) ); /*d3dpp.BackBufferWidth = 800; d3dpp.BackBufferHeight = 600; d3dpp.BackBufferCount = 1; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.Windowed = FALSE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; d3dpp.hDeviceWindow = NULL; d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER ; d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; */d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; if(FAILED(pd3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddevice ))) { MessageBox(hwnd,"Failed to Initialize D3D object",ERROR,MB_ICONERROR | MB_OK | MB_SYSTEMMODAL); //PostQuitMessage(0); return false; } setup(); SetTimer(hwnd,1,20,NULL); //ShowCursor(false); while(!done) { while(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } //if(msg.message == WM_QUIT) break; StartFrame(); Render(); EndFrame(); } KillTimer(hwnd,1); shutdown(); if( d3ddevice != NULL) d3ddevice->Release(); if( pd3d != NULL) pd3d->Release(); //ShowCursor(true); return 0; }
int main(int argc, char* argv[]) { int NoProtect = 0; AllowLinear = true; double MaxMSE = 4.0; CmdLineArgs args; if (args.size() == 1) { Usage(); return 1; } const char* InputDir = NULL; const char* OutputFilename = "Textures.xpr"; for (unsigned int i = 1; i < args.size(); ++i) { if (!stricmp(args[i], "-help") || !stricmp(args[i], "-h") || !stricmp(args[i], "-?")) { Usage(); return 1; } else if (!stricmp(args[i], "-input") || !stricmp(args[i], "-i")) { InputDir = args[++i]; } else if (!stricmp(args[i], "-output") || !stricmp(args[i], "-o")) { OutputFilename = args[++i]; } else if (!stricmp(args[i], "-noprotect") || !stricmp(args[i], "-p")) { NoProtect = 1; } else if (!stricmp(args[i], "-onlyswizzled") || !stricmp(args[i], "-s")) { AllowLinear = false; } else if (!stricmp(args[i], "-quality") || !stricmp(args[i], "-q")) { ++i; if (!stricmp(args[i], "min")) { MaxMSE = DBL_MAX; } else if (!stricmp(args[i], "low")) { MaxMSE = 20.0; } else if (!stricmp(args[i], "normal")) { MaxMSE = 4.0; } else if (!stricmp(args[i], "high")) { MaxMSE = 1.5; } else if (!stricmp(args[i], "max")) { MaxMSE = 0.0; } else { printf("Unrecognised quality setting: %s\n", args[i]); } } else { printf("Unrecognised command line flag: %s\n", args[i]); } } // Initialize DirectDraw pD3D = Direct3DCreate8(D3D_SDK_VERSION); if (pD3D == NULL) { puts("Cannot init D3D"); return 1; } HRESULT hr; D3DDISPLAYMODE dispMode; D3DPRESENT_PARAMETERS presentParams; pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dispMode); ZeroMemory(&presentParams, sizeof(presentParams)); presentParams.Windowed = TRUE; presentParams.hDeviceWindow = GetConsoleWindow(); presentParams.SwapEffect = D3DSWAPEFFECT_COPY; presentParams.BackBufferWidth = 8; presentParams.BackBufferHeight = 8; presentParams.BackBufferFormat = dispMode.Format; hr = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParams, &pD3DDevice); if (FAILED(hr)) { printf("Cannot init D3D device: %08x\n", hr); pD3D->Release(); return 1; } char HomeDir[MAX_PATH]; GetCurrentDirectory(MAX_PATH, HomeDir); XPRFile.OutputBuf = (char*)VirtualAlloc(0, 64 * 1024 * 1024, MEM_RESERVE, PAGE_NOACCESS); if (!XPRFile.OutputBuf) { printf("Memory allocation failure: %08x\n", GetLastError()); pD3DDevice->Release(); pD3D->Release(); return 1; } Bundler.StartBundle(); // Scan the input directory (or current dir if false) for media files ConvertDirectory(InputDir, NULL, MaxMSE); VirtualFree(XPRFile.OutputBuf, 0, MEM_RELEASE); pD3DDevice->Release(); pD3D->Release(); SetCurrentDirectory(HomeDir); DWORD attr = GetFileAttributes(OutputFilename); if (attr != -1 && (attr & FILE_ATTRIBUTE_DIRECTORY)) { SetCurrentDirectory(OutputFilename); OutputFilename = "Textures.xpr"; } printf("\nWriting bundle: %s", OutputFilename); int BundleSize = Bundler.WriteBundle(OutputFilename, NoProtect); if (BundleSize == -1) { printf("\nERROR: %08x\n", GetLastError()); return 1; } printf("\nUncompressed texture size: %6dkB\nCompressed texture size: %8dkB\nBundle size: %8dkB\n\nWasted Pixels: %u/%u (%5.2f%%)\n", (UncompressedSize + 1023) / 1024, (((CompressedSize + 1023) / 1024) + 3) & ~3, (BundleSize + 1023) / 1024, TotalDstPixels - TotalSrcPixels, TotalDstPixels, 100.f * (float)(TotalDstPixels - TotalSrcPixels) / (float)TotalDstPixels); return 0; }