[SOLVED] strange texture blitting

Started by
1 comment, last by stenny 17 years, 6 months ago
hello! I'm creating a graphics core for my engine and I have landed at the texture blitting part. At first the draw function of my ID3DXSprite didn't work but after some trial and error it did. When I debug through my code it dóes say it is correct, but when I execute my app I see this: Of course, this isn't the real texture I want to blit. But this is: Why doesn't it show correctly? I've already walked through the blit function itself with a friend of mine, the texture's size is a power of 2...I'm out of ideas! Here are my texture load- and blitfunctions:

BOOL cTexture::Load(cGraphics *Graphics, char *Filename, DWORD Transparent, D3DFORMAT Format)
{
	Free();

	if((m_Graphics = Graphics) == NULL) { return FALSE; }
	if(Graphics->GetDeviceCOM() == NULL) { return FALSE; }
	if(Filename == NULL) { return FALSE; }

	if(FAILED(D3DXCreateTextureFromFileEx(Graphics->GetDeviceCOM(), Filename, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0,
										  Format, D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE, D3DX_FILTER_TRIANGLE, Transparent,
										  NULL, NULL, &m_Texture)))
	{ return FALSE; }

	m_Width = GetWidth();
	m_Height = GetHeight();

	return TRUE;
}


and

BOOL cTexture::Blit(long DestX, long DestY, long SrcX, long SrcY, long Width, long Height, float XScale, float YScale, D3DCOLOR Color)
{
	RECT Rect;
	ID3DXSprite *pSprite;
	D3DXMATRIX	matTemp;

	if(m_Texture == NULL) { return FALSE; }
	if(m_Graphics == NULL) { return FALSE; }
	if((pSprite = m_Graphics->GetSpriteCOM()) == NULL) { return FALSE; }
	if(!Width) { Width = m_Width; }
	if(!Height) { Height = m_Height; }

	Rect.left = SrcX;
	Rect.top = SrcY;
	Rect.right = Rect.left + Width;
	Rect.bottom = Rect.top + Height;

	D3DXMatrixIdentity(&matTemp);
	D3DXMatrixScaling(&matTemp, XScale, YScale, 1.0f);

	if(FAILED(pSprite->SetTransform(&matTemp))) { return FALSE; }

	if(FAILED(pSprite->Draw(m_Texture,
							&Rect,
							NULL,
							&D3DXVECTOR3(DestX, DestY, 0.0f),
							Color)))
	{
		return FALSE;
	}

	return TRUE;
}


If you want more code, please ask! I really haven't got a clue anymore! -Stenny [Edited by - stenny on October 8, 2006 12:48:07 PM]
What do I expect? A young man's quest to defeat an evil sorceror while discovering the truth of his origins. A plucky youngster attended by her brutish guardian. A powerful artifact which has been broken into a small number of artifactlets distributed around the world.What do I want? Fewer damn cliches. - Sneftel
Advertisement

1. Could you post some of the code that calls cTexture::Blit() or provide an example of the values for the parameters (particularly source coordinates, scaling factors and colour value).

- if the alpha value of 'Color' was 0, then the sprite texture colour would be modulated with 0 and fail the alpha test that's set when you draw sprites (see the docs for ID3DXSprite::Begin.

- a source rectangle that was out of range could cause the call to fail (though the debug version of D3DX [d3dx9d.lib] should have told you this).

- a source scale of 0 (or a negative scale) would give you problems.



2. Also, could you post the flags (if any) you pass to ID3DXSprite::Begin. For example have you asked for anything like D3DXSPRITE_DONOTMODIFY_RENDERSTATE ?



3. Looking away from the sprites themselves, have you rememebered to Clear, and what flags/parameters do you pass to IDirect3DDevice9::Clear() ?

- I'd suggest trying D3DCLEAR_ZBUFFER (as well as D3DCLEAR_TARGET if you actually want the colour buffer cleared). Z buffer testing is still enabled for sprites - if you haven't cleared the Z buffer, what will be tested against is whatever was in memory when the device/depth buffer was created - which could be random crap.

- set the Z parameter for Clear() to 1.0f so that the existing contents are as far away from the camera/eye as possible before rendering the sprites (so that all the sprites are guaranteed to be closer and so pass the Z buffer test).

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

Yes! Thank you! The problem layed in the ID3DXSPrite->Begin() function! I didn't know what to enter there (and the msdn what damn vague), so I put in billboard. I deleted that and put a 0, and it worked!

Can someone please explain what the basic flags are I'll need to pass to begin, to have blitting work? Or is simply none of them enough?

-Stenny
What do I expect? A young man's quest to defeat an evil sorceror while discovering the truth of his origins. A plucky youngster attended by her brutish guardian. A powerful artifact which has been broken into a small number of artifactlets distributed around the world.What do I want? Fewer damn cliches. - Sneftel

This topic is closed to new replies.

Advertisement