Jump to content
  • Advertisement
Sign in to follow this  
axv4745

Image data reading function with directX

This topic is 4834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to write a function that reads in the image data from an image and constructs heightmap data based on it. I previously wrote so that it only works if I read in RAW files. However, I would like to write it so that almost any fileformat would work. One attempt I made is listed below: bool Terrain::readHeightMapFile(string fileName) { //IDirect3DTexture9* myTex; //D3DXCreateTextureFromFile( // Renderer::getDeviceHandle(), // fileName.c_str(), // &myTex); //D3DLOCKED_RECT lockedRect; //myTex->LockRect(0,&lockedRect,0,0); //DWORD * imageData = (DWORD*)lockedRect.pBits; // copy image data to heightmap vector //heightmap.resize( totalVerts ); //int index = 0; //for(int i=0; i < totalVertsPerRow; i++ ) //{ // for(int j=0; j < totalVertsPerCol; j++) // { // heightmap[index] = imageData[i * lockedRect.Pitch / 4 + j]; // index ++; // } //} //myTex->UnlockRect(0); //myTex->Release(); } unfortunatley this does not produce the expected results because I tried it with a png heightmap file and then with the same file except in RAW format and "imageData[i * lockedRect.Pitch / 4 + j]" always seemed to produce values in the range of 4934562 (and as you would imagine this would produce really tall terrain). Considering that my heightmap files were mostly grayish,black, and white this is unexpected. I don't see any reason why this approach wouldn't work and I was hoping someone might know why "imageData[i * lockedRect.Pitch / 4 + j]" is producing such high values.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!