DirectX Effect.fx HELP!!

Started by
7 comments, last by JohnnyCode 14 years, 1 month ago
i started to learn how to do shader and effect. now, i try to load effect file but i got error

void render()
{

	g_pEffect->SetTechnique( "TwoPassTextureBlend" );
	g_pEffect->SetTexture( "texture0", g_pTexture_0 );
	g_pEffect->SetTexture( "texture1", g_pTexture_1 );

	UINT uPasses;
	g_pD3DDevice->SetStreamSource( 0, g_pVertexBuffer, 0, sizeof(Vertex) );
    g_pEffect->Begin( &uPasses, 0 );
    
    for( UINT uPass = 0; uPass < uPasses; ++uPass )
    {
        g_pEffect->BeginPass( uPass );
	g_pD3DDevice->SetFVF( D3DFVF_CUSTOMVERTEX );

	//here is the error-> g_pD3DDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 );

        g_pEffect->EndPass();
    }
 
    g_pEffect->End();

}

void initEffect( void )
{

	D3DXCreateTextureFromFile( g_pD3DDevice, "test.bmp", &g_pTexture_0 );
	D3DXCreateTextureFromFile( g_pD3DDevice, "checker.bmp", &g_pTexture_1 );

	HRESULT hr;
	LPD3DXBUFFER pBufferErrors = NULL;

	hr = D3DXCreateEffectFromFile( g_pD3DDevice, 
		                           "effect.fx",
		                           NULL, 
		                           NULL, 
		                           0, 
		                           NULL, 
		                           &g_pEffect, 
		                           &pBufferErrors );

	if( FAILED(hr) )
	{
		LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();
		MessageBox(NULL, (const char*)pCompilErrors, "Fx Compile Error",
			MB_OK|MB_ICONEXCLAMATION);
	}
}


error is written as "An exception occurred not handle " sorry if it is strange english because i do not use english version of visual studio . i wonder why this happen? and i plan to use effect file to edit Mesh's surface by loading .fx however, after i examined codes from many website.... it is not easy to setting effect. it is not as same as setting texture. am i right? can someone help? i am new to effect and shader system thank in advance [Edited by - fantasyme on March 9, 2010 5:41:33 AM]
Advertisement
Sounds like you have a null or invalid pointer. What is the exact error you get (Doesn't matter what language it's in)? What line does it occur on? Are you sure that your g_pEffect variable is valid (not NULL and not Release()d)?
Quote:Original post by Evil Steve
Sounds like you have a null or invalid pointer. What is the exact error you get (Doesn't matter what language it's in)? What line does it occur on? Are you sure that your g_pEffect variable is valid (not NULL and not Release()d)?


the error that i got when i try to open the program not when i complier the program. and there is a green arrow point to the line that i refered.(visual studio 2005) ,the message is exception handle....something like this.

i am new to effect system so i cannot understand what you mean.....sorry
maybe i use the complicated sample for learning effect.....
do you have any suggestion?
Quote:Original post by Evil Steve
Sounds like you have a null or invalid pointer. What is the exact error you get (Doesn't matter what language it's in)? What line does it occur on? Are you sure that your g_pEffect variable is valid (not NULL and not Release()d)?


the error that i got when i try to open the program not when i complier the program. and there is a green arrow point to the line that i refered.(visual studio 2005) ,the message is exception handle....something like this.

i am new to effect system so i cannot understand what you mean.....sorry
maybe i use the complicated sample for learning effect.....
do you have any suggestion?
In your first post you say you're trying to load an effect file but you get an error, but in the code you showed us you are actually not loading the effect, just trying to use it.
Are you sure you are creating the g_pEffect correctly, without any errors? Could you show us the code and also verify that the debug DirectX runtimes don't throw some errors?
Quote:Original post by Tom KQT
In your first post you say you're trying to load an effect file but you get an error, but in the code you showed us you are actually not loading the effect, just trying to use it.
Are you sure you are creating the g_pEffect correctly, without any errors? Could you show us the code and also verify that the debug DirectX runtimes don't throw some errors?


well, i edit code now and i spread the code because i want to
load texture and .fx just one time.

i am not sure about setting, it is my first time to try effect programming.
i just apply from what i saw in internet.
maybe i was wrong....
Quote:Original post by fantasyme
the message is exception handle....something like this.
What's the exact error message?

I didn't notice the comment there - in that case your device pointer is null - you've tried to load the effect before you've created your device, or creating the device has failed. Do the Debug Runtimes say anything useful? Have you actually called CreateDevice() before you call that code?
Yep, of course you should load the fx file only once, not every time you are about to use it. I just said you didn't show the code so we couldn't know whether you even had it there ;)
The rest of what I said still stays, anyway - is the code where you load the fx file working correctly?

EDIT:
Quote:Original post by Evil Steve
I didn't notice the comment there

I didn't either :)
-g_pEffect->SetTexture( "texture0", g_pTexture_0 );

should be called after Effect::begin or after Effect::BeginPass

-g_pD3DDevice->SetStreamSource( 0, g_pVertexBuffer, 0, sizeof(Vertex) );

just so, and I would for sure put it after vertex declaration is set with
g_pD3DDevice->SetFVF( D3DFVF_CUSTOMVERTEX );

generaly your render call looks like this

Effect::settechniqe
Effect::Begin
set declarations,bind streams,set textures,uniforms,states
Effect::CommitChanges
Effect::BeginPass
you can set render call variables here too
Effect::EndPass
Effect::End


This topic is closed to new replies.

Advertisement