Sign in to follow this  
Kurt-olsson

Why only one point DIrectX11

Recommended Posts

I am trying to change from triangle_list to point_list

but only 1 point is showing. what am i missing to set to 1 that was 3 before?

[source lang="cpp"] // create a triangle using the VERTEX struct
VERTEX OurVertices[] =
{
{0.0f, 0.1f, 0.0f, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f)}, //This is the only one showing on screen.
{0.0f, 0.0f, 0.0f, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f)},
{0.1f, 0.1f, 0.0f, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f)},
};


// create the vertex buffer
D3D11_BUFFER_DESC bd;
ZeroMemory(&bd, sizeof(bd));

bd.Usage = D3D11_USAGE_DYNAMIC; // write access access by CPU and GPU
bd.ByteWidth = sizeof(VERTEX); // size is the VERTEX struct * 3
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; // use as a vertex buffer
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; // allow CPU to write in buffer

dev->CreateBuffer(&bd, NULL, &pVBuffer); // create the buffer


// copy the vertices into the buffer
D3D11_MAPPED_SUBRESOURCE ms;
devcon->Map(pVBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms); // map the buffer
memcpy(ms.pData, OurVertices, sizeof(OurVertices)); // copy the data
devcon->Unmap(pVBuffer, NULL);
// unmap the buffer

// select which vertex buffer to display
UINT stride = sizeof(VERTEX);
UINT offset = 0;
devcon->IASetVertexBuffers(0, 1, &pVBuffer, &stride, &offset);

// select which primtive type we are using
devcon->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
// draw the vertex buffer to the back buffer
// set the new values for the constant buffer
devcon->UpdateSubresource(pCBuffer, 0, 0, &matFinal, 0, 0);
//As many OurVertices.count.
devcon->Draw(30, 0);[/source]

Share this post


Link to post
Share on other sites
There's a lot of reasons that this can happen, and it's notoriously difficult to determine just by looking at code. Try debugging the values on teh CPU side and see what you get on the GPU side with PIX, that'll give you a good place to start.

Share this post


Link to post
Share on other sites
You need to allocate more space in the vertex buffer. Funnily enough, the [i]comment [/i]in the relevant line is correct but the actual statement isn't [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Also, if you only have 3 vertices, you should not try to draw 30 of them. That can cause an access violation in the GPU, and can ultimately result in very funky behavior, including missing geometry or crash. Edited by Nik02

Share this post


Link to post
Share on other sites
D3D11 actually does support drawing beyond the end of a vertex buffer; you'll get "Vertex Buffer at the input vertex slot 0 is not big enough for what the Draw*() call expects to traverse. This is OK, as reading off the end of the Buffer is defined to return 0. However the developer probably did not intend to make use of this behavior. [ EXECUTION WARNING #356: DEVICE_DRAW_VERTEX_BUFFER_TOO_SMALL ]" under the debug runtimes, but it won't crash.

Share this post


Link to post
Share on other sites
Ah, didn't remember that :)

Anyway, in this case, taking geometry beyond the buffer is very likely not the original intention.

As a side note, it is also valid to not use a vertex buffer at all, if you don't use any components from the input assembler and instead construct the data in the vertex shader itself by using the SV_VertexId for flow control.

Share this post


Link to post
Share on other sites
I am still fighting to get along with my triangles and squares. =)
but i have the triangleStrip ok but my Triangle_list wont render texture correct.

I guess i need to go back to basic samples. again, thanks for the answers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this