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
a820f8b0
Commit
a820f8b0
authored
Feb 16, 2019
by
chili
Browse files
solid cube boi
parent
a555aa8d
Changes
4
Hide whitespace changes
Inline
Side-by-side
hw3d/Graphics.cpp
View file @
a820f8b0
...
...
@@ -111,27 +111,22 @@ void Graphics::DrawTestTriangle( float angle,float x,float y )
{
float
x
;
float
y
;
float
z
;
}
pos
;
struct
{
unsigned
char
r
;
unsigned
char
g
;
unsigned
char
b
;
unsigned
char
a
;
}
color
;
};
// create vertex buffer (1 2d triangle at center of screen)
Vertex
vertices
[]
=
{
{
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
,
-
1.0
f
,
255
,
0
,
0
,
0
},
{
-
1.0
f
,
-
1.0
f
,
-
1.0
f
},
{
1.0
f
,
-
1.0
f
,
-
1.0
f
},
{
-
1.0
f
,
1.0
f
,
-
1.0
f
},
{
1.0
f
,
1.0
f
,
-
1.0
f
},
{
-
1.0
f
,
-
1.0
f
,
1.0
f
},
{
1.0
f
,
-
1.0
f
,
1.0
f
},
{
-
1.0
f
,
1.0
f
,
1.0
f
},
{
1.0
f
,
1.0
f
,
1.0
f
},
};
vertices
[
0
].
color
.
g
=
255
;
wrl
::
ComPtr
<
ID3D11Buffer
>
pVertexBuffer
;
D3D11_BUFFER_DESC
bd
=
{};
bd
.
BindFlags
=
D3D11_BIND_VERTEX_BUFFER
;
...
...
@@ -153,10 +148,12 @@ void Graphics::DrawTestTriangle( float angle,float x,float y )
// create index buffer
const
unsigned
short
indices
[]
=
{
0
,
1
,
2
,
0
,
2
,
3
,
0
,
4
,
1
,
2
,
1
,
5
,
0
,
2
,
1
,
2
,
3
,
1
,
1
,
3
,
5
,
3
,
7
,
5
,
2
,
6
,
3
,
3
,
6
,
7
,
4
,
5
,
7
,
4
,
7
,
6
,
0
,
4
,
2
,
2
,
4
,
6
,
0
,
1
,
4
,
1
,
5
,
4
};
wrl
::
ComPtr
<
ID3D11Buffer
>
pIndexBuffer
;
D3D11_BUFFER_DESC
ibd
=
{};
...
...
@@ -184,8 +181,9 @@ void Graphics::DrawTestTriangle( float angle,float x,float y )
{
dx
::
XMMatrixTranspose
(
dx
::
XMMatrixRotationZ
(
angle
)
*
dx
::
XMMatrixScaling
(
3.0
f
/
4.0
f
,
1.0
f
,
1.0
f
)
*
dx
::
XMMatrixTranslation
(
x
,
y
,
0.0
f
)
dx
::
XMMatrixRotationX
(
angle
)
*
dx
::
XMMatrixTranslation
(
x
,
y
,
4.0
f
)
*
dx
::
XMMatrixPerspectiveLH
(
1.0
f
,
3.0
f
/
4.0
f
,
0.5
f
,
10.0
f
)
)
}
};
...
...
@@ -205,6 +203,45 @@ void Graphics::DrawTestTriangle( float angle,float x,float y )
pContext
->
VSSetConstantBuffers
(
0u
,
1u
,
pConstantBuffer
.
GetAddressOf
()
);
// lookup table for cube face colors
struct
ConstantBuffer2
{
struct
{
float
r
;
float
g
;
float
b
;
float
a
;
}
face_colors
[
6
];
};
const
ConstantBuffer2
cb2
=
{
{
{
1.0
f
,
0.0
f
,
1.0
f
},
{
1.0
f
,
0.0
f
,
0.0
f
},
{
0.0
f
,
1.0
f
,
0.0
f
},
{
0.0
f
,
0.0
f
,
1.0
f
},
{
1.0
f
,
1.0
f
,
0.0
f
},
{
0.0
f
,
1.0
f
,
1.0
f
},
}
};
wrl
::
ComPtr
<
ID3D11Buffer
>
pConstantBuffer2
;
D3D11_BUFFER_DESC
cbd2
;
cbd2
.
BindFlags
=
D3D11_BIND_CONSTANT_BUFFER
;
cbd2
.
Usage
=
D3D11_USAGE_DEFAULT
;
cbd2
.
CPUAccessFlags
=
0u
;
cbd2
.
MiscFlags
=
0u
;
cbd2
.
ByteWidth
=
sizeof
(
cb2
);
cbd2
.
StructureByteStride
=
0u
;
D3D11_SUBRESOURCE_DATA
csd2
=
{};
csd2
.
pSysMem
=
&
cb2
;
GFX_THROW_INFO
(
pDevice
->
CreateBuffer
(
&
cbd2
,
&
csd2
,
&
pConstantBuffer2
)
);
// bind constant buffer to pixel shader
pContext
->
PSSetConstantBuffers
(
0u
,
1u
,
pConstantBuffer2
.
GetAddressOf
()
);
// create pixel shader
wrl
::
ComPtr
<
ID3D11PixelShader
>
pPixelShader
;
wrl
::
ComPtr
<
ID3DBlob
>
pBlob
;
...
...
@@ -228,8 +265,7 @@ void Graphics::DrawTestTriangle( float angle,float x,float y )
wrl
::
ComPtr
<
ID3D11InputLayout
>
pInputLayout
;
const
D3D11_INPUT_ELEMENT_DESC
ied
[]
=
{
{
"Position"
,
0
,
DXGI_FORMAT_R32G32_FLOAT
,
0
,
0
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
{
"Color"
,
0
,
DXGI_FORMAT_R8G8B8A8_UNORM
,
0
,
8u
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
{
"Position"
,
0
,
DXGI_FORMAT_R32G32B32_FLOAT
,
0
,
0
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
};
GFX_THROW_INFO
(
pDevice
->
CreateInputLayout
(
ied
,(
UINT
)
std
::
size
(
ied
),
...
...
hw3d/PixelShader.hlsl
View file @
a820f8b0
float4
main
(
float3
color
:
Color
)
:
SV_Target
cbuffer
CBuf
{
return
float4
(
color
,
1
.
0
f
);
float4
face_colors
[
6
];
};
float4
main
(
uint
tid
:
SV_PrimitiveID
)
:
SV_Target
{
return
face_colors
[
tid
/
2
];
}
\ No newline at end of file
hw3d/VertexShader.hlsl
View file @
a820f8b0
struct
VSOut
{
float3
color
:
Color
;
float4
pos
:
SV_Position
;
};
cbuffer
CBuf
{
matrix
transform
;
};
VSOut
main
(
float
2
pos
:
Position
,
float3
color
:
Color
)
float4
main
(
float
3
pos
:
Position
)
:
SV_Position
{
VSOut
vso
;
vso
.
pos
=
mul
(
float4
(
pos
.
x
,
pos
.
y
,
0
.
0
f
,
1
.
0
f
),
transform
);
vso
.
color
=
color
;
return
vso
;
return
mul
(
float4
(
pos
,
1
.
0
f
),
transform
);
}
\ No newline at end of file
hw3d/hw3d.vcxproj
View file @
a820f8b0
...
...
@@ -192,6 +192,10 @@
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
4.0
</ShaderModel>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
4.0
</ShaderModel>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
4.0
</ShaderModel>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
4.0
</ShaderModel>
</FxCompile>
<FxCompile
Include=
"VertexShader.hlsl"
>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
...
...
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