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
PracticeDx
Commits
3417949a
Commit
3417949a
authored
Dec 22, 2022
by
Administrator
Browse files
add drawing multiple triangles with color
parent
7c1cc096
Changes
3
Show whitespace changes
Inline
Side-by-side
PracticeDx/PixelShader.hlsl
View file @
3417949a
float4
main
()
:
SV_T
ARGET
float4
main
(
float3
color
:
Color
)
:
SV_T
arget
{
{
return
float4
(
1
.
0
f
,
1
.
0
f
,
1
.
0
f
,
1
.
0
f
);
return
float4
(
color
,
1
.
0
f
);
}
}
PracticeDx/VertexShader.hlsl
View file @
3417949a
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
;
}
}
PracticeDx/WinMain.cpp
View file @
3417949a
...
@@ -10,6 +10,8 @@
...
@@ -10,6 +10,8 @@
#include <wrl.h>
#include <wrl.h>
#include <array> // to usd std::size
// global declarations
// global declarations
Microsoft
::
WRL
::
ComPtr
<
IDXGISwapChain
>
swapchain
;
// the pointer to the swap chain interface
Microsoft
::
WRL
::
ComPtr
<
IDXGISwapChain
>
swapchain
;
// the pointer to the swap chain interface
Microsoft
::
WRL
::
ComPtr
<
ID3D11Device
>
dev
;
// the pointer to our Direct3D device interface
Microsoft
::
WRL
::
ComPtr
<
ID3D11Device
>
dev
;
// the pointer to our Direct3D device interface
...
@@ -31,13 +33,35 @@ struct Vertex
...
@@ -31,13 +33,35 @@ struct Vertex
{
{
float
x
;
float
x
;
float
y
;
float
y
;
float
r
;
float
g
;
float
b
;
};
};
// create vertex buffer (1 2d triangle at center of screen)
// create vertex buffer (1 2d triangle at center of screen)
const
Vertex
vertices
[]
=
const
Vertex
vertices
[]
=
{
{
{
-
0.0
f
,
0.5
f
},
// center
{
0.5
f
,
-
0.5
f
},
{
0.0
f
,
0.5
f
,
1.0
f
,
0.0
f
,
0.0
f
},
{
-
0.5
f
,
-
0.5
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.0
f
,
0.5
f
,
1.0
f
,
0.0
f
,
0.0
f
},
{
-
0.5
f
,
-
0.5
f
,
0.0
f
,
0.0
f
,
1.0
f
},
{
-
0.3
f
,
0.3
f
,
0.0
f
,
1.0
f
,
0.0
f
},
// right top
{
0.5
f
,
-
0.5
f
,
0.0
f
,
1.0
f
,
0.0
f
},
{
0.0
f
,
0.5
f
,
1.0
f
,
0.0
f
,
0.0
f
},
{
0.3
f
,
0.3
f
,
0.0
f
,
0.0
f
,
1.0
f
},
// center bottom
{
0.5
f
,
-
0.5
f
,
0.0
f
,
1.0
f
,
0.0
f
},
{
0.0
f
,
-
0.8
f
,
1.0
f
,
0.0
f
,
0.0
f
},
{
-
0.5
f
,
-
0.5
f
,
0.0
f
,
0.0
f
,
1.0
f
},
};
};
// Define input layout
// Define input layout
...
@@ -82,12 +106,13 @@ void DefineInputLayout()
...
@@ -82,12 +106,13 @@ void DefineInputLayout()
const
D3D11_INPUT_ELEMENT_DESC
ied
[]
=
const
D3D11_INPUT_ELEMENT_DESC
ied
[]
=
{
{
{
"Position"
,
0
,
DXGI_FORMAT_R32G32_FLOAT
,
0
,
0
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
{
"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
},
};
};
// Create input layout, using the description Defined above
// Create input layout, using the description Defined above
dev
->
CreateInputLayout
dev
->
CreateInputLayout
(
(
ied
,
1
,
//
(UINT)std::size(ied),
ied
,
(
UINT
)
std
::
size
(
ied
),
pCompiledVertexBlob
->
GetBufferPointer
(),
pCompiledVertexBlob
->
GetBufferPointer
(),
pCompiledVertexBlob
->
GetBufferSize
(),
pCompiledVertexBlob
->
GetBufferSize
(),
&
pInputLayout
&
pInputLayout
...
...
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