Hey,
I am facing unknown problem with the below code. Although, I tried debug to find the bug, but all in vain..
So, here is my code
///////////N_TIMES = 6 Global Variable,D3DCOLOR Sprite_Car [ Car_Width * Car_Height ],Car_Width = 1376,Car_Height = 768////////////////
struct Sprite
{
int width;
int height;
D3DCOLOR key;
D3DCOLOR* surface;
};
struct BitmapFileHeader
{
unsigned int fileSize;
unsigned short reserved1, reserved2;
unsigned int offsetToPixelData;
};
struct BitmapInfoHeader
{
unsigned int headerSize;
int width,height;
unsigned short planes;
unsigned short bits;
unsigned int compression;
unsigned int imageSize;
int xResolution,yResolution;
unsigned int nColors;
unsigned int importantColours;
};
struct Pixel24
{
unsigned char blue;
unsigned char green;
unsigned char red;
};
for(int j=0;j<N_TIMES;j++)
{
Car[j].width = Car_Width;
Car[j].height = Car_Height;
Car[j].key=D3DCOLOR_XRGB(255,0,0);
}
for(int u=0;u<N_TIMES;u++)
{
D3DCOLOR Sprite_Car[ Car_Width * Car_Height ];
Car[u].surface = Sprite_Car ;
LoadImageBmp("Shapes\\img3.bmp",Car[u].surface,u);
}
void LoadImageBmp( const char* filename,D3DCOLOR* surface ,int ImgPart)
{
FILE* bmpFile = fopen( filename,"rb" );
char signature[ 2 ];
fread( signature,sizeof( char ),2,bmpFile );
assert(signature[ 0 ] == 'B' && signature[ 1 ] == 'M');
BitmapFileHeader fileHeader;
fread( &fileHeader,sizeof( fileHeader ),1,bmpFile );
BitmapInfoHeader infoHeader;
fread( &infoHeader,sizeof( infoHeader ),1,bmpFile );
fseek( bmpFile,fileHeader.offsetToPixelData,SEEK_SET );
int nPaddingBytesPerRow = (4 - ((infoHeader.width * 3) % 4)) % 4;
for(int i=0;i<N_TIMES;i++)
{
for( int y = ((infoHeader.height)/N_TIMES)-1; y >= 0; y-- )
{
for( int x = 0; x < infoHeader.width; x++ )
{
Pixel24 pixel;
fread( &pixel,sizeof( pixel ),1,bmpFile );
if( i == ImgPart )
{
surface[ (x + y * (infoHeader.width)) ] = D3DCOLOR_XRGB( pixel.red,pixel.green,pixel.blue );
}
}
fseek( bmpFile,nPaddingBytesPerRow,SEEK_CUR );
}
}
fclose( bmpFile );
}
In main or ComposeFrame() func.
for(int i=N_TIMES-1;i>=0;i--)
{
gfx.DrawSprite(0,sum,&Car[i]);
sum +=128;
}
The function above load images pixel in D3DCOLOR Sruface [Car_Width*Car_Height], the DWORD D3DCOLOR Surface doesnot load pixel of higher resolution images, so, I convert the Image into patches and then tried to load the same image in 6 different Car[i].surface.
Check the result after compiling the code,
https://www.dropbox.com/s/y706vqbghpga6zx/img.jpg[
^]
and the orgional image was
https://www.dropbox.com/s/mtrgww3sf85f0xd/Img2.bmp?m[
^]
I am taking patches of pixel in 6 different Car[i].surface but the same pixel loads again and again
Any help plz.............