bool HMTerrain::Initialise(ID3D11Device* pd3dDevice, char* filename, ID3D11ShaderResourceView* texture) { bool result; // Load in the height map for the terrain. result = LoadHeightMap(filename); if (!result) return false; // Normalise the Height int i, j; for (j = 0; j<_pTerrainHeight; j++) { for (i = 0; i<_pTerrainWidth; i++) { _pHeightMap[(_pTerrainHeight * j) + i].y /= 3.75f; } } // Initialize the vertex and index buffer that hold the geometry for the terrain. result = InitialiseBuffers(pd3dDevice); if (!result) return false; _pTextureRV = texture; return true; }
bool DirectX10Renderer::Initialise(HWND* handle) { DEBUG_OUT("DirectX10Renderer::Initialise"); //window handle hWnd = handle; //get window dimensions RECT rc; GetClientRect( *hWnd, &rc ); m_ScreenWidth = rc.right - rc.left; m_ScreenHeight = rc.bottom - rc.top; m_CameraX = 0; m_CameraY = 0; if(!CreateSwapChainAndDevice()) return false; if(!ResizeScreen()) return false; if(!LoadShadersAndCreateInputLayouts()) return false; if(!InitialiseBuffers()) return false; // Load textures if(FAILED(D3DX10CreateShaderResourceViewFromFile(pD3DDevice, "./textures/tiles.png", NULL, NULL, &m_SpriteTexture, NULL))) { return FatalError("Could not load sprite texture"); } if(FAILED(D3DX10CreateShaderResourceViewFromFile(pD3DDevice, "./fonts/default.png", NULL, NULL, &m_FontTexture, NULL))) { return FatalError("Could not load font texture"); } //everything completed successfully return true; }
//Initialise Particle System bool CParticleSystem::Initialise(ID3D11Device* device, std::string mFileName, std::string mFileType, std::string textureLocation) { bool result; //Texture Location std::string textureRelativePath = TextureFinder(textureLocation, mFileName, mFileType); if (FAILED(D3DX11CreateShaderResourceViewFromFile(device, textureRelativePath.c_str(), NULL, NULL, &m_Texture[0], NULL))) { //Output Error Message OutputDebugString("Unable to Load Texture: "); OutputDebugString(textureRelativePath.c_str()); OutputDebugString("\n"); return false; } //Initialise Particles in System result = InitialiseParticleSystem(); if (!result) { return false; } //Initialise Buffers result = InitialiseBuffers(device); if (!result) { return false; } return true; }
bool CWater::Initialise(ID3D11Device* device, D3DXVECTOR3 minPoint, D3DXVECTOR3 maxPoint, unsigned int subDivisionX, unsigned int subDivisionZ, std::string normalMap, int screenWidth, int screenHeight) { // Release the existing data. Shutdown(); if (!InitialiseBuffers(device, minPoint, maxPoint, subDivisionX, subDivisionZ)) { logger->GetInstance().WriteLine("Failed to initialise the buffers of the body of water."); return false; } mpNormalMap = new CTexture(); if (!mpNormalMap->Initialise(device, "Resources/Textures/WaterNormalHeight.png")) { logger->GetInstance().WriteLine("Failed to load the normal map for water. Filename was: " + normalMap); return false; } /////////////////////////// // Refraction render target ////////////////////////// mpRefractionRenderTexture = new CRenderTexture(); if (!mpRefractionRenderTexture->Initialise(device, screenWidth, screenHeight, DXGI_FORMAT_R8G8B8A8_UNORM)) { logger->GetInstance().WriteLine("Failed to initialise the refraction render texture."); return false; } /////////////////////////// // Reflection render target /////////////////////////// mpReflectionRenderTexture = new CRenderTexture(); if (!mpReflectionRenderTexture->Initialise(device, screenWidth, screenHeight, DXGI_FORMAT_R8G8B8A8_UNORM)) { logger->GetInstance().WriteLine("Failed to initialise the reflection render texture."); return false; } /////////////////////////// // Height map render target /////////////////////////// mpHeightRenderTexture = new CRenderTexture(); if (!mpHeightRenderTexture->Initialise(device, screenWidth, screenHeight, DXGI_FORMAT_R32_FLOAT)) { logger->GetInstance().WriteLine("Failed to initialise the height render texture."); return false; } logger->GetInstance().WriteLine("Successfully loaded the texture for the water model."); return true; }
/* Create an instance of the grid so that it is ready to be rendered. */ bool CTerrain::CreateTerrain(ID3D11Device* device) { bool result; // Set the width and height of the terrain. if (mWidth == NULL) { mWidth = 100; } if (mHeight == NULL) { mHeight = 100; } mpWater = new CWater(); if (!mpWater->Initialise(device, D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DXVECTOR3(mWidth - 1.0f, 0.0f, mHeight - 1.0f), 200, 200, "Resources/Textures/WaterNormalHeight.png", mScreenWidth, mScreenHeight)) { logger->GetInstance().WriteLine("Failed to initialise the body of water."); return false; } // Initialise the vertex buffers. result = InitialiseBuffers(device); // If we weren't successful in creating buffers. if (!result) { // Output error to log. logger->GetInstance().WriteLine("Failed to initialise buffers in Terrain.cpp."); return false; } return true; }
AdvImageLayout::AdvImageLayout(AdvImageSection* imageSection, unsigned char layoutId, unsigned int width, unsigned int height, unsigned char dataBpp, FILE* pFile) { m_ImageSection = imageSection; LayoutId = layoutId; Width = width; Height = height; Compression = NULL; DataBpp = dataBpp; unsigned char version; fread(&version, 1, 1, pFile); if (version >= 1) { fread(&Bpp, 1, 1, pFile); unsigned char numTags; fread(&numTags, 1, 1, pFile); m_LayoutTags.clear(); for(int i = 0; i < numTags; i++) { char* tagName = ReadString(pFile); char* tagValue = ReadString(pFile); AddOrUpdateTag(tagName, tagValue); delete tagName; delete tagValue; } } InitialiseBuffers(); }
bool StaticMeshComponent::Initialise(ID3D11Device* device, char* modelFilename, WCHAR* textureFilename) { bool result; result = LoadModel(modelFilename); if (!result) { return false; } result = InitialiseBuffers(device); if (!result) { return false; } result = LoadTexture(device, textureFilename); if (!result) { return false; } return true; }
bool CTerrain::UpdateBuffers(ID3D11Device * device, ID3D11DeviceContext* deviceContext, double ** heightMap, int newWidth, int newHeight) { mUpdating = true; if (mpHeightMap) { ReleaseHeightMap(); } if (mpTerrainTiles != nullptr) { for (int i = 0; i < mHeight; ++i) { delete[] mpTerrainTiles[i]; logger->GetInstance().MemoryDeallocWriteLine(typeid(mpTerrainTiles[i]).name()); mpTerrainTiles[i] = nullptr; } delete[] mpTerrainTiles; mpTerrainTiles = nullptr; logger->GetInstance().MemoryDeallocWriteLine(typeid(mpTerrainTiles).name()); } mHeight = newHeight; mWidth = newWidth; // Load the new data into our member vars. LoadHeightMap(heightMap); if (mpVertexBuffer) { mpVertexBuffer->Release(); mpVertexBuffer = nullptr; } if (mpIndexBuffer) { mpIndexBuffer->Release(); mpIndexBuffer = nullptr; } if (mpWater != nullptr) { mpWater->Shutdown(); delete mpWater; mpWater = nullptr; mpWater = new CWater(); if (!mpWater->Initialise(device, D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DXVECTOR3(mWidth - 1.0f, 0.0f, mHeight - 1.0f), 200, 200, "Resources/Textures/WaterNormalHeight.png", mScreenWidth, mScreenHeight)) { logger->GetInstance().WriteLine("Failed to initialise the body of water."); return false; } } mTreesInfo.clear(); mPlantsInfo.clear(); InitialiseBuffers(device); mUpdating = false; return true; }