Archived

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

hammerstein_02

DirectDraw Loading Image problem..

Recommended Posts

hammerstein_02    134
Ok, I have come to implement a tile system in my program, and I read through and array and load my tiles etc, loading a tile consists of
  
cTile * SpawnTile(LPSTR lpFileName, cGraphics *gfx)
{
	cTile	*tmp;

	tmp = new cTile(gfx);

	tmp->SetSurface(lpFileName);

	tmp->SetPos(0,0);
	tmp->SetLoaded(true);

	return(tmp);
}
  
this fails and my program stops, however if I comment out SetSurface(lpFilename) it works.. so I go deeper and SetSurface calls LoadBMPSurface ..
  
LPDIRECTDRAWSURFACE7 cGraphics::LoadBMPSurface(LPCSTR lpFilename)
{
	HDC						hDC;
	HBITMAP					bit;
	BITMAP					bitmap;
	LPDIRECTDRAWSURFACE7	surf;

	bit = (HBITMAP) LoadImage(NULL,lpFilename,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE | LR_LOADFROMFILE);

	if(!bit)
	{
		return(NULL); //Error trapping

	}

	if(GetObject(bit,sizeof(BITMAP),&bitmap) == NULL)
	{
		return(NULL);
	}

	surf = CreateNewSurface(bitmap.bmWidth,bitmap.bmHeight);

	if(surf == NULL)
	{
		logFile << "Failed to create surface";
		DeleteObject(bit);
		return(NULL); //More error trapping

	}
	else
	{
		surf->GetDC(&hDC);

		HDC bit_dc = CreateCompatibleDC(hDC);

		//Blit the interface to the surface


		SelectObject(bit_dc,bit);
			
		BitBlt(hDC,0,0,bitmap.bmWidth,bitmap.bmHeight,bit_dc,0,0,SRCCOPY);

		surf->ReleaseDC(hDC);

		DeleteDC(bit_dc);
	}

	DeleteObject(bit);

	return(surf);
}
  
Now I know the bitmap loading routine works because I can make a surface object using the graphics component and it works fine. And I have put logging in and it doesn''t fail at the LoadImage .. it just fails.. What I am asking is, am I missing something really stupid? Is there something I should be seeing that I am not. Hammerstein PS - The image is definatley named right, and definatley in the right place (I can manually load the image) =*= If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore =*=

Share this post


Link to post
Share on other sites
hammerstein_02    134
OK.. I have an insight..

Its failing to get the DC of the surface. Why would this be?

=*=
If things seem bad, think that they can get a whole load worse, and they don't seem so bad anymore

=*=

[edited by - hammerstein_02 on October 20, 2002 8:10:05 AM]

Share this post


Link to post
Share on other sites