Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

elis-cool

Loaded BMP screwing up... yes I am doing the padding :)

This topic is 5923 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

it like appears twice, on one side its half the size of the bmp - horizontaly... and then the top appears at twice the size over the top of it... the image is 200x200 as is the back surface...
   
#define RGB32(R, G, B) ((0 <<32) | (R << 16) | (G << 8) | (B))


LPDIRECTDRAWSURFACE4 LoadGameBitmap(char *filename)
{   
	BITMAPINFOHEADER infoheader;  
	DDSURFACEDESC2   surfaceDesc; 
	LPDIRECTDRAWSURFACE4 NewSurface;
	DWORD             *bitmapData;  
	DWORD             *bitmapDone;   
	FILE             *bitmapFile;   
	BYTE             red, green, blue; 
	int padding;
	
	bitmapFile = fopen(filename, "rb");
	fseek(bitmapFile, sizeof(BITMAPFILEHEADER), SEEK_SET);  
	fread(&infoheader, sizeof(BITMAPINFOHEADER), 1, bitmapFile); 
	// get the padding at the end of the bitmap   

	padding = 4 - ((infoheader.biWidth * 3) % 4);   
	if(padding == 4) padding = 0;
	
	ZeroMemory(&surfaceDesc, sizeof(surfaceDesc));  
	surfaceDesc.dwSize = sizeof(surfaceDesc);  
	surfaceDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;  
	surfaceDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;  
	surfaceDesc.dwWidth = infoheader.biWidth;
	surfaceDesc.dwHeight = infoheader.biHeight;

	if(FAILED(g_pDDraw4->CreateSurface(&surfaceDesc, &NewSurface, NULL)))
	{
		MessageBox(g_hwnd, "NewSurface Failed", "ERROR", MB_ICONSTOP | MB_OK);
		Log("NewSurface Failed");
		return false;
	}

	ZeroMemory(&surfaceDesc, sizeof(surfaceDesc));  
	surfaceDesc.dwSize = sizeof(surfaceDesc);  
	NewSurface->Lock(NULL, &surfaceDesc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); 
	bitmapData = new DWORD[infoheader.biWidth * infoheader.biHeight];  
	bitmapDone = (DWORD *)surfaceDesc.lpSurface;   
	for( int y=0; y<infoheader.biHeight; ++y)  
	{     
		for( int x=0; x<infoheader.biWidth; ++x)     
		{        
			fread(&blue, sizeof(BYTE), 1, bitmapFile);     
			fread(&green, sizeof(BYTE), 1, bitmapFile);        
			fread(&red, sizeof(BYTE), 1, bitmapFile);      
			bitmapData[y*infoheader.biWidth + x] = RGB32(red, green, blue);   
		}   
		// skip past the padding in the file      

		fseek(bitmapFile, padding, SEEK_CUR);
	}   
	
	int heightIndex = 0;	
	for( y=infoheader.biHeight-1;  y>=0; --y)   
	{      
		for( int x=0; x<infoheader.biWidth; ++x)         
			bitmapDone[heightIndex*(surfaceDesc.lPitch/2) + x] = bitmapData[y*infoheader.biWidth + x];       
			++heightIndex;   
	}   
	delete bitmapData;
	NewSurface->Unlock(NULL);
	fclose(bitmapFile);
	return NewSurface;
}

g_pBack->Blt(0, g_pSkin, 0, DDBLT_WAIT, &ddbltfx);
  
CEO Plunder Studios

Share this post


Link to post
Share on other sites
Advertisement
Thanks man your my hero! I had nearly given up there after spending the last hour and a half tinkering with every other peice of code I had... I thought I had narrowed it down to me having the size of the surface wrong as windows was over taking shit and so it would have been stretching it smaller... but O well!! I thought I had gotten to everything in that function... I guess it was sorta hard to see...

CEO Plunder Studios

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!