Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
StudyDx
Commits
17c163c3
Commit
17c163c3
authored
Dec 22, 2022
by
Administrator
Browse files
add multiple triangles with color
parent
31e225d7
Changes
3
Hide whitespace changes
Inline
Side-by-side
StudyDx/Graphics.cpp
View file @
17c163c3
...
...
@@ -109,16 +109,32 @@ void Graphics::DrawTestTriangle()
struct
Vertex
{
float
x
;
float
y
;
struct
{
float
x
;
float
y
;
}
pos
;
struct
{
float
r
;
float
g
;
float
b
;
}
color
;
};
// create vertex buffer (1 2d triangle at center of screen)
const
Vertex
vertices
[]
=
{
{
0.0
f
,
0.5
f
},
{
0.5
f
,
-
0.5
f
},
{
-
0.5
f
,
-
0.5
f
},
// center
{
0.0
f
,
0.5
f
,
1.0
f
,
0.0
f
,
0.0
f
},
{
0.5
f
,
-
0.5
f
,
0.0
f
,
1.0
f
,
0.0
f
},
{
-
0.5
f
,
-
0.5
f
,
0.0
f
,
0.0
f
,
1.0
f
},
// left top
{
-
0.3
f
,
0.3
f
,
0.0
f
,
1.0
f
,
0.0
f
},
// right top
{
0.3
f
,
0.3
f
,
0.0
f
,
0.0
f
,
1.0
f
},
// center bottom
{
0.0
f
,
-
0.8
f
,
1.0
f
,
0.0
f
,
0.0
f
},
};
wrl
::
ComPtr
<
ID3D11Buffer
>
pVertexBuffer
;
D3D11_BUFFER_DESC
bd
=
{};
...
...
@@ -137,6 +153,29 @@ void Graphics::DrawTestTriangle()
const
UINT
offset
=
0u
;
pContext
->
IASetVertexBuffers
(
0u
,
1u
,
pVertexBuffer
.
GetAddressOf
(),
&
stride
,
&
offset
);
// Create index buffer
const
unsigned
short
indices
[]
=
{
0
,
1
,
2
,
0
,
2
,
3
,
0
,
4
,
1
,
2
,
1
,
5
,
};
wrl
::
ComPtr
<
ID3D11Buffer
>
pIndexBuffer
;
D3D11_BUFFER_DESC
ibd
=
{};
ibd
.
BindFlags
=
D3D11_BIND_INDEX_BUFFER
;
ibd
.
Usage
=
D3D11_USAGE_DEFAULT
;
ibd
.
CPUAccessFlags
=
0u
;
ibd
.
MiscFlags
=
0u
;
ibd
.
ByteWidth
=
sizeof
(
indices
);
ibd
.
StructureByteStride
=
sizeof
(
unsigned
short
);
D3D11_SUBRESOURCE_DATA
isd
=
{};
isd
.
pSysMem
=
indices
;
GFX_THROW_INFO
(
pDevice
->
CreateBuffer
(
&
ibd
,
&
isd
,
&
pIndexBuffer
));
// Bind index buffer to pipeline
pContext
->
IASetIndexBuffer
(
pIndexBuffer
.
Get
(),
DXGI_FORMAT_R16_UINT
,
0u
);
// create pixel shader
wrl
::
ComPtr
<
ID3D11PixelShader
>
pPixelShader
;
wrl
::
ComPtr
<
ID3DBlob
>
pBlob
;
...
...
@@ -160,6 +199,7 @@ void Graphics::DrawTestTriangle()
const
D3D11_INPUT_ELEMENT_DESC
ied
[]
=
{
{
"Position"
,
0
,
DXGI_FORMAT_R32G32_FLOAT
,
0
,
0
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
{
"Color"
,
0
,
DXGI_FORMAT_R32G32B32_FLOAT
,
0
,
8
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
};
GFX_THROW_INFO
(
pDevice
->
CreateInputLayout
(
ied
,
(
UINT
)
std
::
size
(
ied
),
...
...
@@ -188,7 +228,8 @@ void Graphics::DrawTestTriangle()
pContext
->
RSSetViewports
(
1u
,
&
vp
);
GFX_THROW_INFO_ONLY
(
pContext
->
Draw
((
UINT
)
std
::
size
(
vertices
),
0u
));
//GFX_THROW_INFO_ONLY(pContext->Draw((UINT)std::size(vertices), 0u));
GFX_THROW_INFO_ONLY
(
pContext
->
DrawIndexed
((
UINT
)
std
::
size
(
indices
),
0u
,
0u
));
}
// Graphics exception stuff
...
...
StudyDx/PixelShader.hlsl
View file @
17c163c3
float4
main
()
:
SV_Target
float4
main
(
float3
color
:
Color
)
:
SV_Target
{
return
float4
(
1
.
0
f
,
1
.
0
f
,
1
.
0
f
,
1
.
0
f
);
return
float4
(
color
,
1
.
0
f
);
}
\ No newline at end of file
StudyDx/VertexShader.hlsl
View file @
17c163c3
float4
main
(
float2
pos
:
Position
)
:
SV_Position
struct
VSOut
{
return
float4
(
pos
.
x
,
pos
.
y
,
0
.
0
f
,
1
.
0
f
);
float3
color
:
Color
;
float4
pos
:
SV_Position
;
};
VSOut
main
(
float2
pos
:
Position
,
float3
color
:
Color
)
{
VSOut
vso
;
vso
.
pos
=
float4
(
pos
.
x
,
pos
.
y
,
0
.
0
f
,
1
.
0
f
);
vso
.
color
=
color
;
return
vso
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment