Bmp Loading! fucktion just dont want to work!

Started by
2 comments, last by snoddas14 16 years, 10 months ago
i have allways hated Bmp and 2D games and now i just gona tell you why, becus its allways going bad for me! here is the problem. at the first time i wrote my code down and all that stuff, then when i started it. no debug errors but no pictur is show´n on my screen. (problem nr1) then i wrote a debug system for it. and now i get 3 errors.

/*************************
Render Class Code
*************************/


bool Update::StartRender()
{
	IDirect3DSurface9* sSurface=NULL;
	IDirect3DSurface9* BackBuffer=NULL;
	gDev->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_RGBA(0,0,0,0),1.0f,0);
	hr = gDev->GetBackBuffer(0,1,D3DBACKBUFFER_TYPE_MONO,
		&BackBuffer);
	if(FAILED(hr))
	{
		MessageBox(NULL,"4:0 cant do 'GetBackBuffer' chek the kode pleas","eRRoR",MB_OK);
		return false;
	}

/PROBLEM nr 2 i get this error all the time!/
	hr = gDev->StretchRect(ppSurface,NULL
		,BackBuffer,
		NULL, D3DTEXF_NONE);
	if(FAILED(hr))
	{
		MessageBox(NULL,"3:0 cant strech look at funktion","eRRoR",MB_OK);
		return false;
	}
	return true;
}

void Update::StopRender()
{
	gDev->Present(NULL,NULL,NULL,NULL);
}

/*************************
The Picture loading Code
*************************/

void Surface::LoadBG(UINT WiD, UINT HeI, D3DFORMAT FMT,const char* filename,D3DCOLOR Transp)
{
/problem nr 3 i allso get this problem all the time!/
	hr = gDev->CreateOffscreenPlainSurface(WiD, HeI, FMT, D3DPOOL_MANAGED, &ppSurface, NULL);
	if(FAILED(hr))
	{
		MessageBox(NULL,"5:0 cant do 'Create offscreen plain surface' cheek the code","eRRoR",MB_OK);
	}
/problem nr 4 its the same as the other two/
	hr = D3DXLoadSurfaceFromFile(ppSurface, NULL,NULL,filename,NULL,D3DX_DEFAULT,Transp,NULL);
	if(FAILED(hr))
	{
		MessageBox(NULL,"6:0 Cant do 'LoadfromSurface' cheek code","eRRoR",MB_OK);
	}

}

my problems (2-4) are that i get the debug error about them and its only made for if the code is invalid! if some one out there got a solution pleas help me. if some one out there dident understand my words. ask again and i will try to exaplin better next time!
Advertisement
First, here's how to find out what is wrong:

1) Use the debug Direct3D runtime (see the DirectX Control Panel in the Utilities folder of the SDK). Run your application in the debugger. When D3D returns D3DERR_INVALIDCALL (or any other error), look at the Output window of the debugger.

If an error has been returned from a D3D function and the debug runtime is enabled, details of why you got the error will be output to the debugger.


2) Link with D3DX9D.LIB instead of D3DX9.LIB. Again, run your application in the debugger. Check the output window of the debugger. If any D3DX function failed, more details will be output to the debugger.



Second, looking at your code:

Problem #3: The SDK documentation for CreateOffscreenPlainSurface() says "D3DPOOL_MANAGED is not allowed when creating an offscreen plain surface.. So you will get an error because you're asking D3D to do something which it can't do.

Problem #4: because the surface failed to create (problem #3), you will be passing a bad pDestSurface pointer to D3DXLoadSurfaceFromFile() so it will fail with D3DERR_INVALIDCALL or D3DXERR_INVALIDDATA.

Problem #2: because the surface failed to create (problem #3) or load (problem #2), the ppSurface pointer you pass to StretchRect() is bad/invalid so it too will fail with D3DERR_INVALIDCALL.

Problem #1: because all your D3D calls are failing, you won't see anything on screen.


The debug features built into Direct3D and D3DX are designed to help you debug these kinds of problems. While you are developing, always follow steps 1 and 2 at the top of this post. Only use the retail runtimes/D3DX when you're finished or need to profile.

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

And what about:

D3DXCreateTextureFromFileEx( g_pd3dDevice,
"mybmp.bmp",
D3DPOOL_DEFAULT,
D3DPOOL_DEFAULT,
1, // Don't create mip-maps
D3DPOOL_DEFAULT,
D3DFMT_UNKNOWN,
D3DPOOL_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
NULL,
&d3dxImageInfo,
NULL,
&g_pTexture);
S1CA: your the danm first persons who got a Freaking Fu*king good Explanation!
and thanks again! you descibed it so danm good!

This topic is closed to new replies.

Advertisement