Note that there are some explanatory texts on larger screens.

plurals
  1. POReading in a BMP Heightmap
    text
    copied!<p>I am trying to load in a height map using C++ with DirectX. As a test I created a BMP file that is all black, so the terrain should be flat. Part of the edge is not flat though. Can anyone tell me why?</p> <pre><code>BITMAPFILEHEADER bitmapFileHeader; BITMAPINFOHEADER bitmapInfoHeader; ifstream bitmapFile("heightMap.bmp", ios::binary); if (!bitmapFile) return; // Read in file header. bitmapFile.read((char*)&amp;bitmapFileHeader, sizeof(BITMAPFILEHEADER)); // Read in the bitmap info header. bitmapFile.read((char*)&amp;bitmapInfoHeader, sizeof(BITMAPINFOHEADER)); int width = bitmapInfoHeader.biWidth; int height = bitmapInfoHeader.biHeight; unsigned char* bitmapImage = new unsigned char[width * height * 3]; bitmapFile.seekg(bitmapFileHeader.bfOffBits, ios::beg); // Store the image data. bitmapFile.read((char*)bitmapImage, width * height * 3); int numCellsWide = 200; int numCellsHigh = 200; int numVerticesWide = numCellsWide + 1; int numVerticesHigh = numCellsHigh + 1; numberVertices = (numCellsWide + 1) * (numCellsHigh + 1); numberTriangles = numCellsWide * numCellsHigh * 2; int cellWidth = 1; int cellHeight = 1; // Create the terrain vertices. Vertex* vertices = new Vertex[numberVertices]; int k = 0; for (int z = 0; z &lt; numVerticesHigh; z++) { for (int x = 0; x &lt; numVerticesWide; x++) { int index = z * numVerticesWide + x; vertices[index].x = x * cellWidth; vertices[index].y = (float)bitmapImage[k]; vertices[index].z = z * cellHeight; vertices[index].tu = vertices[index].x / (numCellsWide * cellWidth); vertices[index].tv = vertices[index].z / (numCellsHigh * cellHeight); k += 3; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload