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

This is a discussion on problem with load mesh when its in its own cpp and .h within the Game Programming forums, part of the General Programming Boards category; ive got this function to load the mesh and i cant seem to make it show up on screen , ...

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

    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,046
    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
    316
    well it seems to work fine with other cpps

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    316
    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
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    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
    316
    which other do you need to see because its very big

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    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-13-2009, 11:12 PM
  2. Unexpected end of file, splitting headers into .h/.cpp
    By Shamino in forum C++ Programming
    Replies: 19
    Last Post: 12-11-2007, 12:08 PM
  3. .h files: "constant already defined"
    By wakeup in forum C++ Programming
    Replies: 11
    Last Post: 11-22-2005, 04: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, 05:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21