Thread: problem with load mesh when its in its own cpp and .h

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    319

    problem with load mesh when its in its own cpp and .h

    ive got this function to load the mesh and i cant seem to make it show up on screen , if this code is in main then it works fine , some problem with the parameters thats not making it work right , SetMaterial and the rest is in RenderMesh(); in main...

    Code:
    #include "Globals.h"
    
    
    HRESULT LoadD3DMeshNew(
    					IDirect3DDevice9* g_pDirect3DDevice,
    					DWORD dwNumMaterials,
    					LPD3DXMESH pMesh,
    					D3DMATERIAL9* pMeshMaterials,
    					LPDIRECT3DTEXTURE9* pMeshTextures
    					) 
    { 
    
    
    
        LPD3DXBUFFER pD3DXMtrlBuffer; 
    
    	if( FAILED( D3DXLoadMeshFromX( "airplane 2.x", D3DXMESH_SYSTEMMEM, 
                g_pDirect3DDevice, NULL, &pD3DXMtrlBuffer, NULL,
                &dwNumMaterials, &pMesh ) ) )
    	
        {
         MessageBox(NULL, "Could not find tiger.x","Meshes.exe", MB_OK);
          return E_FAIL;
        }
    	else
    	{
       //  MessageBox(NULL, "Loaded tiger.x","Meshes.exe", MB_OK);
          
    	}
    
      // We need to extract the material properties and texture names from the 
     //  pD3DXMtrlBuffer 
       D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer(); 
       pMeshMaterials = new D3DMATERIAL9[dwNumMaterials]; 
       pMeshTextures = new LPDIRECT3DTEXTURE9[dwNumMaterials]; 
    
        char buf[64];
        sprintf(buf , "%s %d" , "dwNumMaterials is" , dwNumMaterials);
    //	MessageBox(NULL, buf,buf, MB_OK);
    
    
    
        for( DWORD i=0; i<dwNumMaterials; i++ ) 
        { 
            // Copy the material 
            pMeshMaterials[i] = d3dxMaterials[i].MatD3D; 
    
            // Set the ambient color for the material (D3DX does not do this) 
            pMeshMaterials[i].Ambient = pMeshMaterials[i].Diffuse; 
    
            // Create the texture 
            if( FAILED( D3DXCreateTextureFromFile( g_pDirect3DDevice, 
                d3dxMaterials[i].pTextureFilename, 
                &pMeshTextures[i] ) ) ) 
            { 
                pMeshTextures[i] = NULL; 
            } 
        } 
    
        // Done with the material buffer 
        pD3DXMtrlBuffer->Release(); 
    
        return S_OK; 
    }

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I'm guessing (I don't program with DirectX) that you're doing something like this:
    Code:
    void function(int *array) {
        array = new int[10];
    }
    
    int main(void) {
        int *array = 0;
        function(array);
        // error: array has not been set
    }
    In order to reflect changes made to a pointer in a function inside the calling function, you need to pass the pointer as a pointer-to-pointer:
    Code:
    void function(int **array) {
        (*array) = new int[10];
    }
    
    int main(void) {
        int *array = 0;
        function(&array);
        // error: array has not been set
    }
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    well it seems to work fine with other cpps

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    this works fine when usin it
    Clear(g_pDirect3DDevice);

    Code:
    void Clear(IDirect3DDevice9* g_pDirect3DDevice)
    {
    g_pDirect3DDevice->Clear(0, NULL , D3DCLEAR_TARGET , D3DCOLOR_XRGB(0,0,0), 1.0f , 0);
    }

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    We would need more code to find out why it's not rendering. Could be incorrect matrix setup, incorrect lighting, incorrect...well incorrect anything.

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    which other do you need to see because its very big

  7. #7
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    The setup and the render code is a good place to start.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. building problem, need .h file
    By BadWolf in forum C++ Programming
    Replies: 1
    Last Post: 02-14-2009, 12:12 AM
  2. Unexpected end of file, splitting headers into .h/.cpp
    By Shamino in forum C++ Programming
    Replies: 19
    Last Post: 12-11-2007, 01:08 PM
  3. .h files: "constant already defined"
    By wakeup in forum C++ Programming
    Replies: 11
    Last Post: 11-22-2005, 05:31 AM
  4. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM
  5. weird problem with .h files
    By Leeman_s in forum C++ Programming
    Replies: 7
    Last Post: 12-22-2002, 06:11 PM