Archived

This topic is now archived and is closed to further replies.

Kawahee

This is probably obvious... but I can't get it...

Recommended Posts

Kawahee    127
This is probably very obvious, but I can''t figure out what I''m doing wrong here. In my object i use brick.bmp, roof.bmp, floor.bmp and a whitish material for the walls. But, when I run my viewer, all the textures are brick.bmp. I dunno what I''m doing wrong... This is my first real attempt at full on 3D and I hope you guys could point me in the right direction... [I know you can optimize a bit of it, i just slapped it together in a hurry] //Globals LPD3DXMESH g_pMesh = NULL; // Our mesh object in sysmem D3DMATERIAL8* g_pMeshMaterials = NULL; // Materials for our mesh LPDIRECT3DTEXTURE8* g_pMeshTextures = NULL; // Textures for our mesh DWORD g_dwNumMaterials = 0L; // Number of mesh materials LPD3DXBUFFER pD3DXMtrlBuffer; struct CUSTOMVERTEX { FLOAT x, y, z; // The untransformed position for the vertex. DWORD color; // The vertex color. }; void Frame(); void LoadMesh(char* Filename); void Frame() { Graphics.GetDeviceCOM()->SetRenderState( D3DRS_AMBIENT, 0xffffffff ); if(KEY_DOWN(VK_UP)) theta+=0.1f; else if(KEY_DOWN(VK_DOWN)) theta-=0.1f; else if(KEY_DOWN(VK_LEFT)) beta+=0.1f; else if(KEY_DOWN(VK_RIGHT)) beta-=0.1f; else if(KEY_DOWN(VK_INSERT)) alpha+=0.1f; else if(KEY_DOWN(VK_DELETE)) alpha-=0.1f; else return; D3DXMATRIX matWorld; D3DXMATRIX matView; D3DXMATRIX matProj; D3DXMatrixRotationY(&matWorld, beta); D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3( 0.0f, 3.0f, theta), &D3DXVECTOR3(0.0f, alpha, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 1.0f, 1.0f, 1000.0f); Graphics.BeginScene(); Graphics.ClearZ(); for( DWORD i=0; i < g_dwNumMaterials; i++ ) { // Set the material and texture for this subset Graphics.GetDeviceCOM()->SetMaterial( &g_pMeshMaterials ); Graphics.GetDeviceCOM()->SetTexture( 0, g_pMeshTextures[i] ); char temp[200]; sprintf(temp, "Current Texture %i"); // Draw the mesh subset g_pMesh->DrawSubset( i ); } Graphics.GetDeviceCOM()->SetTransform(D3DTS_WORLD, &matWorld); Graphics.GetDeviceCOM()->SetTransform( D3DTS_VIEW, &matView ); Graphics.GetDeviceCOM()->SetTransform( D3DTS_PROJECTION, &matProj ); Graphics.EndScene(); Graphics.Display(); } void LoadMesh(char* Filename) { if(FAILED(D3DXLoadMeshFromX(Filename, D3DXMESH_SYSTEMMEM, Graphics.GetDeviceCOM(), NULL, &pD3DXMtrlBuffer, &g_dwNumMaterials, &g_pMesh))) PostQuitMessage(0); D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer(); g_pMeshMaterials = new D3DMATERIAL8[g_dwNumMaterials]; g_pMeshTextures = new LPDIRECT3DTEXTURE8[g_dwNumMaterials]; for( UINT i=0; i < g_dwNumMaterials; i++ ) { MessageBox(NULL, d3dxMaterials->pTextureFilename, "Filename", MB_OK); if(FAILED(D3DXCreateTextureFromFile(Graphics.GetDeviceCOM(), d3dxMaterials->pTextureFilename,&g_pMeshTextures[i]))) { MessageBox(NULL, "Failed...", "Failed@Text.", MB_OK); g_pMeshTextures[i] = NULL; } } pD3DXMtrlBuffer->Release(); } I''''m a signature virus, copy me into your signature and help me spread!

Share this post


Link to post
Share on other sites
xyzzy00    307
It doesn''t look to me as though "d3dxMaterials->pTextureFilename" changes between iterations of the loop you have loading the textures. Perhaps you meant "d3dxMaterials.pTextureFilename" ?

xyzzy

Share this post


Link to post
Share on other sites