Hey guys, here's another one that's got me to scratching a bald spot on my head. First of all, here's how I'm creating my Direct3D device:
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice)))
{
return;
}
or
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice)))
{
return;
}
(the difference is in the HARDWARE and SOFTWARE Vertex Processing Flags)
I'm using this to create a vertex buffer and index buffer for my 2D game:
if( FAILED( g_pd3dDevice->CreateVertexBuffer( (SP_END*4)*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED, &g_QuadsVB, NULL ) ) )
{
return E_FAIL;
}
if( FAILED( g_pd3dDevice->CreateIndexBuffer ((SP_END*2*3)*sizeof(WORD),
DX_VertexHandlingMode, D3DFMT_INDEX16,
D3DPOOL_MANAGED, &g_QuadsIB, NULL)))
{
return E_FAIL;
}
g_pd3dDevice->SetIndices(g_QuadsIB);
FillIndexBuffer();
if( FAILED( g_QuadsVB->Lock( 0, sizeof(quadVerts), (void**)&pVertices, 0 ) ) )
{
return E_FAIL;
}
memcpy( pVertices, quadVerts, sizeof(quadVerts) );
g_QuadsVB->Unlock();
where SP_END is the last quad in the game (1100). The FillIndexBuffer() function you see in the above code is this right here:
void FillIndexBuffer()
{
int index = 0;
short* indices = NULL;
// All ingame entities...
g_QuadsIB->Lock(0, (SP_END*2*3)*sizeof(WORD), (void**) &indices, 0);
for (int vertex = 0; vertex < SP_END*4; vertex += 4)
{
indices[index] = vertex;
indices[index + 1] = vertex + 2;
indices[index + 2] = vertex + 3;
indices[index + 3] = vertex;
indices[index + 4] = vertex + 1;
indices[index + 5] = vertex + 2;
index += 6;
}
g_QuadsIB->Unlock();
}
After I get the buffers created and filled, I render parts of the vertex buffer within my render loop like so:
void DrawMSQuads()
{
UINT vNum = (MS_END-MS_START) * 6;
UINT pNum = vNum / 3;
// Set up the texture...
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ZERO );
g_pd3dDevice->SetTexture( 0, Texture );
// Now draw the primitives from the MasterGroup struct
g_pd3dDevice->SetStreamSource( 0, g_QuadsVB, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetIndices(g_QuadsIB);
g_pd3dDevice->DrawIndexedPrimitive (D3DPT_TRIANGLELIST,
(MS_START)*4,
0,
vNum,
0,
pNum);
}
where MS_START is 923 and MS_END is 987. This works for the most part, but some ranges of vertices won't render under certain situations. For example, the above function renders all the time. But the following won't render on a GeForce 6800 video card when the Direct3D device is created using the D3DCREATE_SOFTWARE_VERTEXPROCESSING flag:
void DrawMenuTextQuads()
{
UINT vNum = (MT_END-MT_START) * 6;
UINT pNum = vNum / 3;
// Set up the texture...
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ZERO );
g_pd3dDevice->SetTexture( 0, Texture );
// Now draw the primitives from the MasterGroup struct
g_pd3dDevice->SetStreamSource( 0, g_QuadsVB, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetIndices(g_QuadsIB);
g_pd3dDevice->DrawIndexedPrimitive (D3DPT_TRIANGLELIST,
(MT_START)*4, // Starts at index (MT_START * 4)
0,
vNum,
0,
pNum);
}
MT_START is 603 and MT_END is 923. This function WILL render correctly on NVidia cards, however, if the Direct3D device is created using the D3DCREATE_HARDWARE_VERTEXPROCESSING flag.
Any ideas why the DrawMenuTextQuads() function won't render on a NVidia video card when the Direct3D device is created using the D3DCREATE_SOFTWARE_VERTEXPROCESSING flag? I hope you can help me out on this, because I don't want to scratch my bald spot any bigger!