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
hw3d
Commits
2dfc064e
Commit
2dfc064e
authored
Feb 03, 2019
by
chili
Browse files
indexed triangle drawing
parent
61f3e9ba
Changes
1
Show whitespace changes
Inline
Side-by-side
hw3d/Graphics.cpp
View file @
2dfc064e
...
...
@@ -124,6 +124,9 @@ void Graphics::DrawTestTriangle()
{
0.0
f
,
0.5
f
,
255
,
0
,
0
,
0
},
{
0.5
f
,
-
0.5
f
,
0
,
255
,
0
,
0
},
{
-
0.5
f
,
-
0.5
f
,
0
,
0
,
255
,
0
},
{
-
0.3
f
,
0.3
f
,
0
,
255
,
0
,
0
},
{
0.3
f
,
0.3
f
,
0
,
0
,
255
,
0
},
{
0.0
f
,
-
0.8
f
,
255
,
0
,
0
,
0
},
};
vertices
[
0
].
color
.
g
=
255
;
wrl
::
ComPtr
<
ID3D11Buffer
>
pVertexBuffer
;
...
...
@@ -144,6 +147,30 @@ void Graphics::DrawTestTriangle()
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
pContext
->
IASetIndexBuffer
(
pIndexBuffer
.
Get
(),
DXGI_FORMAT_R16_UINT
,
0u
);
// create pixel shader
wrl
::
ComPtr
<
ID3D11PixelShader
>
pPixelShader
;
wrl
::
ComPtr
<
ID3DBlob
>
pBlob
;
...
...
@@ -200,7 +227,7 @@ void Graphics::DrawTestTriangle()
pContext
->
RSSetViewports
(
1u
,
&
vp
);
GFX_THROW_INFO_ONLY
(
pContext
->
Draw
(
(
UINT
)
std
::
size
(
vert
ices
),
0u
)
);
GFX_THROW_INFO_ONLY
(
pContext
->
Draw
Indexed
(
(
UINT
)
std
::
size
(
ind
ices
),
0u
,
0u
)
);
}
...
...
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