Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Leprosy

Using bitmaps to generate heigh fields

This topic is 6505 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

Anyone know of a good tutorial to extract darkness intesity out of a bitmap to generate an array of heights? Using DX thanks Lep

Share this post


Link to post
Share on other sites
Advertisement
What do you mean extract darkness intensity. Just create is as a greyscale, black = lowest height, white = highest height.

*** Triality ***

Share this post


Link to post
Share on other sites
What do you mean extract darkness intensity. Just create it as a greyscale, black = lowest height, white = highest height.

*** Triality ***

Share this post


Link to post
Share on other sites
Well, since a bitmap is basicly a matrix. Tranforming a bitmap into a height map is relitivly simple.


  
// Heres What You Need To Declare

struct BGRENTRY // RGB bitmaps are realy in BGR order, don''t ask why

{
UCHAR byBlue;
UCHAR byGreen;
UCHAR byRed;
};

UCHAR *byImgData; // This Contains Data From The Bitmap (RGB encoded)

BGRENTRY Bitmap;
float *fHeightMap;

// LOAD BITMAP DATA INTO byImgData (Source Not Included)

// FROM NOW ON, bmpdata WILL SPECIFY DATA TO BE TAKEN FROM THE

// BITMAPS HEADER


bitmap = new(BGRENTRY [bmpdata.width] [bmpdata.height]); // Syntax Error?


for (int i, j = 0; i <= (bmpdata.width - 1) && j <= (bmpdata.height - 1); )
{
bitmap<i>[j].blue = byImgData[(i * 3) + 0];
bitmap[i][j].green = byImgData[(i * 3) + 1];
bitmap[i][j].red = byImgData[(i * 3) + 2];

if (i < (bmpdata.width - 1))
{
i++;
}
else if (i = (bmpdata.width - 1))
{
j = j + 1;
i = 0;
}
else
{
//This Would Be Bad News

//BAIL!!

}

}

fHeightMap = new(float [bmpdata.width][bmpdata.height]);

// THE FOLLOWING SECTION NEEDS A FUNCTION float Value(UCHAR byNumber)

// THIS NUMBER SHOULD TAKE A HEX NUMBER AND MAKE IT INTO A FLOAT

// SORRY I DON''T HAVE TIME TO INCLUDE IT


for (i, j = 0; i <= (bmpdata.width - 1) && j <= (bmpdata.height - 1)<img src="wink.gif" width=15 height=15 align=middle>
{
fHeightMap[i] [j] = ( (Value(bitmap[i] [j]) * Value(bitmap[i] [j]) * Value(bitmap[i] [j]))/ 3);


if (i < (bmpdata.width - 1))
{
i++
}
else if (i = (bmpdata.width - 1))
{
j = j + 1
i = 0;
}
else
{
//This Would Be Bad News

//BAIL!!

}
}



That should be it. It should create a X by Y Matrix of floats. The floats will be a adverage of the Red, Green and Blue Values. Which means (255, 255, 255) will return 255. This means that color bitmaps will work as well as black and white bitmaps.

Good Enough?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!