Then I just create the vertex buffer and index buffer normally. I set the primitive type to triangle list. w and h are just the size of the quad that I generate. But when I render this with DrawIndexed it only draws a triangle. Is there anything wrong with my vertex/index data?
Is it ok to use 4 verticles for 2 triangles in DX11 ?
Try giving coordinates for both triangles one after the other , see what happens then.
Another thing , I'm too tired to look at that right now but make sure the second triangle isn't facing the opposite direction ( so that culling removes it )
Off the top of my head ...
Sorry, I was sick and couldn't get on. I already tried to disable culling and that didn't work. I'll post the drawing code as soon as I can get to the computer that it's on. DX debug isn't on. I know that DirectX11 supports drawing a quad with four vertices because it supports indexed primitives and that's what they're for.
I just opened it up in PIX and it shows two primitives, and only three vertices. The first primitive is made up of the first three vertices like I expected. The second one is just made of the last vertex over and over again. I init the vertex and index data like I showed above, and then I create the buffers like this:
CDX11MeshBuffer::CDX11MeshBuffer(
ID3D11Device* d3dDevice,
const std::string& name,
E_PRIMITIVE_TYPE primitiveType,
IMaterial* defaultMat,
bool isStatic,
SVertex vertices[],
unsigned int indices[],
unsigned int numIndices)
:IMeshBuffer(name, primitiveType, defaultMat, isStatic),
m_stride(0), m_offset(0), m_numIndices(numIndices)
{
//Create index buffer
{
core::DebugUtils::out << "Creating index buffer.\n";
D3D11_BUFFER_DESC bufferDesc;
ZeroMemory( &bufferDesc, sizeof(bufferDesc) );
if ( m_isStatic )
bufferDesc.Usage = D3D11_USAGE_IMMUTABLE;//Or a different static format if this is the wrong one.
else
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
bufferDesc.ByteWidth = sizeof( unsigned int ) * 3;
bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA initData;
initData.pSysMem = indices;
initData.SysMemPitch = 0;
initData.SysMemSlicePitch = 0;
if ( FAILED(d3dDevice->CreateBuffer( &bufferDesc, &initData, &m_indexBuffer ) ) )
{
core::DebugUtils::out << "Error: Failed to create index buffer.\n";
m_indexBuffer = 0;
}
}
//Create vertex buffer
{
core::DebugUtils::out << "Creating vertex buffer.\n";
D3D11_BUFFER_DESC bd;
ZeroMemory( &bd, sizeof(bd) );
if ( m_isStatic )
bd.Usage = D3D11_USAGE_IMMUTABLE;//Or a different static format if this is the wrong one.
else
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof( SVertex ) * 3;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
bd.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA initData;
ZeroMemory( &initData, sizeof(initData) );
initData.pSysMem = vertices;
if ( FAILED(d3dDevice->CreateBuffer( &bd, &initData, &m_vertexBuffer ) ) )
{
core::DebugUtils::out << "Error: Failed to create vertex buffer.\n";
m_vertexBuffer = 0;
}
}
//Calculate stride and offset
m_stride = sizeof(SVertex);
m_offset = 0;
}