   Help with VB/IB not rendering
  I am just learning how to use DX's VB/IB and must be doing something wrong, I can render a DX teapot just fine, but not my own VB/IB. I am trying to draw a simple box and getting no where. I have setup my own vertex format also. I am looking for what noobs may do wrong or miss.void StaticMesh::AllocateVertexMemory(unsigned long size){HRESULT result; vertices = new Vertex[size];D3DVERTEXELEMENT9 VertexPosElements[] = {{0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},{0, 12,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},{0, 24,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0},{0, 36,  D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},D3DDECL_END()};result = dxApp.d3dDevice->CreateVertexDeclaration(VertexPosElements, &vertexDeclaration);if(FAILED(result)){SHOWERROR("AllocateVertexMemory() - Failed", __FILE__, __LINE__);}}bool StaticMesh::CreateVertexData(void){HRESULT result; //setup to load data from a file or manual setup of vertex data here...//Vertex *tempVertices = NULL;Vertex tempVertices[8];//setting first two parameters to 0 locks entire bufferresult = vertexBuffer->Lock(0, 0, (void**)&tempVertices, 0);if(FAILED(result)){SHOWERROR("CreateVertexBuffer() - Failed", __FILE__, __LINE__);return false;}tempVertices[0] = Vertex(-1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0, 0.0f, 0.0f);tempVertices[1] = Vertex(-1.0f,  1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0, 0.0f, 0.0f);tempVertices[2] = Vertex( 1.0f,  1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0, 0.0f, 0.0f);tempVertices[3] = Vertex( 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0, 0.0f, 0.0f);tempVertices[4] = Vertex(-1.0f, -1.0f,  1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0, 0.0f, 0.0f);tempVertices[5] = Vertex(-1.0f,  1.0f,  1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0, 0.0f, 0.0f);tempVertices[6] = Vertex( 1.0f,  1.0f,  1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0, 0.0f, 0.0f);tempVertices[7] = Vertex( 1.0f, -1.0f,  1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0, 0.0f, 0.0f);//not sure if I need to memcpy the buffer???//memcpy(tempVertices, vertices, size);vertexBuffer->Unlock();return true;}bool StaticMesh::CreateVertexBuffer(unsigned long size, DWORD usage, DWORD fvf, D3DPOOL pool){HRESULT result; result = dxApp.d3dDevice->CreateVertexBuffer(size, usage, fvf, pool, &vertexBuffer, NULL);if(FAILED(result)){   SHOWERROR("CreateVertexBuffer() - Failed", __FILE__, __LINE__);return false;}elsereturn true;if(!CreateVertexData())return false;elsereturn true;}void StaticMesh::DrawVertexBuffer(D3DPRIMITIVETYPE type, INT baseVertexIndex, UINT minIndex, UINT numVertices, UINT startIndex, UINT polygonCount,   unsigned long renderMode, bool lighting, bool depth){// Let Direct3D know the vertex buffer, index buffer and vertex // declaration we are using.dxApp.d3dDevice->SetStreamSource(0, vertexBuffer, 0, sizeof(Vertex));dxApp.d3dDevice->SetIndices(indexBuffer);dxApp.d3dDevice->SetVertexDeclaration(vertexDeclaration);switch(renderMode){case 0:   dxApp.d3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);break;case 1:dxApp.d3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);break;case 2:dxApp.d3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_POINT);break;default:dxApp.d3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);break;}if(lighting){dxApp.d3dDevice->SetRenderState(D3DRS_LIGHTING, true);dxApp.d3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);}if(depth)dxApp.d3dDevice->SetRenderState(D3DRS_ZENABLE, true);dxApp.d3dDevice->DrawIndexedPrimitive(type, baseVertexIndex, minIndex, numVertices, startIndex, polygonCount);}bool StaticMesh::CreateIndexBuffer(unsigned long size, DWORD usage, D3DFORMAT format, D3DPOOL pool){HRESULT result;result = dxApp.d3dDevice->CreateIndexBuffer(size, usage, format, pool, &indexBuffer, 0);if(FAILED(result)){SHOWERROR("CreateIndexBuffer() - Failed", __FILE__, __LINE__);return false;}elsereturn true;if(!CreateIndexBufferData())return false;else return true;}bool StaticMesh::CreateIndexBufferData(void){//setup here indexbuffer data ordering for meshWORD *k = NULL;indexBuffer->Lock(0, 0, (void**)&k, 0);// Front face.k[0] = 0; k[1] = 1; k[2] = 2;k[3] = 0; k[4] = 2; k[5] = 3;// Back face.k[6] = 4; k[7]  = 6; k[8]  = 5;k[9] = 4; k[10] = 7; k[11] = 6;// Left face.k[12] = 4; k[13] = 5; k[14] = 1;k[15] = 4; k[16] = 1; k[17] = 0;// Right face.k[18] = 3; k[19] = 2; k[20] = 6;k[21] = 3; k[22] = 6; k[23] = 7;// Top face.k[24] = 1; k[25] = 5; k[26] = 6;k[27] = 1; k[28] = 6; k[29] = 2;// Bottom face.k[30] = 4; k[31] = 0; k[32] = 3;k[33] = 4; k[34] = 3; k[35] = 7;indexBuffer->Unlock();return true;}Thanks   
  Will DX still render a simple cube if I have my vertex data with normals, tangent, texcoords? Maybe I am including to much info for I am not texturing or doing any HLSL, just trying to draw a simple cube with indexbuffers. I wouldn't think it would matter but this is all new ground to me. Thanks   ;  It seems that you are trying to render a simple cube without any lights enabled. By default DirectX enables lighting. If you aren't using HLSL or not specifying FFP lights you are not going to see anything.Try setting dxApp.d3dDevice->SetRenderState(D3DRS_LIGHTING, false);Also check your input data.I hope this helps.Take care.   ;Quote:Original post by ArmadonIt seems that you are trying to render a simple cube without any lights enabled. By default DirectX enables lighting. If you aren't using HLSL or not specifying FFP lights you are not going to see anything.Try setting dxApp.d3dDevice->SetRenderState(D3DRS_LIGHTING, false);Also check your input data.I hope this helps.Take care.So the DX shapes e.g. teapot, cube aren't affected then by this behavior? I can see them but not my cube with the VB/IB calls. I will check the lighting...;  Assuming you've got the same code working without an index buffer, but when using an IB it fails, theres a good chance that the parameters to DrawIndexedPrimitive might be incorrect.The minVert and number of vertices drawn must be correct. If the range these values specify doesn't cover all the vertices used in the draw, the call might not get drawn on certain cards. I'd recommend you make sure those were correct if you're code works with DrawPrimitive, but not with DrawIndexedPrimitive.Hope this helps :).   ;  Ok what happens if I don't get anything to draw with DrawPrimitive()? Cause as of now its not working.DrawPrimitive(D3DPT_TRIANGLELIST, 0, 12);Is what I am calling now instead and still a no go. I know my app is setup correctly since I can see the teapot. thanks   ;  still a no go on the rendering, but with my view matrix when I set my eye to (0.0, 0.0, 20.0) and use HLSL I can see the teapot again, now if I set to (0.0, 0.0, 0.0) it isn't rendered. If I drop the HLSL code and leave the view matrix eye parameters to (0.0, 0.0, 0.0) it renders... No doubt DX is harder to get a hold of than OpenGL IMO so far... Any help would be greatly appreciated. Thanks   ;  I fixed it. Thanks for the help.   