//---------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------- void Renderer::EndRecord( const wchar_t* outputPath ) { assert( m_recording ); GetDevice()->SetRenderTarget( 0, m_recordingTempTarget ); GetDevice()->SetDepthStencilSurface( m_recordingTempDepth ); ES_SAFE_RELEASE( m_recordingTempTarget ); ES_SAFE_RELEASE( m_recordingTempDepth ); D3DXSaveSurfaceToFileW( outputPath, D3DXIFF_PNG, m_recordingTarget, NULL, NULL ); ES_SAFE_RELEASE( m_recordingTarget ); ES_SAFE_RELEASE( m_recordingTargetTexture ); ES_SAFE_RELEASE( m_recordingDepth ); m_recording = false; }
bool DirectXTextureManager::loadTileSetFromTexture( Game *game, wstring dir, wstring sourceImageFileName, int tileWidth, int tileHeight, int spacing, int margin) { // CONVERT THE FILE NAME INTO A WINDOW LONG CHAR wchar_t (LPCWSTR) wstring sourcePath = dir + sourceImageFileName; LPDIRECT3DTEXTURE9 textureToDivide; LPDIRECT3DSURFACE9 surfaceToDivide; unsigned int result = fillTexture(sourcePath, &textureToDivide); textureToDivide->GetSurfaceLevel(0, &surfaceToDivide); if (result != S_OK) return false; // DETERMINE THE NUMBER OF TILE ROWS AND COLUMNS D3DSURFACE_DESC surfaceDesc; surfaceToDivide->GetDesc(&surfaceDesc); int textureWidth = surfaceDesc.Width; int textureHeight = surfaceDesc.Height; int columns = (textureWidth-margin)/(tileWidth+spacing); int rows = (textureHeight-margin)/(tileHeight+spacing); DirectXGraphics *dxg = (DirectXGraphics*)graphics; LPDIRECT3DDEVICE9 graphicsDevice = ((DirectXGraphics*)graphics)->getGraphicsDevice(); // THE TILE SET IMAGE LOADED SUCCESSFULLY, SO LET'S CUT IT UP for (int row = 0; row < rows; row++) { for (int column = 0; column < columns; column++) { LPDIRECT3DTEXTURE9 extractedTexture; LPDIRECT3DSURFACE9 extractedSurface; result = graphicsDevice->CreateRenderTarget(tileWidth, tileHeight, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, false, &extractedSurface, NULL); if (result != S_OK) return false; RECT sourceRect; sourceRect.left = (column * (tileWidth + spacing)) + margin; sourceRect.right = tileWidth + (sourceRect.left) - 1; sourceRect.top = (row * (tileHeight + spacing)) + margin; sourceRect.bottom = tileHeight + (sourceRect.top) - 1; graphicsDevice->StretchRect(surfaceToDivide, &sourceRect, extractedSurface, NULL, D3DTEXF_NONE); // BUILD A UNIQUE FILE NAME FOR THIS TEXTURE wstring textureFilename = sourceImageFileName; unsigned int id = wstringTable.getNumWStringsInTable(); wchar_t dot = '.'; int dotIndex = textureFilename.rfind(dot); textureFilename = textureFilename.substr(0, dotIndex); wstringstream idWss; idWss << id; wstring idText; idWss >> idText; textureFilename = textureFilename + idText + L".png"; textureFilename = wstring(dir.begin(), dir.end()) + textureFilename; // LET'S PUT THE SURFACE IN AN IMAGE FILE D3DXSaveSurfaceToFileW(textureFilename.c_str(), D3DXIFF_PNG, extractedSurface, NULL, NULL); D3DXIMAGE_INFO info; HRESULT result = D3DXGetImageInfoFromFile(textureFilename.c_str(), &info); if (result != S_OK) return false; // AND THEN LOAD IT BACK IN AS A TEXTURE result = D3DXCreateTextureFromFileEx( graphicsDevice, // GPU textureFilename.c_str(), // BITMAP FILE PATH/NAME tileWidth, // BITMAP IMAGE WIDTH tileHeight, // BITMAP IMAGE HEIGHT 1, // MIP-MAP LEVELS (1 FOR NO CHAIN) D3DPOOL_DEFAULT, // THE TYPE OF SURFACE (STANDARD) D3DFMT_UNKNOWN, // SURFACE FORMAT (DEFAULT) D3DPOOL_DEFAULT, // MEMORY CLASS FOR THE TEXTURE D3DX_DEFAULT, // IMAGE FILTER D3DX_DEFAULT, // MIP FILTER NULL, // COLOR KEY &info, // BITMAP FILE INFO NULL, // COLOR PALETTE &extractedTexture ); // THE TEXTURE WE ARE CREATING AND LOADING if (result != S_OK) return false; // ADD IT TO THE STRING TABLE wstringTable.putWStringInTable(textureFilename); // AND ADD IT TO THE TEXTURES textures[textureFilename] = extractedTexture; } } return true; }