Ok, I'm writing a simple program with VC++ and DirectX. It's basically a working framework for 3D games, but all I need it to do right now is load a mesh and display it, and it is killing me. I've done this successfully before, I don't know why its not working now.

The function I use to load the .X file is Mesh::LoadFromX()

declared here:

int LoadFromX(char* filename);

defined here:

//Loads the model from a .X file
//Takes the filename of the model as a parameter
//Returns 1 on success, 0 on failure
int Model::LoadFromX(char* filename)
	ID3DXBuffer* matbuffer;
	HRESULT result;

	result = D3DXLoadMeshFromX(filename,D3DXMESH_SYSTEMMEM,d3ddev,NULL,&matbuffer,NULL,(DWORD*)&m_materialCount,&m_mesh);
	if(result != D3D_OK)
			MessageBox(NULL,"D3DERR_INVALIDCALL from D3DXLoadMeshFromX() in Model::LoadFromX()","Error",MB_OK | MB_ICONERROR);
			MessageBox(NULL,"E_OUTOFMEMORY from D3DXLoadMeshFromX() in Model::LoadFromX()","Error",MB_OK | MB_ICONERROR);
			MessageBox(NULL,"D3DXFERR_FILENOTFOUND from D3DXLoadMeshFromX() in Model::LoadFromX()","Error",MB_OK | MB_ICONERROR);
			char error[1000];
			sprintf(error,"Unknown error from D3DXLoadMeshFromX() in Model::LoadFromX(): %d",result);
			MessageBox(NULL,error,"Error",MB_OK | MB_ICONERROR);
		return 0;

	D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)matbuffer->GetBufferPointer();
	m_materials = new D3DMATERIAL9[m_materialCount];
	m_textures = new IDirect3DTexture9*[m_materialCount];

	for(int i = 0;i < m_materialCount;i++)
		m_materials[i] = d3dxMaterials[i].MatD3D;
		m_materials[i].Ambient = m_materials[i].Diffuse;

		m_textures[i] = NULL;
		if(d3dxMaterials[i].pTextureFilename != NULL && d3dxMaterials[i].pTextureFilename != "")
			result = D3DXCreateTextureFromFile(d3ddev,d3dxMaterials[i].pTextureFilename,&m_textures[i]);
			if(result != D3D_OK)
				MessageBox(NULL,"Could not load proper texture file","Error loading model",MB_OK | MB_ICONERROR);
				return 0;

	return 1;

and called here:

house = new Model;

I keep getting D3DXFERR_FILENOTFOUND from the call to D3DXLoadMeshFromX().

The .X file is at C:\Documents and Settings\<user>\Desktop\Projects\3DGameFramework\3DGameFramework\fachwerk33T.x,the same directory all my source files are in. The computer recognizes it as a "DirectX X-File".

Anyone know why it isn't working?

Also, random other question: anyone know how to get the address bar to come up in windows explorer (like the one that says: C:\...,like it would in a web browser?). I tried View->Toolbars->Address Bar, but that just added a box saying "Address" to the top-right of windows explorer (you got to love windows).

Recommended Answers

All 3 Replies

Did you try using a full path to specify the file? i.e:

house->LoadFromX("C:\\Documents and Settings\\<user>\\Desktop\\Projects\\3DGameFramework\\3DGameFramework\\fachwerk33T.x");

Try this temporarily. The initial working directory of your application is not necessarily the folder where source files are located; you can normally set the application's working directory either from the IDE ( if appropriate ) or from a shortcut, etc.

The windows explorer addressbar thing; do View > Toolbars > Address Bar, and then right click the toolbar and uncheck "Lock the Toolbars".. you should then be able to move the address bar into the correct place ( from what you've said, it's showing but is too small/wrong place to see properly ).

I got it, but that wasn't it.

It was an issue with Windows Explorer. For some reason, it's set to not display file extensions on files (except DLLs, and maybe some other exceptions). The .X file was originally shown w/o a .X at the end, so that's the way I wrote it in C++, but in reality, the .X was part of the name. I then tried renaming it in Explorer to <modelname>.x, but that renamed it to <modelname>.x.x

So, now I have it to appear as just the model name w/o the extension in Explorer, but I include the extension in C++. Works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.