Sign in to follow this  

Direct3D Sprites

This topic is 4677 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

I'm having some issues with Direct3D initially I was trying to do CopyRects and was a wierd error that said "Unhandled exception at 0x7c901230 in TankUClient.exe: User breakpoint." I have no user breakpoint there and it bombs out. So I went to a different angle of sprites and I and getting the same error. Here is my code; the globals were taken from my header and the rest is in my render section for the Direct 3D render. LPD3DXSPRITE g_pSprite; // Sprite Pointer LPDIRECT3DTEXTURE8 g_pTexture; // Texture Pointer
HRESULT hrD3DRender(D3DLOCKED_RECT *pTankRect, D3DLOCKED_RECT *pMapRect)
{
	HRESULT hReturn;
	LPDIRECT3DSURFACE8 pBackBuffer;
	
	
	
	D3DXVECTOR2 scaling;
	D3DXVECTOR2 rotation;
	D3DXVECTOR2 translation;
	D3DCOLOR color;

	scaling.x = scaling.y = 1.0f;
	rotation.x = rotation.y = 0.0f;
	translation.x = translation.y = 0.0f;
	color = D3DCOLOR_XRGB(255, 255, 255);


	D3DLOCKED_RECT LockedRect;


	//STEP 1 Clear the Back Buffer
	if(FAILED(g_pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0)))
		vShowText(hLB_Output, "Couldn't clear back buffer!");

	//STEP 2 Aquire a Pointer to the Back Buffer
	if(FAILED(g_pD3DDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer)))
		vShowText(hLB_Output, "Couldn't Get Back Buffer");

	//STEP 3 Lock The Back Buffer
	if(FAILED(pBackBuffer->LockRect(&LockedRect, NULL, 0)))
		vShowText(hLB_Output, "Could Not Lock the Back Buffer");

	//STEP 4 Rendering into the Back Buffer
	//Drawing to Buffer Code HERE
	DWORD *pData = (DWORD*)(LockedRect.pBits);
	DWORD *pMap = (DWORD*)(pMapRect->pBits);
	DWORD *pTank = (DWORD*)(pTankRect->pBits);


//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!SPRITE STUFF!!!!!!!!!!!!!!!!!!!!!!!!!

	hReturn = D3DXCreateTextureFromFile( g_pD3DDevice, "c:\\pix\\4man3.dds", &g_pTexture);
	if (FAILED (hReturn))
		vShowText(hLB_Output, "Failed to Create Texture");

	g_pTexture->AddRef();
	
	hReturn = D3DXCreateSprite(g_pD3DDevice, &g_pSprite);
	if (FAILED (hReturn))
	{
		vShowText(hLB_Output, "Sprite Creation FAILED");	
		return hReturn;
	}

	g_pSprite->Begin();
	hReturn = g_pSprite->Draw(g_pTexture, NULL, &scaling, &rotation, 0.0f, &translation, color);
	if (FAILED (hReturn))
	{
		vShowText(hLB_Output, "Sprite Rendering FAILED");	
		return hReturn;
	}


	g_pSprite->End();

	//STEP 5 Unlock The Back Buffer
	pBackBuffer->UnlockRect();

	//STEP 6 Release the Surface
	pBackBuffer->Release();
	pBackBuffer = 0;

	//STEP 7 Copy Back Buffer to the Primary Surface
	g_pD3DDevice->Present(NULL, NULL, NULL, NULL);



	return S_OK;
}


Share this post


Link to post
Share on other sites
1) try running the code in the debugger. When the breakpoint occurs, go to the call stack and look down it from the breakpoint until you see an entry for your application. The cause will be somewhere around there.


2a) if you haven't done already, enable the debug Direct3D runtime (see the forum FAQ), and crank the output level up.

2b) also, since you use D3DX functions, link with d3dx8d.lib instead of d3dx8.lib.

2c) run the application from the debugger and check the "Output" window when the error occurs - if Direct3D or D3DX are unhappy with anything, they'll give you some information about why they're unhappy.


3a) Check that you've not got the "Break on D3D Error" option checked in the DirectX control panel applet.

3b) Check that "Break on Memory Leak" isn't checked and the value in "Break on AllocId" is 0 too.

3c) Those, as their names suggest will cause a breakpoint when those situations occur.


4) You don't use the F12 key for anything do you? With NT based operating systems (Windows NT, Windows 2000, Windows XP, Windows Server 2003), if there's a debugger attached to your process, then pressing F12 causes an immediate breakpoint. This is simply a debugging "feature" of the NT kernel that people often find the hard way [wink]

Share this post


Link to post
Share on other sites
Quote:
Original post by S1CA
4) You don't use the F12 key for anything do you? With NT based operating systems (Windows NT, Windows 2000, Windows XP, Windows Server 2003), if there's a debugger attached to your process, then pressing F12 causes an immediate breakpoint. This is simply a debugging "feature" of the NT kernel that people often find the hard way [wink]
That's pretty neat. It also explains why my app suddenly broke to the debugger earlier today when I missed the Print Screen key. I spent 15 mins looking for invalid pointers and things, and never found anything...

You should really stick to the ID3DXSprite method if possible, since it'll be *considerably* faster than locking the backbuffer evey frame.

Share this post


Link to post
Share on other sites
Sign in to follow this