Използването на динамичен буфер показва празна мрежа в 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