# create 2 index buffer

This topic is 2051 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi there, ive just read the following tutorial http://www.braynzarsoft.net/index.php?p=D3D11INDICES
A
nd i started do the exercise 1. Make 2 index buffer.

	Vertex v[] =
{
Vertex( -0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f ),
Vertex( -0.5f,  0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f ),
Vertex(  0.5f,  0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f ),
Vertex(  0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f ),
Vertex(  0.0f,  1.0f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f ),
};

DWORD indices1[] = {
0, 1, 2,
0, 2, 3,
};

DWORD indices2[] = {
1, 2, 4
};

D3D11_BUFFER_DESC indexBufferDesc;
ZeroMemory( &indexBufferDesc, sizeof(indexBufferDesc) );

indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
indexBufferDesc.ByteWidth = sizeof(DWORD) * 2 * 3;
indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
indexBufferDesc.CPUAccessFlags = 0;
indexBufferDesc.MiscFlags = 0;

D3D11_SUBRESOURCE_DATA iinitData;
//D3D11_SUBRESOURCE_DATA iinitData2;

iinitData.pSysMem = indices1;
d3d11Device->CreateBuffer(&indexBufferDesc, &iinitData, &squareIndexBuffer1);

indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
indexBufferDesc.ByteWidth = sizeof(DWORD) * 1 * 3;
indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
indexBufferDesc.CPUAccessFlags = 0;
indexBufferDesc.MiscFlags = 0;

iinitData.pSysMem = indices2;
d3d11Device->CreateBuffer(&indexBufferDesc, &iinitData, &squareIndexBuffer2);

d3d11DevCon->IASetIndexBuffer( squareIndexBuffer1, DXGI_FORMAT_R32_UINT, 0);
d3d11DevCon->IASetIndexBuffer( squareIndexBuffer2, DXGI_FORMAT_R32_UINT, 0);


And the questions are:

1.i use the same D3D11_BUFFER_DESC and D3D11_SUBRESOURCE_DATA to create 2 Index buffer ( adjust the fied of D3D11_BUFFER_DESC )
Is it possible?
2. the function d3d11DevCon->IASetIndexBuffer(). i so confuse about the third parametter, how can we know the offset? Thankyou

##### Share on other sites

1. Yes it is.

2. the offset param defines the start of the buffer. Mostly this is zero (so the first index used is the first inside the buffer). You could however have 1 big buffer made of multiple smaller onces, that is where the offset comes into place.

##### Share on other sites

thankyou .

d3d11DevCon->IASetIndexBuffer( squareIndexBuffer1, DXGI_FORMAT_R32_UINT, 0);
d3d11DevCon->IASetIndexBuffer( squareIndexBuffer2, DXGI_FORMAT_R32_UINT, 0);

the second index buffer set  to the IA stage require the offset, how can we get the size of the first buffer ?

Edited by linhmai27

##### Share on other sites

Sounds like you're trying to set 2 index buffers at once, you can have set only 1 index buffer at a time.

##### Share on other sites

the article say "Make 2 buffers", can u post the code, i can't imagine it . If there is 1 buffer set. Thankyou so much, i have tried but its all blank screen.

Edited by linhmai27

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013595
×