Jump to content
  • Advertisement
Sign in to follow this  
nuclear123

[D3D11] Filling a rectangle?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

i'm still rather new to direct x and i've currently just drawn a box on the screen. I'm wanting to FILL this rectangle in with a solid color but i'm unsure on how to perform this approach.

The box is being drawn with the following C++ code.


// Create Vertex Buffer
SVertex3 Vertex[] =
{
{ D3DXVECTOR3(0.8f, 0.8f, 0.0f), D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f) },
{ D3DXVECTOR3(-0.8f, 0.8f, 0.0f), D3DXCOLOR(0.5f, 0.5f, 0.5f, 0.5f) },
{ D3DXVECTOR3(-0.8f, -0.8f, 0.0f), D3DXCOLOR(0.5f, 0.5f, 0.5f, 0.5f) },
{ D3DXVECTOR3(0.8f, -0.8f, 0.0f), D3DXCOLOR(0.5f, 0.5f, 0.5f, 0.5f) }
};

// Create Index List
DWORD indexList[6] = {0, 1, 2, 3, 0}; // Box



m_pDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP);
m_pDeviceContext->DrawIndexed(5, 0, 0);

Share this post


Link to post
Share on other sites
Advertisement
To draw solid triangles instead of lines change the primitive topology to a triangle list (or triangle strip). You'll also need a new index buffer for that topology. Also, by default, triangles are only rendered if their vertices are in clockwise order on screen to avoid unnecessary rendering of the inside of a 3D model.

Share this post


Link to post
Share on other sites
awesome thanks man got it working :) I now want to draw my box with just lines instead of having a filled in CENTER. The only way i can think of in doing this is to set the RasterizerStage to draw in wireframe. Is there another way to do this? Also I cant find any information on how to change the RasterizerStage's state within my effect file! thanks

Share this post


Link to post
Share on other sites
You can set the topology back to a line list or strip like you had it, but i think lists are easier to understand. For a line list, you would set the indices "2" at a time instead of 3 like you would for a triangle (or if your not using indices, just do them in order in the vertex buffer, so that every two is one line instead of every three)

about the rasterizer state in the effect file, this might shed some light:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb205052(v=vs.85).aspx#Rasterizer

Share this post


Link to post
Share on other sites
here is my current vertex buffer and indices list



// Create Vertex Buffer
SVertex3 Vertex[] =
{
// quad with unique vertices
{ D3DXVECTOR3(-0.8f, -0.8f, 1.0f), D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f) }, // bottom left vertex
{ D3DXVECTOR3(-0.8f, 0.8f, 1.0f), D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f) }, // top left vertex
{ D3DXVECTOR3(0.8f, 0.8f, 1.0f), D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f) }, // top right vertex
{ D3DXVECTOR3(0.8f, -0.8f, 1.0f), D3DXCOLOR(1.0f, 1.0f, 0.5f, 0.0f) } // bottom right vertex

};



// Create Index List
DWORD indexList[6] = {0, 1, 2, // First bottom triangle
0, 2, 3}; // Second top triangle



What is the easiest way to setup this vertex information so it can be used with either LINESTRIP or TRIANGLESTRIP? do i need to make my vertex buffer and index list dynamic? Also where would the changing of indice array be used at when the user decided to switch topologies

Share this post


Link to post
Share on other sites
you will just need to have two index buffers, one for the lines, and one for the triangles.

linestrip index buffer would probably be (two for the first line, one for each line after that)
{0, 1,
2,
3,
0}

linelist index buffer would be (two for each line)
{0, 1,
1, 2,
2, 3,
3, 0}

to change the topology, you would check if a button was pressed or an option changed, then set a variable such as an integer (since the topologies are enumerated):

if(isButtonTPressed == true){ // Check if the "T" button was pressed
whichTopology == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
}
elseif(isButtonLPressed == true){ // Check if the "L" button was pressed
whichTopology == D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP;
}

d3d11DevCon->IASetPrimitiveTopology( whichTopology );



You bind the index buffer to the IA right before you draw any of your objects using this:


if(whichTopology == D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP){
D3D11DeviceContext->IASetIndexBuffer( objectLineIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
}
elseif whichTopology == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST){
D3D11DeviceContext->IASetIndexBuffer( objectTriangleIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
}
// Draw your object


I would use [color=#000000][font=Consolas, Courier, monospace]

D3D11_PRIMITIVE_TOPOLOGY_LINELIST [/font]for complex models though, because using a linestrip, every line must be connected to another, and each line can only be connected to a maximum of two other lines (one on each end)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!