Sign in to follow this  

Image data reading function with directX

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this