Which is the Directx function to load bitmap for height maps
easiest way (use it with a 16 bit bitmap for best results)
open the file using fopen or whatever type of stream open function you prefer, then load the bitmapinfoheader and the bitmap info, then create a mesh from the loaded data.
i may be wrong (i dont know anything about the sample framework, it may be in there) but i dont believe there is any function to directly load a heightmap from a bitmap.
___________________
-Nicholas Anton, Owner RaptorTech
-Admin(at)Raptor85.com
open the file using fopen or whatever type of stream open function you prefer, then load the bitmapinfoheader and the bitmap info, then create a mesh from the loaded data.
i may be wrong (i dont know anything about the sample framework, it may be in there) but i dont believe there is any function to directly load a heightmap from a bitmap.
___________________
-Nicholas Anton, Owner RaptorTech
-Admin(at)Raptor85.com
I'm reluctant to do this, because this code screams COPY-PASTE ME, but here is code that'll load a bitmap for you.
This will return a pointer to the bitmap data, and will give you the width, height, and bit depth of the bitmap data via reference parameters. You'll then have to process that into a heightmap.
[edited by - Promit on April 13, 2004 10:07:03 PM]
#define WIN32_LEAN_AND_MEAN#include <windows.h>#include <cstdio>unsigned char* ReadBitmap( const char* FileName, int& Width, int& Height, int& bpp ){ BITMAPFILEHEADER Header; BITMAPINFOHEADER Info; FILE* fp; unsigned char* RawData; fp = fopen( FileName, "rb" ); if( fp== NULL ) { fclose( fp ); return NULL; } //read in the heightmap data fread( &Header, sizeof(Header), 1, pMap ); fread( &Info, sizeof(Info), 1, pMap ); fseek( pMap, Header.bfOffBits, SEEK_SET ); //notice these are all reference parameters Width = Info.biWidth; Height = Info.biHeight; bpp = Info.biBitCount; RawData = new unsigned char[Width*Height*bpp]; fread( RawData, 1, Width*Height*bpp, fp ); fclose( fp ); return RawData;}
This will return a pointer to the bitmap data, and will give you the width, height, and bit depth of the bitmap data via reference parameters. You'll then have to process that into a heightmap.
[edited by - Promit on April 13, 2004 10:07:03 PM]
Oh for gods sake, please don't use a new inside the function! Just make it return the data to a user defined pointer and let the function be made queryable so they can make the correct size buffer.
Usage:
Please note I didn't compile this so please don't flame me if something's a bit askew.
@Promit: Don't take it personally, I just have a personal thing with new inside of functions (who ever remembers to delete afterwards?)
EDIT: Promit, how did you get pretty spacing inside your [ source]? I've never been able to do that!
[edited by - ms291052 on April 13, 2004 10:40:58 PM]
#define WIN32_LEAN_AND_MEAN#include <windows.h>#include <cstdio>void ReadBitmap(unsigned char** RawData, const char* FileName, int* Width, int* Height, int* bpp ){BITMAPFILEHEADER Header;BITMAPINFOHEADER Info;FILE* fp;fp = fopen( FileName, "rb" );if( fp== NULL ){fclose( fp );return;}//read in the heightmap datafread( &Header, sizeof(Header), 1, pMap );fread( &Info, sizeof(Info), 1, pMap );fseek( pMap, Header.bfOffBits, SEEK_SET );//notice these are all reference parametersif(Width != NULL)Width = Info.biWidth;if(Height != NULL)Height = Info.biHeight;if(bpp != NULL)bpp = Info.biBitCount;if(RawData == NULL)return;fread( *RawData, 1, Info.biWidth*Info.biHeight*Info.biBitCount, fp );fclose( fp );}
Usage:
int Width=0, Height=0, bpp=0;unsigned char* BitmapInfo;//Query for Width, Height and BPPReadBitmap(NULL, "somefile.bmp", &Width, &Height, &bpp );//Create buffer for infoBitmapInfo = new unsigned char[Width*Height*bpp];//Read in infoReadBitmap(&BitmapInfo, "somefile.bmp", NULL, NULL, NULL);
Please note I didn't compile this so please don't flame me if something's a bit askew.
@Promit: Don't take it personally, I just have a personal thing with new inside of functions (who ever remembers to delete afterwards?)
EDIT: Promit, how did you get pretty spacing inside your [ source]? I've never been able to do that!
[edited by - ms291052 on April 13, 2004 10:40:58 PM]
First off, I don''t see any problem with using new inside a function as long as you make it pretty clear that somebody is going to have to delete it afterwards. Although my version of the code is actually inside a class whch deals with its pointers itself, so there''s no real need. Not to mention I don''t like the querying thing.
As for the pretty spacing, I used the space bar. A lot.
As for the pretty spacing, I used the space bar. A lot.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement