Использование динамического буфера отображает пустую сетку в Directx 9

Я пытаюсь использовать динамические массивы при создании буферов вершин и индексов для сетки, например:

// Create the mesh with a call to D3DXCreateMeshFVF
D3DXCreateMeshFVF(caras_a_dibujar, // NumFaces
    cantidad_de_puntos, // NumVertices
    D3DXMESH_MANAGED, // Options
    CUSTOMFVF, // FVF
    d3ddev, // pDevice
    &esfera_purete); // ppMesh

CUSTOMVERTEX* g_Vertices = NULL;   // Pointer to CUSTOMVERTEX, initialize to nothing.
g_Vertices = new CUSTOMVERTEX[cantidad_de_puntos];  // Allocate cantidad_de_puntos and save pointer in g_Vertices.

for (int n = 0; n < cantidad_de_puntos; n++) g_Vertices[n] = { puntos_unicos[n].x, puntos_unicos[n].y, puntos_unicos[n].z, { puntos_unicos[n].x, puntos_unicos[n].y, puntos_unicos[n].z }, 0.5f + atan2f(puntos_unicos[n].z, puntos_unicos[n].x) / (2 * D3DX_PI), 0.5f - asinf(puntos_unicos[n].y) / D3DX_PI };
VOID* pVertices;
// Lock the vertex buffer
esfera_purete->LockVertexBuffer(D3DLOCK_DISCARD, (void**)&pVertices);
// Copy the vertices into the buffer
memcpy(pVertices, g_Vertices, sizeof(g_Vertices));
// Unlock the vertex buffer
esfera_purete->UnlockVertexBuffer();


WORD* IndexData = NULL;   // Pointer to WORD, initialize to nothing.
IndexData = new WORD[caras_a_dibujar * 3];  // Allocate caras_a_dibujar * 3 and save pointer in IndexData.

for (int n = 0; n < caras_a_dibujar * 3; n++) IndexData[n] = indice[n];
// Prepare to copy the indices into the index buffer
VOID* IndexPtr;
// Lock the index buffer
esfera_purete->LockIndexBuffer(0, &IndexPtr);
// Copy the indices into the buffer
memcpy(IndexPtr, IndexData, sizeof(IndexData));
// Unlock the buffer
esfera_purete->UnlockIndexBuffer();


delete[] g_Vertices;  // free memory pointed to by g_Vertices.
g_Vertices = NULL;     // Clear a to prevent using invalid memory reference.
delete[] IndexData;  // free memory pointed to by IndexData.
IndexData = NULL;     // Clear a to prevent using invalid memory reference.

cantidad_faces = esfera_purete->GetNumFaces();

Код компилируется и работает гладко и даже дает мне правильное количество граней и вершин в сетке с помощью GetNumFaces() и GetNumVertices(), но сетка не отображается, она просто невидима. Я впервые использую такое динамическое выделение памяти, поэтому уверен, что проблема в строках:

CUSTOMVERTEX* g_Vertices = NULL;   // Pointer to CUSTOMVERTEX, initialize to nothing.
g_Vertices = new CUSTOMVERTEX[cantidad_de_puntos];  // Allocate cantidad_de_puntos and save pointer in g_Vertices.

и:

WORD* IndexData = NULL;   // Pointer to WORD, initialize to nothing.
IndexData = new WORD[caras_a_dibujar * 3];  // Allocate caras_a_dibujar * 3 and save pointer in IndexData.

Но что не так?


person Haalef    schedule 23.02.2015    source источник


Ответы (1)


У меня была эта проблема однажды. Это произошло потому, что порядок индексов для лица был обратным. Вместо индексации по часовой стрелке потребовалась индексация против часовой стрелки. Это означает, что (0,1,2) не сработало, а (0,2,1) сработало. Я полагаю, это зависит от того, как вы настроили матрицы и отсечение задней поверхности.

person Ganshauk    schedule 24.03.2015