Jump to content
  • Advertisement
Sign in to follow this  
dawchiks

I'm made of fail! cant load .fx

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

hey guys. yep, it looks liek i'm made of fail! im a programming noob and i cant load simple .fx file ( i've done it before, and it worked). since i havent programmed about half year i've forgotten a lot of things. ok. about the problem - i compile it, no errors, no nothing. when i open the .exe it throws out an error - bla.exe has stopped working. there is a .fx file whitch looks like this: (i didnt make it, just copied); texture texture0; texture texture1; technique TwoPassTextureBlend { pass Pass0 { AlphaBlendEnable = False; Texture[0] = <texture0>; ColorOp[0] = SelectArg1; ColorArg1[0] = Texture; ColorOp[1] = Disable; } pass Pass1 { AlphaBlendEnable = True; SrcBlend = One; DestBlend = One; Texture[0] = <texture1>; ColorOp[0] = SelectArg1; ColorArg1[0] = Texture; ColorOp[1] = Disable; } } and in my c++ project i implent these lines: LPD3DXEFFECT fx = NULL; void LoadFX() { D3DXCreateTextureFromFile(d3dDev,"test.bmp",&tex1); D3DXCreateTextureFromFile(d3dDev,"checker.bmp",&tex2); HRESULT hr; LPD3DXBUFFER pBufferErrors = NULL; hr = D3DXCreateEffectFromFile( d3dDev, "effect.fx", NULL, NULL, 0, NULL, &fx, &pBufferErrors ); if( FAILED(hr) ) { LPVOID pCompilErrors = pBufferErrors->GetBufferPointer(); MessageBox(NULL, (const char*)pCompilErrors, "Fx Compile Error", MB_OK|MB_ICONEXCLAMATION); } } void SetVariables() { fx->SetTexture("texture0",tex1); fx->SetTexture("texture1",tex2); } and whole Render : void Render(void) { d3dDev->Clear(0,NULL,D3DCLEAR_ZBUFFER|D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0); d3dDev->BeginScene(); Matrix(); static float index; index +=0.01f; D3DXMatrixRotationY(&Rotate,index); d3dDev->SetTransform(D3DTS_WORLD,&Rotate); fx->SetTechnique("TwoPassTextureBlend"); SetVariables(); UINT uPasses; fx->Begin(&uPasses,0); for(UINT uPass = 0;uPass<uPasses;uPass++) { fx->BeginPass(uPass); for(DWORD i=0;i<numMat;i++) { d3dDev->SetMaterial(&mat); if(tex !=NULL) d3dDev->SetTexture(0,tex); Mesh->DrawSubset(i); } fx->EndPass(); } fx->End(); d3dDev->EndScene(); d3dDev->Present(NULL,NULL,NULL,NULL); return; }

Share this post


Link to post
Share on other sites
Advertisement
First, make sure you're running a debug build. That way you'll break to the debugger and you can tell what line is causing the error and you can inspect the variables. Here is an excellent tutorial on using Visual Studio's debugger.

Secondly, make sure you're using the Debug Runtimes for Direct3D. They'll spew any errors to the debug output to help you track down any D3D functions failing.

Thirdly, make sure you check the return value for all D3D functions that create resources, return pointers, or fill in structures. For instance, you have two D3DXCreateTextureFromFile() calls you're not checking the return value of. If either fails, you'll have a null pointer, and that could cause problems.

Share this post


Link to post
Share on other sites
hmm, cant use debug runtimes. i cant select any of them. and if i try to debug application, it opens, and does nothing. just black screen. and i cant close it even with task manager, only by closing VCexpress.
but i can compile and run other samples who uses .fx files. so the problem is in the code :D


if it helps there is the whole code:
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <d3dx9.h>

#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

#define SCREEN_HEIGHT 480
#define SCREEN_WIDTH 640

LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3dDev;
LPD3DXMESH Mesh;
D3DMATERIAL9* mat;
LPDIRECT3DTEXTURE9* tex,tex1,tex2 = NULL;
DWORD numMat;
D3DXMATRIX View,Proj,World,Rotate;
D3DXMATRIXA16 WorldViewProjection;
LPD3DXEFFECT fx = NULL;

