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
d40ceedc
Commit
d40ceedc
authored
Dec 23, 2022
by
Administrator
Browse files
modify code to draw cube
parent
58bfba78
Changes
2
Show whitespace changes
Inline
Side-by-side
PracticeDx/VertexShader.hlsl
View file @
d40ceedc
...
...
@@ -9,10 +9,10 @@ cbuffer CBuf
matrix
transform
;
};
VSOut
main
(
float
2
pos
:
Position
,
float3
color
:
Color
)
VSOut
main
(
float
3
pos
:
Position
,
float3
color
:
Color
)
{
VSOut
vso
;
vso
.
pos
=
mul
(
float4
(
pos
.
x
,
pos
.
y
,
0
.
0
f
,
1
.
0
f
),
transform
);
vso
.
pos
=
mul
(
float4
(
pos
,
1
.
0
f
),
transform
);
vso
.
color
=
color
;
return
vso
;
...
...
PracticeDx/WinMain.cpp
View file @
d40ceedc
...
...
@@ -40,42 +40,51 @@ struct Vertex
{
float
x
;
float
y
;
float
z
;
float
r
;
float
g
;
float
b
;
};
// create vertex buffer (
1 2d triangle at center of screen
)
// create vertex buffer (
8 vertices for one cube
)
const
Vertex
vertices
[]
=
{
// 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
},
// left bottom back
{
-
1.0
f
,
-
1.0
f
,
-
1.0
f
,
1.0
f
,
0.0
f
,
0.0
f
},
// right bottom back
{
1.0
f
,
-
1.0
f
,
-
1.0
f
,
0.0
f
,
1.0
f
,
0.0
f
},
// left top back
{
-
1.0
f
,
1.0
f
,
-
1.0
f
,
0.0
f
,
0.0
f
,
1.0
f
},
// right top back
{
1.0
f
,
1.0
f
,
-
1.0
f
,
1.0
f
,
1.0
f
,
0.0
f
},
// left bottom front
{
-
1.0
f
,
-
1.0
f
,
1.0
f
,
1.0
f
,
0.0
f
,
1.0
f
},
// right bottom front
{
1.0
f
,
-
1.0
f
,
1.0
f
,
0.0
f
,
1.0
f
,
1.0
f
},
// left top front
{
-
1.0
f
,
1.0
f
,
1.0
f
,
0.0
f
,
0.0
f
,
0.0
f
},
// right top front
{
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
},
};
// Define index buffer
Microsoft
::
WRL
::
ComPtr
<
ID3D11Buffer
>
pIndexBuffer
;
//
c
reate index buffer
//
C
reate index buffer
const
unsigned
short
indices
[]
=
{
// draw center
0
,
1
,
2
,
// draw left top
0
,
2
,
3
,
// draw right top
0
,
4
,
1
,
// draw bottom
1
,
5
,
2
,
// back surface
0
,
2
,
1
,
2
,
3
,
1
,
// right surface
1
,
3
,
5
,
3
,
7
,
5
,
// top surface
2
,
6
,
3
,
3
,
6
,
7
,
// front surface
4
,
5
,
7
,
4
,
7
,
6
,
// left surface
0
,
4
,
2
,
2
,
4
,
6
,
// bottom surface
0
,
1
,
4
,
1
,
5
,
4
,
};
// Define constant buffer
...
...
@@ -94,7 +103,14 @@ ConstantBuffer cb =
dx
::
XMMatrixTranspose
(
// rotate Z axis
dx
::
XMMatrixRotationZ
(
-
angle
)
*
dx
::
XMMatrixScaling
(
heightWidthRatio
,
1.0
f
,
1.0
f
)
// rotate X axis
*
dx
::
XMMatrixRotationX
(
-
angle
)
// scaling
//* dx::XMMatrixScaling(heightWidthRatio, 1.0f, 1.0f)
// translation
*
dx
::
XMMatrixTranslation
(
0.0
f
,
0.0
f
,
4.0
f
)
// projection
*
dx
::
XMMatrixPerspectiveLH
(
1.0
f
,
heightWidthRatio
,
0.1
f
,
10.0
f
)
)
};
...
...
@@ -162,7 +178,14 @@ void DefineConstantBuffer(float angle)
dx
::
XMMatrixTranspose
(
// rotate Z axis
dx
::
XMMatrixRotationZ
(
-
angle
)
*
dx
::
XMMatrixScaling
(
heightWidthRatio
,
1.0
f
,
1.0
f
)
// rotate X axis
*
dx
::
XMMatrixRotationX
(
-
angle
)
// scaling
//* dx::XMMatrixScaling(heightWidthRatio, 1.0f, 1.0f)
// translation
*
dx
::
XMMatrixTranslation
(
0.0
f
,
0.0
f
,
4.0
f
)
// projection
*
dx
::
XMMatrixPerspectiveLH
(
1.0
f
,
heightWidthRatio
,
0.5
f
,
10.0
f
)
)
};
...
...
@@ -188,8 +211,10 @@ void DefineInputLayout()
// Create input elements description, choosing whatever need to send to GPU
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
},
//{ "Position",0,DXGI_FORMAT_R32G32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
{
"Position"
,
0
,
DXGI_FORMAT_R32G32B32_FLOAT
,
0
,
0
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
//{ "Color",0,DXGI_FORMAT_R32G32B32_FLOAT,0,8,D3D11_INPUT_PER_VERTEX_DATA,0 },
{
"Color"
,
0
,
DXGI_FORMAT_R32G32B32_FLOAT
,
0
,
12
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
};
// Create input layout, using the description Defined above
...
...
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