I got a Surface class, very simple, just containing Width,Height, the buffer(WORD) and a SetPixel function.
now I'm trying to load a bitmap to my surface, but I get really really weird results...
here is my code:
Can someone help me please?
I'm kind of stuck because of this...
the result I get is just a weird grayscale picture...
I think something is wrong when converting from 24bit to 16bit...
now I'm trying to load a bitmap to my surface, but I get really really weird results...
here is my code:
- Code:
WORD rgb(BYTE r,BYTE g,BYTE b)
{
return (WORD) (r & 0xff) << 11 | (g & 0xff)<< 6 | (b & 0xff);
}
Surface *Display::CreateSurfaceFromFile(const char *FileName)
{
Surface *pRetSurface;
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
RGBQUAD *pBits;
FILE *pFile=fopen(FileName,"rb");
if (!pFile)
return NULL;
fread(&bmfh,sizeof(bmfh),1,pFile);
fread(&bmih,sizeof(bmih),1,pFile);
fseek(pFile,bmfh.bfOffBits,SEEK_CUR);
pBits=new RGBQUAD[bmih.biWidth*bmih.biHeight];
fread(pBits,sizeof(RGBQUAD),bmih.biWidth*bmih.biHeight,pFile);
pRetSurface=new Surface(bmih.biWidth,bmih.biHeight);
long i=0;
for (long x=0;x<bmih.biWidth;x++)
{
for (long y=0;y<bmih.biHeight;y++)
{
BYTE R,G,B;
R=pBits[i].rgbRed;
G=pBits[i].rgbGreen;
B=pBits[i].rgbBlue;
pRetSurface->SetPixel(x,y,rgb(255,255,0));
i++;
}
}
fclose(pFile);
delete pBits;
return pRetSurface;
}
Can someone help me please?
I'm kind of stuck because of this...
the result I get is just a weird grayscale picture...
I think something is wrong when converting from 24bit to 16bit...