void LoadFX()
{
D3DXCreateTextureFromFile(d3dDev,"test.bmp",&tex1);
D3DXCreateTextureFromFile(d3dDev,"checker.bmp",&tex2);

HRESULT hr;
LPD3DXBUFFER pBufferErrors = NULL;

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

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

void Variables()
{
fx->SetTexture("texture0",tex1);
fx->SetTexture("texture1",tex2);

}



void LoadMesh(void)
{
LPD3DXBUFFER bufMat;
D3DXLoadMeshFromX("mesh.x",D3DXMESH_SYSTEMMEM,d3dDev,NULL,&bufMat,NULL,&numMat,&Mesh);

D3DXMATERIAL* tempMat = (D3DXMATERIAL*)bufMat->GetBufferPointer();
mat = new D3DMATERIAL9[numMat];
tex = new LPDIRECT3DTEXTURE9[numMat];


for(DWORD i=0;i<numMat;i++)
{
mat = tempMat.MatD3D;
mat.Ambient = mat.Diffuse;
if(FAILED(D3DXCreateTextureFromFile(d3dDev,tempMat.pTextureFilename,&tex)))
tex=NULL;
}
return;
}

void Lights(void)
{
D3DLIGHT9 light;
ZeroMemory(&light,sizeof(D3DLIGHT9));
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse.r = 0.5f;
light.Diffuse.g = 0.5f;
light.Diffuse.b = 0.5f;
light.Diffuse.a = 1.0f;

D3DXVECTOR3 lDir(-1.0f,-1.0f,0.0f);
light.Direction = lDir;
d3dDev->SetLight(0,&light);
d3dDev->LightEnable(0,true);
return;
}
void InitD3D(HWND hWnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;

ZeroMemory(&d3dpp,sizeof(d3dpp));
d3dpp.Windowed = true;
d3dpp.SwapEffect =D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferHeight = SCREEN_HEIGHT;
d3dpp.BackBufferWidth = SCREEN_WIDTH;
//d3dpp.MultiSampleQuality =
d3dpp.EnableAutoDepthStencil = 1;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&d3dDev);

// Lights();
LoadMesh();


//d3dDev->SetRenderState(D3DRS_LIGHTING,TRUE);
d3dDev->SetRenderState(D3DRS_ZENABLE,TRUE);
d3dDev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50));
d3dDev->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
return;
}

void Matrix(void)
{

D3DXMatrixLookAtLH(&View,&D3DXVECTOR3(0.0f,2.0f,-5.0f),&D3DXVECTOR3(0.0f,0.0f,0.0f),&D3DXVECTOR3(0.0f,1.0f,0.0f));
d3dDev->SetTransform(D3DTS_VIEW,&View);


D3DXMatrixPerspectiveFovLH(&Proj,D3DXToRadian(45),1.33f,1.0f,1000.0f);
d3dDev->SetTransform(D3DTS_PROJECTION,&Proj);
return;
}



void Render(void)
{
d3dDev->Clear(0,NULL,D3DCLEAR_ZBUFFER|D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0);
d3dDev->BeginScene();
Matrix();
static float index; index +=0.01f;
D3DXMatrixRotationY(&Rotate,index);
d3dDev->SetTransform(D3DTS_WORLD,&Rotate);
fx->SetTechnique("TwoPassTextureBlend");
Variables();
UINT uPasses;
fx->Begin(&uPasses,0);
for(UINT uPass = 0;uPass<uPasses;uPass++)
{
fx->BeginPass(uPass);

for(DWORD i=0;i<numMat;i++)
{
d3dDev->SetMaterial(&mat);
if(tex !=NULL)
d3dDev->SetTexture(0,tex);
Mesh->DrawSubset(i);
}
fx->EndPass();
}
fx->End();

d3dDev->EndScene();
d3dDev->Present(NULL,NULL,NULL,NULL);
return;
}

void CleanD3D(void)
{
fx->Release();
Mesh->Release();
d3dDev->Release();
d3d->Release();
return;
}





LRESULT CALLBACK WindowProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}break;
}
return DefWindowProc(hWnd,message,wParam,lParam);
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
HWND hWnd;
WNDCLASSEX wc;

ZeroMemory(&wc,sizeof(WNDCLASSEX));

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
// wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = "Class";


RegisterClassEx(&wc);

hWnd = CreateWindowEx(NULL,"Class","DX9",WS_OVERLAPPEDWINDOW,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,NULL,NULL,hInstance,NULL);

ShowWindow(hWnd,nShowCmd);
InitD3D(hWnd);

MSG msg;

while(true)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Render();

if(KEY_DOWN(VK_ESCAPE))
PostMessage(hWnd,WM_DESTROY,0,0);

d3dDev->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(20,40,a),1.0f,0);


}
CleanD3D();
return msg.wParam;
}

[Edited by - dawchiks on July 21, 2008 9:54:11 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by dawchiks
hmm, cant use debug runtimes. i cant select any of them. and if i try to debug application, it opens, and does nothing. just black screen. and i cant close it even with task manager, only by closing VCexpress.
but i can compile and run other samples who uses .fx files. so the problem is in the code :D
Do you have the latest DirectX SDK? Do you have a breakpoint at the start of WinMain? Or are you running in debug mode with F10 instead of F5?

Share this post


Link to post
Share on other sites
First, you really need to check the return values from your DirectX function calls as Evil Steve suggested!

Quote:
i cant select any of them

Do you mean that the selections ("Use Debug Version of Direct3D 9" and "Use Retail Version of Direct3D 9") are grayed-out? If so, reread Debug Runtime and make sure you're using the latest SDK.
Quote:
the problem is in the code

There's no disagreement there, dawchiks. You need more information about where the error is located!

So: check return values from the DirectX function calls and get the debugger working!

EDIT: simultaneous posts - Listen to Evil Steve!

Share this post


Link to post
Share on other sites
thx for trying to help.
i announce my self as the stupidiest in here.

i made a loadFx() function, and guess what i forgot? i forgot to call it :D.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!