Jump to content
  • Advertisement
Sign in to follow this  
nuclear123

[D3D11] Filling a rectangle?

This topic is 2504 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. Any advice is greatly appreciated! thanks

Share this post


Link to post
Share on other sites
Advertisement
Put a 4d vector or 4d float in your vertex structure to represent your color (rgba), add a color element to your vertex layout, then add a color input and output to your vertex shader, and a color input for your pixel shader. pass the color input in your vertex shader to the pixel shader, and just return the color value in your pixel shader. like this for example:


struct Vertex // Vertex Structure
{
XMFLOAT3 pos;
XMFLOAT4 color;
};


D3D11_INPUT_ELEMENT_DESC layout[] = // Input layout
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};


// Make sure you have the correct number of elements when you create your input layout
UINT numElements = ARRAYSIZE(layout);

d3d11Device->CreateInputLayout( layout, numElements, VS_Buffer->GetBufferPointer(),
VS_Buffer->GetBufferSize(), &vertLayout );


// Effect File
struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float4 Color : COLOR;
};

VS_OUTPUT VS(float4 inPos : POSITION, float4 inColor : COLOR)
{
VS_OUTPUT output;

output.Pos = inPos;
output.Color = inColor;

return output;
}

float4 PS(VS_OUTPUT input) : SV_TARGET
{
return input.Color;
}


http://braynzarsoft....hp?p=D3D11COLOR


EDIT:
My bad, i didn't realize this was a double post

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!