need help with Lesson 20

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Kenny
Posts: 2
Joined: June 5th, 2012, 5:57 pm
Location: Germany

need help with Lesson 20

Post by Kenny » June 6th, 2012, 12:10 pm

I wached Lesson 20 and managed to load the bmp, but the part with the PaddingBytes don't seem to change anything the dude is still fucked up and i have no idea where the error is.

Thanks in advance

P.S. thanks to Chili for the great tutorials.
Attachments
Sprites.zip
(77.05 KiB) Downloaded 161 times

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: need help with Lesson 20

Post by chili » June 6th, 2012, 12:27 pm

Hey bro, welcome to the board. Nice to see someone who can follow the rules and post their cleaned solution when asking a question. ;)


You have a bad habit of omitting the braces after control statements. For example:

Code: Select all

void D3DGraphics::DrawSurface( int xoff,int yoff,int width,int height,const D3DCOLOR* surf )
{
	for( int y = 0; y < height; y++ )
		for( int x = 0; x < width; x++ )
			PutPixel( x + xoff,y + yoff,surf[ x + y * width ] );
}
In this case there is no problem, but it's not good practice at all. Want to see why?
Look at this other code snipped from your solution (LoadBmp).

Code: Select all

for( int y = 0; y < infoHeader.height; y++ )
		for( int x = 0; x < infoHeader.width; x++ )			
		{
			Pixel24 pixel;
			fread( &pixel,sizeof( pixel ),1,bmpFile );
			surface[ x + y * infoHeader.width ] = D3DCOLOR_XRGB( pixel.red,pixel.green,pixel.blue );
		}
		fseek( bmpFile,nPaddingBytesPerRow,SEEK_CUR );
In this case, the y loop will only repeat the following x loop, and the fseek function call will not be called until after the y loop has completed.

You don't get any bonus points for shaving a couple of lines off your code, so save yourself some headaches and use the braces everytime ({}). ;)
Chili

Kenny
Posts: 2
Joined: June 5th, 2012, 5:57 pm
Location: Germany

Re: need help with Lesson 20

Post by Kenny » June 6th, 2012, 12:40 pm

Thanks, this error was really unnecessary :oops: i will try to make the braces every time in the future

Post Reply