ID3DXSprite trouble

Started by
4 comments, last by theMadHatter 17 years, 11 months ago
Hello. I am having some trouble with the ID3DXSprite stuff. I have this code and it errors with the Draw function. When I debug it it doesn't tell me anything about that error. I looked at the SDK and I'm almost positive all my parameters for Draw are correct. It must do with something earlier or something. So I'm asking if there is anything that seems like I'm doing wrong in this section of code.

void render(void)
{
	HRESULT hr;

	hr = pd3dDevice->BeginScene();
	if (FAILED(hr))
		MessageBox(NULL, "begine scene", "ERROR", MB_OK); 
	
	// check to make sure we have a valid Direct3D Device
	if( NULL == pd3dDevice )
        return;
	
	// Create texture to use with the pFront sprite
	hr = D3DXCreateTextureFromFile(pd3dDevice, "frontPage.bmp", &pFrontTex);
	if (FAILED(hr))
		MessageBox(NULL, "loading texture error", "ERROR", MB_OK);

	// Create the sprite pFront
	hr = D3DXCreateSprite(pd3dDevice, &pFront);
	if(FAILED(hr))
		MessageBox(NULL, "stupid sprite", "ERROR", MB_OK);

	hr = pd3dDevice->SetTexture(0, pFrontTex);
	if(FAILED(hr))
		MessageBox(NULL, "set texture", "ERROR", MB_OK);
	hr = pFront->Draw(pFrontTex, NULL, NULL, NULL, 0xFFFFFFFF);
	if(FAILED(hr))
		MessageBox(NULL, "draw", "ERROR", MB_OK);

	hr = pd3dDevice->EndScene();
	if (FAILED(hr))
		MessageBox(NULL, "end scene", "ERROR", MB_OK); 

	// Presenteth to el screen
    pd3dDevice->Present( NULL, NULL, NULL, NULL );
}

Advertisement
What does the debug runtime say about it? You mentioned that when you debug it, it doesn't give any info - however, have you enabled debug runtimes and checked the Output window of Visual Studio? Any time a function fails, you are almost guaranteed to get detailed feedback as to why it failed.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
... a couple things here...

you are calling render once per frame. so your code also creates a texture & creates a sprite object every frame.. thats not good..

you should have a load function that gets called once at the begining of the program.. in the load function you load a texture and create the sprite.

then rearage your render function like this

void Render(void){	if( !pd3dDevice )		return;			if( FAILED (pd3dDevice->BeginScene() ))		return;		// start sprite rendering	pFront->Begin( D3DXSPRITE_ALPHABLEND );		pFront->Draw(pFrontTex, NULL, NULL, NULL, 0xFFFFFFFF);		// end sprite rendering	pFront->End();	pd3dDevice->EndScene();	    	pd3dDevice->Present( NULL, NULL, NULL, NULL )}
Quote:you should have a load function that gets called once at the begining of the program.. in the load function you load a texture and create the sprite.

I actually had it like this I just moved them there for easy posting.
Next time I'll think twice :).

Alright when I make the addition of the Begin and End I get this

error LNK2001: unresolved external symbol "void __cdecl render(void)" (?render@@YAXXZ)

I'm pretty sure I have all the library and header files so I don't know what this is.

#pragma comment( lib, "d3dx9.lib" )
#include <d3dx9core.h>

Those are the only two needed for begin and end as far as I know and I have them.

And as for the debug after I get rid of this error and still no prevail I will try debugging it again and yeah.
Quote:
error LNK2001: unresolved external symbol "void __cdecl render(void)" (?render@@YAXXZ)


that means it cant find "your" render function... make sure your function declaration and implementation have the same name..

your function was called render.. but I posted it as Render..
Thank You. It now works.
Thanks.

This topic is closed to new replies.

Advertisement