Not sure what I am doing wrong here. Probably a simple mistake but I can't seem to find it. I plan on having a CObject class that represents a single instance of an object; a mesh (.X file), vertex buffer, ect. This way I can load the object and create instances of it that will be held in seperate CObject's. Everything seems to be working fine except that nothing is being rendered to the display. I am still working on it and it is still a bit messy but here is what I have so far.
CObject contains a struct that defines what kind of object it is.
I create a vertex buffer and an index bufferCode:typedef enum D3DDATATYPE { D3DOBJECTTYPE_NOOBJECT = 0x000, D3DOBJECTTYPE_SIMPLEMESH = 0x001, D3DOBJECTTYPE_SKINNEDMESH = 0x002, D3DOBJECTTYPE_VERTEXBUFFER = 0x003 } D3DDATATYPE; typedef struct D3DOBJECTTYPE { D3DDATATYPE Type; union { CMesh *pSimpleMesh; CSkinnedMesh *pSkinnedMesh; CVertexBuffer *pVertexBuffer; }; } D3DOBJECTTYPE;
And I create an instance (CObject)Code:CGameApp::CreateDevice() ... cstmVertex::PositionColor vertices[] = { {-1.0f, -1.0f, 0.0f, D3DCOLOR_XRGB( 255, 0, 0 ) }, {-1.0f, 1.0f, 0.0f, D3DCOLOR_XRGB( 255, 255, 0 ) }, { 1.0f, -1.0f, 0.0f, D3DCOLOR_XRGB( 0, 255, 0 ) }, { 1.0f, 1.0f, 0.0f, D3DCOLOR_XRGB( 0, 0, 255 ) } }; UINT indices[] = { 0, 1, 2, 1, 3, 2 }; m_IndexBuffer.CreateBuffer(pDevice, 6, D3DFMT_INDEX16); m_IndexBuffer.SetData(6, indices); m_VertexBuffer.CreateBuffer(pDevice, // The D3DDevice 4, // num verts sizeof(cstmVertex::PositionColor), // vert size 2, // num primitives D3DPT_TRIANGLELIST, // primitive type D3DFVF_XYZ | D3DFVF_DIFFUSE, // FVF false, // dynamic (void*)vertices, // vertices &m_IndexBuffer); // CIndexBuffer m_pCube = new (CObject); m_VertexBuffer.CreateInstance(pDevice, m_pCube); D3DVERTEXELEMENT9 VertexElement[] = { { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 }, D3DDECL_END() }; LPDIRECT3DVERTEXDECLARATION9 VertexDeclaration = 0; pDevice->CreateVertexDeclaration(VertexElement, &VertexDeclaration); pDevice->SetVertexDeclaration(VertexDeclaration); ... bool CVertexBuffer::CreateBuffer(LPDIRECT3DDEVICE9 pDevice, UINT NumVertices, UINT VertexSize, UINT NumPrimitives, D3DPRIMITIVETYPE PrimitiveType, DWORD FVF, bool dynamic, void *pVertexData, CIndexBuffer *pIB) { if (m_pVB) Release(); m_NumVertices = NumVertices; m_VertexSize = VertexSize; m_NumPrimitives = NumPrimitives; m_PrimitiveType = PrimitiveType; m_FVF = FVF; // Dynamic buffers can't be in D3DPOOL_MANAGED D3DPOOL pool = dynamic ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED; DWORD usage = dynamic ? D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC : D3DUSAGE_WRITEONLY; if (FAILED(pDevice->CreateVertexBuffer(m_NumVertices * m_VertexSize, usage, m_FVF, pool, &m_pVB, NULL ) ) ) { SHOW_ERROR("CreateVertexBuffer failed."); return false; } // If there is an index buffer, set it if (pIB) m_pIB = pIB; // Set the vertex data char *pData; // Lock the vertex buffer if (FAILED(m_pVB->Lock( 0, 0, (void**)&pData, D3DLOCK_DISCARD) ) ) { SHOW_ERROR("IDirect3DVertexBuffer9::Lock failed."); return false; } // Copy vertex data to the vertex buffer memcpy(pData, pVertexData, m_NumVertices * m_VertexSize); // Unlock vertex buffer if (FAILED(m_pVB->Unlock() ) ) { SHOW_ERROR("IDirect3DVertexBuffer9::Unlock failed."); return false; } return true; }
and then I render itCode:bool CVertexBuffer::CreateInstance(LPDIRECT3DDEVICE9 pDevice, CObject *pObjToCreate) { if (!pObjToCreate) return false; pObjToCreate->SetObjRef(pDevice, D3DOBJECTTYPE_VERTEXBUFFER, (void*)this); return true; } void CObject::SetObjRef(LPDIRECT3DDEVICE9 pDevice, D3DDATATYPE Type, void *pObject) { Release(); if (Type == D3DOBJECTTYPE_VERTEXBUFFER) { m_Object.Type = D3DOBJECTTYPE_VERTEXBUFFER; m_Object.pVertexBuffer = (CVertexBuffer*)pObject; } return; }
Anyone see anything I am missing that would cause this not to display anything?Code:CGameApp::Render() ... m_camera.Update(); pDevice->SetTransform(D3DTS_VIEW, m_camera.GetViewMatrix() ); pDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); pDevice->BeginScene(); m_pCube->Render(pDevice); pDevice->EndScene(); pDevice->Present(0, 0, 0, 0); ... void CObject::Render(LPDIRECT3DDEVICE9 pDevice) { pDevice->SetTransform(D3DTS_WORLD, GetTransform() ); switch (m_Object.Type) { case D3DOBJECTTYPE_VERTEXBUFFER : { m_Object.pVertexBuffer->Render(pDevice, NULL); } break; } return; } void CVertexBuffer::Render(LPDIRECT3DDEVICE9 pDevice, CObject *pObject) { pDevice->SetStreamSource(0, m_pVB, 0, m_VertexSize); pDevice->SetFVF(m_FVF); if (m_pIB) { pDevice->SetIndices(m_pIB->GetBuffer() ); pDevice->DrawIndexedPrimitive(m_PrimitiveType, 0, 0, m_NumVertices, 0, m_NumPrimitives); } else { pDevice->DrawPrimitive(m_PrimitiveType, 0, m_NumPrimitives); } return; }



LinkBack URL
About LinkBacks


