Jump to content
  • Advertisement
Sign in to follow this  

[SOLVED] strange texture blitting

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

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)

	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,
										  NULL, NULL, &m_Texture)))
	{ return FALSE; }

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

	return TRUE;

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;

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

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

							&D3DXVECTOR3(DestX, DestY, 0.0f),
		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]

Share this post

Link to post
Share on other sites

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).

Share this post

Link to post
Share on other sites
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?


Share this post

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

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!