0

For our student project I've been tinkering with an OBJ-loader in order to import models into our application. It loads without issues, and drawing it kind of works without index (the model is obviously not represented correctly because I'm not using an index buffer) However, drawing with DeviceContext->DrawIndexed shows nothing on screen.

Without indexed drawing

With indexed drawing

Buffer creation method:

void ObjectLoader::CreateBuffers()
{
    //Index buffer
    D3D11_BUFFER_DESC iBufferDesc;
    memset(&iBufferDesc, 0, sizeof(iBufferDesc));
    iBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
    iBufferDesc.Usage = D3D11_USAGE_DEFAULT;
    iBufferDesc.ByteWidth = sizeof(DWORD);

    D3D11_SUBRESOURCE_DATA indexData;
    indexData.pSysMem = &ind;
    pDevice->CreateBuffer(&iBufferDesc, &indexData, &pIndexBuffer);


    //Vertex buffer
    D3D11_BUFFER_DESC bufferDesc;
    memset(&bufferDesc, 0, sizeof(bufferDesc));
    bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    bufferDesc.Usage = D3D11_USAGE_DEFAULT;
    bufferDesc.ByteWidth = sizeof(TriangleVertex) * this->NumberOfVerts();

    D3D11_SUBRESOURCE_DATA data;
    data.pSysMem = tva;
    pDevice->CreateBuffer(&bufferDesc, &data, &pVertexBuffer);
}

Draw method:

void ObjectLoader::Draw()
{
    if (pDevice == nullptr)
        return;

    UINT32 vertexSize = sizeof(float) * 5;
    UINT32 offset = 0;

    pDeviceContext->IASetVertexBuffers(0, 1, &pVertexBuffer, &vertexSize, &offset);
    pDeviceContext->IASetIndexBuffer(this->pIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
    pDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    pDeviceContext->DrawIndexed(vIndex.size(),0 , 0);

    //pDeviceContext->Draw(this->NumberOfVerts(), 0);

}

What the hell am I missing? I've looked at several books on indexed drawing and it seems pretty straight-forward. At first I thought the winding order was reversed but I checked this by simply reversing the index array; same result.

If you need more code let me know, but I feel this should suffice.

Thanks in advance!

Edit: OT: I never figured out how to get my code to be properly formatted so I apologize for that, feel free to share how that's done.

Elias Finoli
  • 121
  • 9
  • Sounds like it could be rasterizer cull mode? – mrvux Feb 20 '17 at 18:14
  • @catflier `iBufferDesc.ByteWidth = sizeof(DWORD);` was the problem. ByteWidth is the size of the entire array of data, not just the size of a single element, which is probably what i thought it meant when i wrote it. – Elias Finoli Feb 21 '17 at 16:28
  • Oh, missed that one, makes sense indeed. – mrvux Feb 22 '17 at 13:39

0 Answers0