2014-01-06 4 views
0

내 사각형이 왜 이렇게합니까 (인덱스 버퍼 문제)?내 사각형이 왜 이렇게합니까 (인덱스 버퍼 문제)?

struct VERTEX 
{ 
    float X, Y, Z; 
    float R, G, B; 
}; 

const unsigned short SquareVertices::indices[ 6 ] = { 
    0, 1, 2, 
    0, 2, 3 
}; 

const VERTEX SquareVertices::vertices[ 4 ] = { 
    -1.0f, -1.0f, 1.0f,  1.0f, 0.0f, 0.0f, 
    -1.0f, 1.0f, 1.0f,  0.0f, 1.0f, 0.0f, 
    1.0f, 1.0f, 1.0f,  0.0f, 0.0f, 1.0f, 
    1.0f, -1.0f, 1.0f,  0.0f, 1.0f, 0.0f 
}; 

내가 이런 식으로 초기화를 수행 한 : 셰이더의 설정 외모에 전달

void Player::Initialize() 
{ 
    // Create vertex buffer 
    D3D11_BUFFER_DESC bd = { 0 }; 
    bd.ByteWidth = sizeof(VERTEX)* ARRAYSIZE(Player::vertices); 
    bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; 

    D3D11_SUBRESOURCE_DATA srd = { Player::vertices, 0, 0 }; 

    d3dDevice->CreateBuffer(&bd, &srd, &vertexbuffer); 

    // Create the index buffer 
    D3D11_BUFFER_DESC ibd = { 0 }; 
    ibd.ByteWidth = sizeof(short)* ARRAYSIZE(Player::indices); 
    ibd.BindFlags = D3D11_BIND_INDEX_BUFFER; 

    D3D11_SUBRESOURCE_DATA isrd = { Player::indices, 0, 0 }; 

    d3dDevice->CreateBuffer(&ibd, &isrd, &indexbuffer); 
} 

내 일정한 버퍼를

enter image description here

나는 다음 정점과 지표를 설정 이렇게 :

void Game::SetUpConstantBuffer() 
{ 
    D3D11_BUFFER_DESC bd = { 0 }; 

    bd.Usage = D3D11_USAGE_DEFAULT; 
    bd.ByteWidth = 64; 
    bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; 

    d3dDevice->CreateBuffer(&bd, nullptr, &constantbuffer); 
    d3dDeviceContext->VSSetConstantBuffers(0, 1, constantbuffer.GetAddressOf()); 
} 

내 입력 레이아웃은 다음과 같습니다

void Game::SetUpViewTransformations() 
{ 
    XMVECTOR vecCamPosition = XMVectorSet(0.0f, 0.0f, -10.0f, 0); 
    XMVECTOR vecCamLookAt = XMVectorSet(0, 0, 0, 0); 
    XMVECTOR vecCamUp = XMVectorSet(0, 1, 0, 0); 

    matView = XMMatrixLookAtLH(vecCamPosition, vecCamLookAt, vecCamUp); 
} 

void Game::SetUpMatProjection() 
{ 
    CoreWindow^ window = CoreWindow::GetForCurrentThread(); // get the window pointer 

    matProjection = XMMatrixPerspectiveFovLH(
     XMConvertToRadians(45),          // the field of view 
     (FLOAT)window->Bounds.Width/(FLOAT)window->Bounds.Height, // aspect ratio 
     1,               // the near view-plane 
     100);              // the far view-plan 
} 

:이처럼 내 관점과 카메라를 설정 한

// set the vertex buffer 
      UINT stride = sizeof(VERTEX); 
      UINT offset = 0; 
       d3dDeviceContext->IASetVertexBuffers(0, 1, player->vertexbuffer.GetAddressOf(), &stride, &offset); 
       d3dDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); 
       d3dDeviceContext->IASetIndexBuffer(player->indexbuffer.Get(), DXGI_FORMAT_R32_UINT, 0); 
       d3dDeviceContext->UpdateSubresource(constantbuffer.Get(), 0, 0, &matFinal[ 0 ], 0, 0); // set the new values for the constant buffer 
       d3dDeviceContext->DrawIndexed(ARRAYSIZE(player->indices), 0, 0); // draw 3 vertices, starting from vertex 0 

:

// initialize input layout 
D3D11_INPUT_ELEMENT_DESC ied[ ] = 
{ 
    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, 
    { "COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 } 
}; 

내 그리기 섹션은 다음과 같습니다 추가 정보

는 나는이 그리는 DXGI_FORMAT_R16_UINT 내 IASetIndexBuffer 2 매개 변수를 변경하는 경우 :

enter image description here

답변

0

두 번째 매개 변수 IASetIndexBuffer에이DXGI_FORMAT_R16_UINT을해야합니다. 반바지는 32 비트가 아니라 16 비트입니다. DirectX 전문가는 아니지만 D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELISTIASetPrimitiveTopology으로 전달해야한다고 생각합니다.

+0

삼각형 목록이 문제를 해결했습니다. 지금 스트립이 작동하지 않는 이유에 관해서 나는 대단히 혼란 스럽다. 그러나 무엇이든지간에, 그것이 작동한다면 그것은 작동한다 : D 고마워! – Jimmyt1988

+0

삼각형 스트립은 다른 형식입니다. 사각형을 삼각형 스트립으로 포맷 할 수 있지만 인덱스는 다릅니다. 예를 들어 [삼각형 스트립에 관한 위키피디아 기사] (http://en.wikipedia.org/wiki/Triangle_strip)를 참조하십시오. 어쨌든, 아무런 문제가 없습니다 :) –

+0

당신은 그것이 무엇인지 압니다. 뒷면 새김 - 나는 마지막 색인의 순서를 바꾸었고 그것이 작동하기 시작했습니다. 부끄러움 – Jimmyt1988