Skip to main content
gamedev.net
🔒 Locked

IDirect3DTexture9::Draw problem

Started by startreky498 Jan 6, 2005 at 9:04 PM 5 replies 1.2k views
Original Post
startreky498
startreky498
Using DirectX 9 SDK December 2004 I'm trying to get a sprite to blit itself to the screen. However, even though the code seems to be ok, nothing shows up. I've done away with background images, which just leaves the original blue surface that comes up when I call pd3dDevice::Clear. So here's the code: void Render(void) { if( NULL == pd3dDevice ) return; // Clear the backbuffer to a blue color pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0); IDirect3DSurface9* backbuffer = NULL; HRESULT hResult = pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer); //SPRITE CODE D3DXCreateTextureFromFile(pd3dDevice,"./Mario",&pTexture); D3DXCreateSprite(pd3dDevice, &pSprite); RECT rSource; rSource.top = 0; rSource.bottom = 54; rSource.left = 0; rSource.right = 32; D3DXVECTOR3 vCenter ( 0.0f, 0.0f, 0.0f); D3DXVECTOR3 vPos (0.0f, 0.0f, 0.0f); pSprite->Begin( D3DXSPRITE_ALPHABLEND ); pSprite->Draw(pTexture, &rSource, &vCenter, &vPos, 0); pSprite->End(); // Present the backbuffer contents to the display pd3dDevice->Present(NULL, NULL, NULL, NULL); } My first assumption is that maybe my problem has something to do with lack of reference to the backbuffer on the ::Draw function, however I haven't found a suitable replacement. Also keep in mind that I've also tried this with the D3DXCreateTextureFromFileEx to no avail. No idea what's going on. anyone have any ideas?
Namethatnobodyelsetook
Namethatnobodyelsetook
Do you call BeginScene() and EndScene() somewhere? Nothing is allowed to draw except between those two calls. You should do Clear(), BeginScene(), Draw()*n, EndScene(), Present(). I suggest installing and/or enabling the debug runtimes. If you were using the debug runtimes (optional install during SDK installation, selectable via control panel) D3D would have let you know exactly what the problem was.
startreky498
startreky498
Hmm... did that, still nothing is drawing.

void Render(void)
{
if( NULL == pd3dDevice )
return;

// Clear the backbuffer to a blue color
pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0);

pd3dDevice->BeginScene();

IDirect3DSurface9* backbuffer = NULL;
HRESULT hResult = pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer);

//SPRITE CODE
D3DXCreateTextureFromFile(pd3dDevice,"./Mario",&pTexture);
D3DXCreateSprite(pd3dDevice, &pSprite);

RECT rSource;
rSource.top = 0;
rSource.bottom = 54;
rSource.left = 0;
rSource.right = 32;

D3DXVECTOR3 vCenter ( 0.0f, 0.0f, 0.0f);
D3DXVECTOR3 vPos (0.0f, 0.0f, 0.0f);

pSprite->Begin( D3DXSPRITE_ALPHABLEND );
pSprite->Draw(pTexture, &rSource, &vCenter, &vPos, 0);
pSprite->End();


// Present the backbuffer contents to the display
pd3dDevice->EndScene();
pd3dDevice->Present(NULL, NULL, NULL, NULL);
}

Nothing's drawing. Still, the Surfaces that I drew before managed to draw without the BeginScene and EndScene functions.

Any other ideas?
eviltwigflipper
eviltwigflipper
You sure that this is right?

D3DXCreateTextureFromFile(pd3dDevice,"./Mario",&pTexture);

Looks like your texture name does not have a extension.
startreky498
startreky498
Quote:
Original post by crozzbreed23
You sure that this is right?

D3DXCreateTextureFromFile(pd3dDevice,"./Mario",&pTexture);

Looks like your texture name does not have a extension.


I'll admit, it's hard for one to proof read his own work, I guess. But unfortunately, that didn't do it...

void Render(void){	if( NULL == pd3dDevice )        return;    // Clear the backbuffer to a blue color	pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0);	pd3dDevice->BeginScene();		IDirect3DSurface9* backbuffer = NULL;	HRESULT hResult = pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer);	if (FAILED(hResult))		MessageBox(NULL,"get backbuffer failed", "error", MB_OK);	if (backbuffer == NULL || bkgrd == NULL)		MessageBox(NULL,"null value", "error", MB_OK);	//hResult = pd3dDevice->StretchRect(bkgrd, NULL, backbuffer, NULL, D3DTEXF_NONE);	if (FAILED(hResult))		MessageBox(NULL,"stretch failed", "error", MB_OK);	//SPRITE CODE	D3DXCreateTextureFromFile(pd3dDevice,"mario.bmp",&pTexture);	D3DXCreateSprite(pd3dDevice, &pSprite);	RECT rSource;	rSource.top = 0;	rSource.bottom = 54;	rSource.left = 0;	rSource.right = 32;	D3DXVECTOR3 vCenter ( 0.0f, 0.0f, 0.0f);	D3DXVECTOR3 vPos (0.0f, 0.0f, 0.0f);	pSprite->Begin( D3DXSPRITE_ALPHABLEND );	pSprite->Draw(pTexture, &rSource, &vCenter, &vPos, 0);	pSprite->End();	// Present the backbuffer contents to the display	pd3dDevice->EndScene();	pd3dDevice->Present(NULL, NULL, NULL, NULL);}


Edited by Coder: Source tags are cool. Check GDNet Forums FAQ

[Edited by - Coder on January 6, 2005 10:24:00 PM]
startreky498
startreky498
Ok, maybe this is a better idea: does anyone know of a good 2D tutorial or some kind of working documentation on getting the ID3DXSprite::Draw function to work? Thanks.
eFoDay
eFoDay
you shouldnt be creating a new texture and sprite every single frame
also make sure your texture name is correct

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.