Vertexes not getting drawn

Started by
7 comments, last by noatom 11 years, 6 months ago
[source lang="cpp"]// Create vertex buffer
Vertex vertices[] =
{
//paddle 1
{ XMFLOAT3(-10.0f, -100.0f, 0.0f), (const float*)&Colors::White },
{ XMFLOAT3(-10.0f, +140.0f, 0.0f), (const float*)&Colors::Black },
{ XMFLOAT3(+10.5f, +140.0f, 0.0f), (const float*)&Colors::Red },
{ XMFLOAT3(+10.5f, -100.0f, 0.0f), (const float*)&Colors::Green },

//paddle
{ XMFLOAT3(-10.0f, -100.0f, 0.0f), (const float*)&Colors::White },
{ XMFLOAT3(-10.0f, +140.0f, 0.0f), (const float*)&Colors::Black },
{ XMFLOAT3(+10.5f, +140.0f, 0.0f), (const float*)&Colors::Red },
{ XMFLOAT3(+10.5f, -100.0f, 0.0f), (const float*)&Colors::Green }
};

D3D11_BUFFER_DESC vbd;
vbd.Usage = D3D11_USAGE_IMMUTABLE;
vbd.ByteWidth = sizeof(Vertex) * 8;
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = 0;
vbd.MiscFlags = 0;
vbd.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA vinitData;
vinitData.pSysMem = vertices;
HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mBoxVB));


// Create the index buffer

UINT indices[] = {
// paddle1
0, 1, 2,
0, 2, 3,

//paddl2
4,5,6,
4,7,6


};

D3D11_BUFFER_DESC ibd;
ibd.Usage = D3D11_USAGE_IMMUTABLE;
ibd.ByteWidth = sizeof(UINT) * 12;
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
ibd.CPUAccessFlags = 0;
ibd.MiscFlags = 0;
ibd.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA iinitData;
iinitData.pSysMem = indices;
HR(md3dDevice->CreateBuffer(&ibd, &iinitData, &mBoxIB));


D3DX11_TECHNIQUE_DESC techDesc;
mTech->GetDesc( &techDesc );
for(UINT p = 0; p < techDesc.Passes; ++p)
{
XMMATRIX w = XMMatrixTranslation(510,0,0);
XMMATRIX worldViewProj = w*view*proj;
mfxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj));
mTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);

// 36 indices for the box.
md3dImmediateContext->DrawIndexed(6, 0, 0);

////////////////////////////////////////////////////////////////

XMMATRIX w2 = XMMatrixTranslation(0,0,0);
XMMATRIX worldViewProj2 = w2*view*proj;
mfxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj2));
mTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);

// 36 indices for the box.
md3dImmediateContext->DrawIndexed(6, 6,4);


}[/source]


As you can see I use the DrawIndexed 2 times,the first time it works perfectly,the second time NOTHING gets drawn! Can someone tell me why? I forgot something?
Advertisement
Do you mean that second time your program enters the drawing part nothing gets drawn or that the second draw command has no effect?

I hope that the code isn't the actual code from your program since you don't need to and must not create the vertex buffer every time you want something to get drawn. It's something you do once, and after you can use the same data for the rest of the program.

Also, the paddle 1 and paddle 2 geometry seems to be the same, you may want to use the same geometry for them both.

Maybe you forget to bind your vertex and index buffer before drawing?

Cheers!
ofcourse I don't create a vertex buffer every time I draw a frame,that wouldn't even be possible,the app would crash before I could even see it on the screen.I just extracted the code so you can see how they're defined.

Yes the geometry for the paddles is exactly the same,but that's not the point,I just want to see how this work,how drawing two things from the same buffer is working.Is more like an exercise for me...

So md3dImmediateContext->DrawIndexed(6, 0, 0); draws the first one perfectly but the second one just doesn't get drawn!
but
I guess you have tried to draw the first paddle multiple times with different transforms to verify that things works as they should?

[s]The drawing commands seems to be fine in my opinion.[/s] I guess you could show some code before the drawing calls so that the everything is set correctly for drawing.

[edit]

From MSDN:

void DrawIndexed( [in] UINT IndexCount, [in] UINT StartIndexLocation, [in] INT BaseVertexLocation);
BaseVertexLocation [in] Type: INT A value added to each index before reading a vertex from the vertex buffer.


I think that your 3rd value should be 0.

[edit]

Cheers!
[source lang="cpp"]md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::LightSteelBlue));
md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);

md3dImmediateContext->IASetInputLayout(mInputLayout);
md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

UINT stride = sizeof(Vertex);
UINT offset = 0;
md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset);
md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0);

// Set constants

XMMATRIX view = XMLoadFloat4x4(&mView);
XMMATRIX proj = XMLoadFloat4x4(&mProj);[/source]

That's what happens before the code I gave you(before it actually starts the drawing process)
Check my earlier answer. I made some changes.

Best regards!
yes but doesn't that just make it draw the same first 4 vertices just that they are transformed? I want to draw the last 4 of them!
Nope,

since your indices define already that you want to draw the 4 last of them.

You can test it easily by setting different colors to the last vertices.

[edit]

BaseVertexLocation [in] Type: INT A value added to each index before reading a vertex from the vertex buffer.

If you put 4 as the BaseVertexLocation, you'll be reading outside of your vertex buffer. Consider adding 4 to values

//paddl2
4,5,6,4,7,6 -> 8,9,10,8,11,10

All of them are out of bounds.

[edit]


Cheers!
Thanks a lot,got it where I was wrong!

This topic is closed to new replies.

Advertisement