首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未渲染偶数索引的DirectX 11模型

未渲染偶数索引的DirectX 11模型
EN

Stack Overflow用户
提问于 2012-11-05 23:19:56
回答 1查看 927关注 0票数 1

我有一个关于DirectX11渲染的问题-如果我尝试渲染多个模型,我看到的只是索引奇怪的模型。所有使用偶数索引渲染的模型都不可见。

我的代码基于rastertek教程:

代码语言:javascript
复制
m_dx->BeginScene(0.0f, 0.0f, 0.0f, 1.0f);
{
    m_camera->Render();

    XMMATRIX view;
    m_camera->GetViewMatrix(view);

    XMMATRIX world;
    m_dx->GetWorldMatrix(world);

    XMMATRIX projection;
    m_dx->GetProjectionMatrix(projection);

    XMMATRIX ortho;
    m_dx->GetOrthoMatrix(ortho);

    world = XMMatrixTranslation(-2, 0, -4);
    m_model->Render(m_dx->GetDeviceContext());
    m_texture_shader->Render(m_dx->GetDeviceContext(), m_model->GetIndicesCount(), world, view, projection,
        m_model->GetTexture());

    world = XMMatrixTranslation(2, 0, -2);
    m_model->Render(m_dx->GetDeviceContext());
    m_texture_shader->Render(m_dx->GetDeviceContext(), m_model->GetIndicesCount(), world, view, projection,
        m_model->GetTexture());

    world = XMMatrixTranslation(0, 0, -3);
    m_model->Render(m_dx->GetDeviceContext());
    m_texture_shader->Render(m_dx->GetDeviceContext(), m_model->GetIndicesCount(), world, view, projection,
        m_model->GetTexture());

}
m_dx->EndScene();

模型渲染方法

代码语言:javascript
复制
UINT stride, offset;

stride = sizeof(VertexPosTextureNormal);
offset = 0;

device_context->IASetVertexBuffers(0, 1, &m_vertex_buffer, &stride, &offset);
device_context->IASetIndexBuffer(m_index_buffer, DXGI_FORMAT_R32_UINT, 0);
device_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

着色器渲染方法:

代码语言:javascript
复制
world = XMMatrixTranspose(world);
view = XMMatrixTranspose(view);
projection = XMMatrixTranspose(projection);

D3D11_MAPPED_SUBRESOURCE mapped_subres;
RETURN_FALSE_IF_FAILED(context->Map(m_matrix_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_subres));
MatrixBuffer* data = (MatrixBuffer*)mapped_subres.pData;
data->world = world;
data->view = view;
data->projection = projection;
context->Unmap(m_matrix_buffer, 0);
context->VSSetConstantBuffers(0, 1, &m_matrix_buffer);
context->PSSetShaderResources(0, 1, &texture);

    // render
    context->IASetInputLayout(m_layout);

context->VSSetShader(m_vertex_shader, NULL, 0);
context->PSSetShader(m_pixel_shader, NULL, 0);
context->PSSetSamplers(0, 1, &m_sampler_state);
context->DrawIndexed(indices, 0, 0);

这可能是什么原因呢?

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-06 17:23:48

这段代码-

代码语言:javascript
复制
world = XMMatrixTranspose(world);
view = XMMatrixTranspose(view);
projection = XMMatrixTranspose(projection); 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13235055

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档