I’m trying to create a dice however I’ve been caught on this for a really very long time to no avail.
My outcomes seem like this:
All of my indices are tousled! Some are related to the unsuitable vertices and most weirdly the sunshine blue vertex is alone; it is not a whole triangle.
Right here is my initialization operate:
swap_chain_description.BufferDesc.Width = 0; // Determine it out your self
swap_chain_description.BufferDesc.Top = 0;
swap_chain_description.BufferDesc.Format = DXGI_FORMAT::DXGI_FORMAT_B8G8R8A8_UNORM; // Format of pixels
swap_chain_description.BufferDesc.RefreshRate.Numerator = 0; // Decide no matter is already there
swap_chain_description.BufferDesc.RefreshRate.Denominator = 0; // Decide no matter is already there
swap_chain_description.BufferDesc.Scaling = DXGI_MODE_SCALING::DXGI_MODE_SCALING_UNSPECIFIED; // Do not want scaling
swap_chain_description.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER::DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; // Scanline order (Interlaced, and so forth)
swap_chain_description.SampleDesc.Depend = 1; // No anti-aliasing
swap_chain_description.SampleDesc.High quality = 0; // No anti-aliasing
swap_chain_description.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // Use buffer as render goal
swap_chain_description.BufferCount = 1; // One again buffer
swap_chain_description.OutputWindow = window; // Use this window
swap_chain_description.Windowed = true; // We would like it windowed
swap_chain_description.SwapEffect = DXGI_SWAP_EFFECT::DXGI_SWAP_EFFECT_DISCARD; // Swap impact that normally has the most effective efficiency
swap_chain_description.Flags = 0u; // No flags
D3D11CreateDeviceAndSwapChain(
nullptr, // Select default adapter
D3D_DRIVER_TYPE::D3D_DRIVER_TYPE_HARDWARE, // Use {hardware} machine
nullptr, // Deal with to driver
0, // No flags
nullptr, // Give us any characteristic stage
0,
D3D11_SDK_VERSION, // Default SDK Model
&swap_chain_description, // Swap chain description
&swap_chain, // Swap Chain
&machine, // System
nullptr, // Output pointer - Units to characteristic stage
&context // Context
);
Microsoft::WRL::ComPtr<ID3D11Resource> back_buffer = nullptr;
swap_chain->GetBuffer(0, __uuidof(ID3D11Resource), &back_buffer);
device->CreateRenderTargetView(
back_buffer.Get(),
nullptr,
&goal
);
// Create depth stencil state
D3D11_DEPTH_STENCIL_DESC depth_stencil_description = {};
depth_stencil_description.DepthEnable = true;
depth_stencil_description.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depth_stencil_description.DepthFunc = D3D11_COMPARISON_LESS;
Microsoft::WRL::ComPtr<ID3D11DepthStencilState> depth_stencil_state;
device->CreateDepthStencilState(&depth_stencil_description, &depth_stencil_state);
// Bind depth state
context->OMSetDepthStencilState(depth_stencil_state.Get(), 1u);
//Create depth stencil texture
Microsoft::WRL::ComPtr<ID3D11Texture2D> depth_stencil;
D3D11_TEXTURE2D_DESC desc_depth = { };
desc_depth.Width = 800u;
desc_depth.Top = 600u;
desc_depth.MipLevels = 1u;
desc_depth.ArraySize = 1u;
desc_depth.Format = DXGI_FORMAT::DXGI_FORMAT_D32_FLOAT;
desc_depth.SampleDesc.Depend = 1u;
desc_depth.SampleDesc.High quality = 0u;
desc_depth.Utilization = D3D11_USAGE::D3D11_USAGE_DEFAULT;
desc_depth.BindFlags = D3D11_BIND_FLAG::D3D11_BIND_DEPTH_STENCIL;
device->CreateTexture2D(&desc_depth, nullptr, &depth_stencil);
// Create depth stensil state
D3D11_DEPTH_STENCIL_VIEW_DESC descDSV = { };
descDSV.Format = DXGI_FORMAT::DXGI_FORMAT_D32_FLOAT;
descDSV.ViewDimension = D3D11_DSV_DIMENSION::D3D11_DSV_DIMENSION_TEXTURE2D;
descDSV.Texture2D.MipSlice = 0u;
device->CreateDepthStencilView(depth_stencil.Get(), &descDSV, &depth_stencil_view);
Microsoft::WRL::ComPtr<ID3D11RasterizerState> rasterizer_state = nullptr;
D3D11_RASTERIZER_DESC rasterizer_state_description = { };
rasterizer_state_description.FillMode = fill_mode;
rasterizer_state_description.CullMode = cull_mode;
rasterizer_state_description.FrontCounterClockwise = true;
rasterizer_state_description.DepthBias = false;
rasterizer_state_description.DepthBiasClamp = 0;
rasterizer_state_description.SlopeScaledDepthBias = 0;
rasterizer_state_description.DepthClipEnable = true;
rasterizer_state_description.ScissorEnable = false;
rasterizer_state_description.MultisampleEnable = false;
rasterizer_state_description.AntialiasedLineEnable = false;
HANDLE_POSSIBLE_EXCEPTION(device->CreateRasterizerState(&rasterizer_state_description, rasterizer_state.GetAddressOf()));
context->RSSetState(rasterizer_state.Get());
// Configure Viewport
viewport.Width = 800u;
viewport.Top = 600u;
viewport.MinDepth = 0;
viewport.MaxDepth = 1;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
context->RSSetViewports(1u, &viewport);
Microsoft::WRL::ComPtr<ID3D11BlendState> blend_state = nullptr;
D3D11_BLEND_DESC blend_description = {};
ZeroMemory(&blend_description, sizeof(D3D11_BLEND_DESC));
blend_description.RenderTarget[0].BlendEnable = true;
blend_description.RenderTarget[0].SrcBlend = D3D11_BLEND::D3D11_BLEND_SRC_ALPHA;
blend_description.RenderTarget[0].DestBlend = D3D11_BLEND::D3D11_BLEND_INV_SRC_ALPHA;
blend_description.RenderTarget[0].BlendOp = D3D11_BLEND_OP::D3D11_BLEND_OP_ADD;
blend_description.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND::D3D11_BLEND_ONE;
blend_description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND::D3D11_BLEND_ZERO;
blend_description.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP::D3D11_BLEND_OP_ADD;
blend_description.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE::D3D11_COLOR_WRITE_ENABLE_ALL;
device->CreateBlendState(&blend_description, &blend_state);
context->OMSetBlendState(blend_state.Get(), 0, 0xffffffff);
// Set Primitive Topology to triangle checklist
set_primitive_topology(primitive_topology);
context->OMSetRenderTargets(1u, goal.GetAddressOf(), depth_stencil_view.Get());
My primitive topology is about to D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST
, which is why I am confused about why there’s that uncompleted triangle within the outcome.
That is my draw operate:
set_vertex_buffer(object);
set_index_buffer(object);
/* I do not suppose the shader and fixed buffer enterprise issues so I did not embody it right here, it is right here although */
// Draw it
context->DrawIndexed((unsigned int)object.look.mesh.indices.dimension(), 0u, 0u);
Setting my index and vertex buffers is straight-forward:
Microsoft::WRL::ComPtr<ID3D11Buffer> vertex_buffer = nullptr;
// Buffer Description (Vertex)
D3D11_BUFFER_DESC buffer_description = { };
buffer_description.BindFlags = D3D11_BIND_VERTEX_BUFFER;
buffer_description.Utilization = D3D11_USAGE_DEFAULT;
buffer_description.CPUAccessFlags = 0u;
buffer_description.MiscFlags = 0u;
buffer_description.ByteWidth = sizeof(Vertex) * object.look.mesh.vertices.dimension();
buffer_description.StructureByteStride = sizeof(Vertex);
D3D11_SUBRESOURCE_DATA knowledge = { };
knowledge.pSysMem = &object.look.mesh.vertices[0];
// Creating the Buffer
device->CreateBuffer(&buffer_description, &knowledge, &vertex_buffer);
// Bind Vertex Buffer to Pipeline
UINT stride = sizeof(Vertex);
UINT offset = 0u;
context->IASetVertexBuffers(0u, 1u, vertex_buffer.GetAddressOf(), &stride, &offset);
and
Microsoft::WRL::ComPtr<ID3D11Buffer> index_buffer;
D3D11_BUFFER_DESC index_buffer_description = { };
index_buffer_description.BindFlags = D3D11_BIND_INDEX_BUFFER;
index_buffer_description.Utilization = D3D11_USAGE_DEFAULT;
index_buffer_description.CPUAccessFlags = 0u;
index_buffer_description.MiscFlags = 0u;
index_buffer_description.ByteWidth = sizeof(unsigned brief) * object.look.mesh.indices.dimension();
index_buffer_description.StructureByteStride = sizeof(unsigned brief);
D3D11_SUBRESOURCE_DATA subresource_data = { };
subresource_data.pSysMem = &object.look.mesh.indices[0];
device->CreateBuffer(&index_buffer_description, &subresource_data, &index_buffer);
// Bind index buffer
context->IASetIndexBuffer(index_buffer.Get(), DXGI_FORMAT_R16_UINT, 0u);
Right here is the place I am initializing my vertices and indices, I additionally drew them out:
Mesh mesh = {
{
{-1.0f, -1.0f, -1.0f, 255, 0, 0, 255},
{ 1.0f, -1.0f, -1.0f, 0, 255, 0, 255 },
{ -1.0f, 1.0f, -1.0f, 0, 0, 255, 255 },
{ 1.0f, 1.0f, -1.0f, 255, 0, 255, 255 },
{ -1.0f, -1.0f, 1.0f, 255, 255, 0, 255 },
{ 1.0f, -1.0f, 1.0f, 0, 255, 255, 255 },
{ -1.0f, 1.0f, 1.0f, 255, 0, 0, 255 },
{ 1.0f, 1.0f, 1.0f, 0, 255, 0, 255 }
},
{
0u, 2u, 1u, 2u, 3u, 1u,
1u, 3u, 5u, 3u, 7u, 5u,
2u, 6u, 3u, 3u, 6u, 7u,
4u, 5u, 7u, 4u, 7u, 6u,
0u, 4u, 2u, 2u, 4u, 6u,
0u, 1u, 4u, 1u, 5u, 4u,
}
};
Please ask me something about my code if you might want to, I’m very confused about why my code is doing this.
Thanks.