- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 DirectX 中的顶点和索引缓冲区进行绘图时遇到了一些问题。
这是一个定义立方体的函数,但我已经注释掉了除正面之外的所有内容:
void GeometryGenerator::CreateCube(MeshData& meshData)
{
meshData.Vertices.resize(8);
meshData.Indices.resize(6);
float width;
float height;
float depth;
width = 45;
height = 45;
depth = 45;
XMFLOAT3 pos[8] =
{
XMFLOAT3(-0.5f * width, -0.5f * height, -0.5f * depth),
XMFLOAT3(-0.5f * width, -0.5f * height, 0.5f * depth),
XMFLOAT3(-0.5f * width, 0.5f * height, -0.5f * depth),
XMFLOAT3(-0.5f * width, 0.5f * height, 0.5f * depth),
XMFLOAT3( 0.5f * width, -0.5f * height, -0.5f * depth),
XMFLOAT3( 0.5f * width, -0.5f * height, 0.5f * depth),
XMFLOAT3( 0.5f * width, 0.5f * height, -0.5f * depth),
XMFLOAT3( 0.5f * width, 0.5f * height, 0.5f * depth)
};
unsigned short k[6] =
{
////1,0,2, // -x
////2,1,0,
////6,5,1, // +x
////6,7,5,
////
////0,1,5, // -y
////0,5,4,
////
////2,6,7, // +y
////2,7,3,
////4,6,0, // -z
////6,2,0,
7,3,1, //+z
5,7,1,
};
for(size_t i = 0; i < 8; ++i)
meshData.Vertices[i].Position = pos[i];
for(size_t i = 0; i < 6; ++i)
meshData.Indices[i] = k[i];
它绘制了一个三角形和一条线,两者都没有到达预期的顶点。一个三角形看起来像是覆盖了 7,3,0,并且有一条线覆盖了 1,0。我在下面附上了旋转 90 度的图片:
我很乐意发布任何必要的代码,但我怀疑您是否希望我发布我的整个项目。我认为可能有用的一些东西是......
我的顶点结构:
struct Vertex
{
DirectX::XMFLOAT3 pos;
DirectX::XMFLOAT3 color;
};
我的输入布局:
const D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
{
{ "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 },
};
我的顶点着色器:
cbuffer ModelViewProjectionConstantBuffer : register(b0)
{
matrix model;
matrix view;
matrix projection;
};
struct VertexShaderInput
{
float3 pos : POSITION;
float3 color : COLOR0;
};
struct VertexShaderOutput
{
float4 pos : SV_POSITION;
float3 color : COLOR0;
};
VertexShaderOutput main(VertexShaderInput input)
{
VertexShaderOutput output;
float4 pos = float4(input.pos, 1.0f);
// Transform the vertex position into projected space.
pos = mul(pos, model);
pos = mul(pos, view);
pos = mul(pos, projection);
output.pos = pos;
// Pass through the color without modification.
output.color = input.color;
return output;
}
原始拓扑:
m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
索引缓冲区格式:
m_d3dContext->IASetIndexBuffer(
m_indexBuffer.Get(),
DXGI_FORMAT_R16_UINT,
0);
顶点跨度和偏移:
UINT stride = sizeof(Vertex);
UINT offset = 0;
m_d3dContext->IASetVertexBuffers(
0,
1,
m_vertexBuffer.GetAddressOf(),
&stride,
&offset);
这里是 DrawIndexed 调用:
m_d3dContext->DrawIndexed(
m_Indices.size(),
0,
0);
获取数据并创建索引缓冲区的代码:
GeometryGenerator generator;
GeometryGenerator::MeshData cubeData;
generator.CreateCube(cubeData);
//m_Indices is a std::Vector<Vertex>
m_Indices.resize(cubeData.Indices.size());
for(size_t i = 0; i < cubeData.Indices.size(); i++)
m_Indices[i] = cubeData.Indices[i];
D3D11_SUBRESOURCE_DATA indexBufferData = {0};
indexBufferData.pSysMem = &m_Indices[0];
indexBufferData.SysMemPitch = 0;
indexBufferData.SysMemSlicePitch = 0;
const UINT indexBufferWidth = m_Indices.size() * sizeof(UINT);
CD3D11_BUFFER_DESC indexBufferDesc(indexBufferWidth, D3D11_BIND_INDEX_BUFFER);
DX::ThrowIfFailed(
m_d3dDevice->CreateBuffer(
&indexBufferDesc,
&indexBufferData,
&m_indexBuffer));
感谢您的帮助!我一直在研究 Frank Luna 的“Introduction to 3D Game Programming with DirectX 11”,但我找不到关于此类问题的任何讨论。
最佳答案
您很可能在以下其中一项中犯了错误。任何一个错误都可能很容易导致您观察到的问题。
// Input layout defined correctly:
D3D11_INPUT_ELEMENT_DESC vertexDesc[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 } };
// Vertex shader input matches input layout:
VS_OUT main(float3 pos : POSITION)
// Primitive topology set correctly:
context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
// Index buffer format set correctly:
context->IASetIndexBuffer(indexBuffer, DXGI_FORMAT_R16_UINT, 0);
// Vertex stride and offset set correctly:
UINT stride = sizeof(XMFLOAT3);
UINT offset = 0;
context->IASetVertexBuffers(0, 1, vertexBuffer, &stride, &offset);
// Draw arguments are correct:
context->DrawIndexed(6, 0, 0);
关于c++ - DirectX Index Buffer 索引顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19529899/
我想用groupshared DirectX 计算着色器中的内存以减少全局内存带宽并有望提高性能。我的输入数据是 Texture2D我可以像这样使用二维索引来访问它: Input[threadID.x
我一直在查看 MSDN 和 Microsoft.com,但只能找到存档论坛。现在还有 Microsoft Run DirectX 论坛吗? 最佳答案 在这里: http://forums.xna.co
我正在尝试将网格切成两半,或者至少能够实时删除其中的面。我想知道如何去做这件事? 锁定顶点缓冲区,将选定的面或顶点 memset 为 0,对我不起作用。有没有人对此有解决方案或教程,我真的希望在我的程
我想这是一个相当深入的主题,因此任何带有洞察信息的网址也很乐意接受。我一直在使用原生 DirectX,但从未管理过。另一方面,大多数情况下,在开发不需要高级 GPU 渲染的其他类型的应用程序时,我通常
微软的开源DirectX Shader Compiler描述了一种用于 HLSL 着色器的新中间语言 (IL) 的格式,称为 DXIL。 文档引用了从以前的 HLSL IL(称为 DXBC)到新 DX
我需要同时在更大的显示器上全屏显示在我的应用程序中播放的视频。在某些显卡上,这称为影院模式,使用显卡制造商提供的工具进行配置。 我只想用软件来做到这一点。我可以用 DirectX 做到这一点吗? 我的
我问 how to take the screen shot in DirectX并回答了“使用 GetFrontBufferData()”。然而,“这个函数在设计上非常慢,并且不应该在任何性能关键路
这让我感到困惑。 DirectX 绕过所有内容并直接与设备驱动程序对话,因此 GDI 和其他常用方法将不起作用 - 除非 Aero 被禁用(或不可用),否则出现的只是屏幕左上角的黑色矩形。我已经尝试了
我们正在开发一个通过 Direct3D 可视化显示信息的应用程序。迟到的客户端请求是能够通过某些远程桌面解决方案查看此应用程序。 有人做过类似的事情吗?哪些选项可用/不可用?我正在考虑 RDC、VNC
由于D3DPOOL_SCRATCH处理速度较慢,所以我编写了桌面捕获程序以引用网上的报告。然而,结果却是一片漆黑的画面。这是控制台程序的结果还是有其他原因? #include #include #
背景 我正在玩东方系列游戏之一的不朽之夜。射击按钮是“z”,移动较慢是“shift”,方向键移动。对我来说不幸的是,使用 shift-z 重影我的右箭头键,所以我在射击时无法向右移动。这种重影发生在所
我已经阅读了关于 DirectX 光栅化规则的在线文档,但我仍然不明白为什么这段代码没有在屏幕上产生任何可见的东西? target->SetAntialiasMode(D2D1_ANTIALIAS_M
如您所知,当我们想要在 DirectX 中绘制三维对象时,我们应该定义相机。现在我们有一个设备对象,它的名称是“device1”。这是我的问题: device1.View = Matrix.Look.
我正在使用桌面复制 API 从一个 GPU 捕获桌面,并且需要将纹理(位于 GPU 内存中)复制到另一个 GPU。为此,我有一个捕获线程,用于获取桌面图像,然后使用 ID3D11DeviceConte
假设 DX12 被挂接到叠加渲染的场景,看起来挂接的最佳函数是 IDXGISwapChain::Present,与 DX11 的方式相同。将此函数 Hook 后,交换链就可用,并且可以从中检索设备以创
当帧开始时,我会进行逻辑更新并在此之后进行渲染。 在我的渲染代码中,我做通常的事情。我设置了一些状态、缓冲区、纹理,并通过调用 Draw 来结束。 m_deviceContext->Draw(
我使用 DirectX 9.0 制作了一个小型 3D 查看器应用程序。现在我想添加一些编辑功能。假设我想编辑一个大多边形。当用户编辑形状时,顶点将被添加、删除和移动。现在每个多边形都存储为顶点缓冲区。
我编写了一个应用程序,它可以在 OpenGL、DirectX 9 和 DirectX 11 之间切换以进行渲染,而无需重新启动或重新创建窗口。在 OpenGL 和 DirectX 9 以及 Direc
如何在 DirectX 中执行此操作? glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); 不知何故,我似乎无
msdn documentation解释了在 directx 11 中,有多种方法可以通过编程方式填充 directx 11 纹理: (1) 使用默认使用纹理创建纹理并使用内存中的数据对其进行初始化
我是一名优秀的程序员,十分优秀!