Original Post
Ok i solved my bitmap loading problem the other day... now im trying to only load part of the bitmap onto the surface.. so i can have templated bitmaps.The bitmap appears fuzzy, you can tell that the image is correct... but one of the values isnt... so it looks all skewed..
heres the code
I know i dont use cell yet, i want to get the first surface right. then i will advance along each cell
thanks for your help in advance.
btw - the bitmap im trying to load is 64x64
[edited by - ACAC on May 26, 2002 1:54:15 PM]
void CPlayer::Create(char *filename, int numcells, int cellw, int cellh)
{
this->cellw = cellw; this->cellh = cellh;
int num_bytes; // needed to store the amount of bytes
ifstream filestream;
filestream.open(filename, ios::in | ios::binary); // open the file ! :)
if(filestream.is_open())
{
//first read in some usefull info
filestream.seekg(0, ios::beg); // make sure were reading from the beggining
filestream.read((char*)&this->bitmapfile.bmfh, sizeof(BITMAPFILEHEADER));
filestream.read((char*)&this->bitmapfile.bmih, sizeof(BITMAPINFOHEADER));
// we have info LETS READ IN THE PIXELS BABY YEAH!
num_bytes = this->bitmapfile.bmih.biWidth * bitmapfile.bmih.biHeight;
num_bytes *= (this->bitmapfile.bmih.biBitCount/8);
this->bitmapfile.ByteAmount = num_bytes;
this->bitmapfile.BitmapBits = new BYTE[num_bytes]; // we have our byte array! :)
filestream.read((char*)&this->bitmapfile.BitmapBits[0], num_bytes);
// that was SO EASY DUDE!
filestream.close();
}
else
{
MessageBox(g_hWnd, "Could Not open bitmapfile!!", filename, MB_OK);
return;
}
//now we need to write it to a surface :S here goes!
DDSURFACEDESC2 ddsd;
DDCOLORKEY ck;
ck.dwColorSpaceHighValue = _16BIT(255,0,255); //pink is transparent
ck.dwColorSpaceLowValue = _16BIT(255,0,255);//pink is transparent
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = cellw;
ddsd.dwHeight = cellh;
DebugOut("The bitmap width is %d the height is %d", cellw,
cellh);
for(int index = 0; index < numcells; index++)
{
ErrorCheck(DDraw->GetInterface()->CreateSurface(&ddsd, &this->lpDDAnims[index], NULL), "Creating Surface");
ErrorCheck(this->lpDDAnims[index]->SetColorKey(DDCKEY_SRCBLT, &ck), "Colorkey");
}
for(int cell = 0; cell < numcells; cell++)
{
//now get the bitmap onto the surface
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ErrorCheck(this->lpDDAnims[cell]->Lock(NULL,&ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL),"lock Surface");
USHORT *vid_buf = (USHORT*)ddsd.lpSurface;
int lPitch = (ddsd.lPitch>>1);
int curbit = 0;
int cury = cellh;
int curx = 0;
int bytes = (cellw * cellh) * 3;
while(curbit < bytes)
{
vid_buf[(curx) + cury*lPitch] = _16BIT(this->bitmapfile.BitmapBits[curbit+2],this->bitmapfile.BitmapBits[curbit+1],this->bitmapfile.BitmapBits[curbit+0]);
curx++;
if(curx >= cellw)
{
DebugOut("Y is :%d",cury);
cury--;
curx = 0;
}
curbit+=3;
}
ErrorCheck(this->lpDDAnims[cell]->Unlock(NULL), "Unlock Surface");
}