Jump to content
  • Advertisement


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

Andy Reno

Casting IDirect3DVertexBuffer9 to custom vbuff

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

Im having trouble converting a mesh vertex into my custom type. struct VERTEXSTRUCT { D3DVECTOR coords; // Direction D3DVECTOR normal; // Direction of faces DWORD dwColor; // Colours float tu, tv; // Texture coords }; some problem doing this?? int nVerts = 0, nFaces = 0; HRESULT hr = S_OK; LPD3DXBUFFER m_pMaterialBuf; //Interface, Mesh needs a material buffer that will store all the materials and textures that will be used char szPath[64] = {"..\\Meshes\\"}; char szBuff[128] = "..\\Textures\\"; char szFiles[MAX_MESHES][64] = {"a.x","b.x","c.x","d.x"}; for(int j = 0; j < MAX_MESHES; j++) { strcat(szPath,szFiles[j]); int len = strlen(szPath); szPath[len+1] = NULL; hr = D3DXLoadMeshFromX(szPath, D3DXMESH_SYSTEMMEM, m_pD3DDevice, NULL, &m_pMaterialBuf, NULL,&Mesh[j].m_dwNumMaterials, &Mesh[j].pMesh ); if(hr != D3D_OK) { MessageBox(m_hWnd,szPath,"Could not find", MB_OK); return E_FAIL; } if(j==2) { VERTEXSTRUCT* pVB; IDirect3DVertexBuffer9* pVBuffer; DWORD f = Mesh[j].pMesh->GetFVF(); Mesh[j].pMesh->GetVertexBuffer(&pVBuffer); Mesh[j].pMesh->LockVertexBuffer(D3DLOCK_NO_DIRTY_UPDATE,(void**)&pVBuffer); pVB = (VERTEXSTRUCT*) pVBuffer;// Cast it to my Vertex type nFaces = (int) Mesh[j].pMesh->GetNumFaces(); nVerts = (int) Mesh[j].pMesh->GetNumVertices(); for(int i = 0; i < nVerts; i += 6) { pVB.tu = 0.0f; pVB[i].tv = 0.0f; pVB[i+1].tu = 5.0f; pVB[i+1].tv = 5.0f; pVB[i + 2].tu = 0.0f; pVB[i + 2].tv = 5.0f; pVB[i + 3].tu = 5.0f; pVB[i + 3].tv = 0.0f; pVB[i + 4].tu = 0.0f; pVB[i + 4].tv = 0.0f; pVB[i + 5].tu = 0.0f; pVB[i + 5].tv = 5.0f; } Mesh[j].pMesh->UnlockVertexBuffer(); } // Extract the material properties and texture names from the material buffer. D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)m_pMaterialBuf->GetBufferPointer(); Mesh[j].pMeshMat = new D3DMATERIAL9[(Mesh[j].m_dwNumMaterials)]; Mesh[j].pMeshTex = new LPDIRECT3DTEXTURE9[(Mesh[j].m_dwNumMaterials)]; for( DWORD i=0; i< Mesh[j].m_dwNumMaterials; i++ ) { // Copy the material Mesh[j].pMeshMat[i] = d3dxMaterials[i].MatD3D; // Set the ambient color for the material (D3DX does not do this) Mesh[j].pMeshMat[i].Ambient = Mesh[j].pMeshMat[i].Diffuse; Mesh[j].pMeshTex[i] = NULL; if( d3dxMaterials[i].pTextureFilename != NULL && lstrlen(d3dxMaterials[i].pTextureFilename) > 0 ) { // Create the texture strcat(szBuff, d3dxMaterials[i].pTextureFilename); if( FAILED( D3DXCreateTextureFromFile(m_pD3DDevice,szBuff, &Mesh[j].pMeshTex[i] ) ) ) { char szError[128]; strcpy(szError,"Could not find texture map "); strcat(szError,szBuff); MessageBox(m_hWnd,szBuff, "Meshes.exe", MB_OK); return E_FAIL; } } sprintf(szBuff,"%s","..\\Textures\\",d3dxMaterials[i].pTextureFilename,NULL); } strcpy(szPath,"..\\Meshes\\"); strcpy(szBuff,"..\\Textures\\"); } // Done with the material buffer m_pMaterialBuf->Release(); return D3D_OK; All sugestions welcome

Share this post

Link to post
Share on other sites

  • 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!