Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ DirectX
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);
    }
 
/////////////////LoadImageBmp- Function//////////////////////
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.............
Posted 24-Jan-13 5:09am
saad_lah1.1K
Edited 24-Jan-13 5:15am
v2
Comments
Sergey Alexandrovich Kryukov at 24-Jan-13 14:47pm
   
What "doesn't load" means? Insufficient memory exception, something else?
—SA
saad_lah at 24-Jan-13 14:55pm
   
Load or you can to initialize data(pixels) in surface[car_width*car_height].
but the limit exceeds as the size(car_width*car_height) or resolution of image increase and I am unable to store pixel data in surface, So I tried to store image in patches of N_TIMES(6) in array of Sprite Car. Everything works fine when i try to display image individually, but when i try to make it general just like above, it keeps on print or displaying same patch of image again and again :(
merano at 24-Jan-13 18:50pm
   
Is there a reason why you dont use the MSDN declarations ?
 
http://msdn.microsoft.com/en-us/library/windows/desktop/dd318229(v=vs.85).aspx
 
http://msdn.microsoft.com/en-us/library/windows/desktop/dd183374(v=vs.85).aspx
saad_lah at 25-Jan-13 2:30am
   
@merano:: No, the struct BitmapInfoHeader and BitmapFileHeader is working fine..the porblem is with surface[...] which doesnot stores large number of pixels in it :(
Michael Haephrati at 3-Mar-13 14:00pm
   
Don't you need to allocate memory for Car[u].surface first?
saad_lah at 4-Mar-13 0:05am
   
yea,... and I have done the step here...in a for loop
D3DCOLOR Sprite_Car[ Car_Width * Car_Height ];
Car[u].surface = Sprite_Car ;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 515
1 Maciej Los 340
2 Richard MacCutchan 265
3 BillWoodruff 225
4 Mathew Soji 155
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411028.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100