3

How do I draw a full screen quad that shows red on the screen?

concept3d
  • 12,706
  • 4
  • 45
  • 57
terry
  • 31
  • 1
  • 4

1 Answers1

3

First, set the primitive topology to TRIANGLESTRIP (ID3D11DeviceContext::IASetPrimitiveTopology), set the following shaders then call devicecontext->Draw(4,0). You don't even need vertex buffers for this because of the automatic system value of vertex id in the shader.

float4 VertexShader(uint vI : SV_VERTEXID):SV_POSITION
{
    float2 texcoord = float2(vI&1,vI>>1); //you can use these for texture coordinates later
    return float4((texcoord.x-0.5f)*2,-(texcoord.y-0.5f)*2,0,1);
}

float4 PixelShader(float4 pos : SV_POSITION):SV_TARGET
{
    return float4(1,0,0,1); //the red color
}
János Turánszki
  • 3,079
  • 3
  • 15
  • 22