debut triangle
This commit is contained in:
parent
70c19f4619
commit
6bd66dc5d4
18
enginecustom/Color.cpp
Normal file
18
enginecustom/Color.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "pch.h"
|
||||
#include "Color.h"
|
||||
#if __has_include("Color.g.cpp")
|
||||
#include "Color.g.cpp"
|
||||
#endif
|
||||
|
||||
namespace winrt::enginecustom::implementation
|
||||
{
|
||||
int32_t Color::MyProperty()
|
||||
{
|
||||
throw hresult_not_implemented();
|
||||
}
|
||||
|
||||
void Color::MyProperty(int32_t /*value*/)
|
||||
{
|
||||
throw hresult_not_implemented();
|
||||
}
|
||||
}
|
21
enginecustom/Color.h
Normal file
21
enginecustom/Color.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "Color.g.h"
|
||||
|
||||
namespace winrt::enginecustom::implementation
|
||||
{
|
||||
struct Color : ColorT<Color>
|
||||
{
|
||||
Color() = default;
|
||||
|
||||
int32_t MyProperty();
|
||||
void MyProperty(int32_t value);
|
||||
};
|
||||
}
|
||||
|
||||
namespace winrt::enginecustom::factory_implementation
|
||||
{
|
||||
struct Color : ColorT<Color, implementation::Color>
|
||||
{
|
||||
};
|
||||
}
|
10
enginecustom/Color.idl
Normal file
10
enginecustom/Color.idl
Normal file
@ -0,0 +1,10 @@
|
||||
namespace enginecustom
|
||||
{
|
||||
[bindable]
|
||||
[default_interface]
|
||||
runtimeclass Color
|
||||
{
|
||||
Color();
|
||||
Int32 MyProperty;
|
||||
}
|
||||
}
|
22
enginecustom/Color.ps.hlsl
Normal file
22
enginecustom/Color.ps.hlsl
Normal file
@ -0,0 +1,22 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Filename: color.ps
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//////////////
|
||||
// TYPEDEFS //
|
||||
//////////////
|
||||
struct PixelInputType
|
||||
{
|
||||
float4 position : SV_POSITION;
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Pixel Shader
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
float4 ColorPixelShader(PixelInputType input) : SV_TARGET
|
||||
{
|
||||
return input.color;
|
||||
}
|
50
enginecustom/Color.vs.hlsl
Normal file
50
enginecustom/Color.vs.hlsl
Normal file
@ -0,0 +1,50 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Filename: color.vs
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////
|
||||
// GLOBALS //
|
||||
/////////////
|
||||
cbuffer MatrixBuffer
|
||||
{
|
||||
matrix worldMatrix;
|
||||
matrix viewMatrix;
|
||||
matrix projectionMatrix;
|
||||
};
|
||||
|
||||
//////////////
|
||||
// TYPEDEFS //
|
||||
//////////////
|
||||
struct VertexInputType
|
||||
{
|
||||
float4 position : POSITION;
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
struct PixelInputType
|
||||
{
|
||||
float4 position : SV_POSITION;
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Vertex Shader
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
PixelInputType ColorVertexShader(VertexInputType input)
|
||||
{
|
||||
PixelInputType output;
|
||||
|
||||
|
||||
// Change the position vector to be 4 units for proper matrix calculations.
|
||||
input.position.w = 1.0f;
|
||||
|
||||
// Calculate the position of the vertex against the world, view, and projection matrices.
|
||||
output.position = mul(input.position, worldMatrix);
|
||||
output.position = mul(output.position, viewMatrix);
|
||||
output.position = mul(output.position, projectionMatrix);
|
||||
|
||||
// Store the input color for the pixel shader to use.
|
||||
output.color = input.color;
|
||||
|
||||
return output;
|
||||
}
|
203
enginecustom/Colorshaderclass.cpp
Normal file
203
enginecustom/Colorshaderclass.cpp
Normal file
@ -0,0 +1,203 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Filename: colorshaderclass.cpp
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include "colorshaderclass.h"
|
||||
|
||||
ColorShaderClass::ColorShaderClass()
|
||||
{
|
||||
m_vertexShader = 0;
|
||||
m_pixelShader = 0;
|
||||
m_layout = 0;
|
||||
m_matrixBuffer = 0;
|
||||
}
|
||||
|
||||
|
||||
ColorShaderClass::ColorShaderClass(const ColorShaderClass& other)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ColorShaderClass::~ColorShaderClass()
|
||||
{
|
||||
}
|
||||
|
||||
bool ColorShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
{
|
||||
bool result;
|
||||
wchar_t vsFilename[128];
|
||||
wchar_t psFilename[128];
|
||||
int error;
|
||||
|
||||
|
||||
// Set the filename of the vertex shader.
|
||||
error = wcscpy_s(vsFilename, 128, L"../Engine/color.vs");
|
||||
if (error != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the filename of the pixel shader.
|
||||
error = wcscpy_s(psFilename, 128, L"../Engine/color.ps");
|
||||
if (error != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Initialize the vertex and pixel shaders.
|
||||
result = InitializeShader(device, hwnd, vsFilename, psFilename);
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ColorShaderClass::Shutdown()
|
||||
{
|
||||
// Shutdown the vertex and pixel shaders as well as the related objects.
|
||||
ShutdownShader();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool ColorShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix,
|
||||
XMMATRIX projectionMatrix)
|
||||
{
|
||||
bool result;
|
||||
|
||||
|
||||
// Set the shader parameters that it will use for rendering.
|
||||
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix);
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now render the prepared buffers with the shader.
|
||||
RenderShader(deviceContext, indexCount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ColorShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
|
||||
{
|
||||
HRESULT result;
|
||||
ID3D10Blob* errorMessage;
|
||||
ID3D10Blob* vertexShaderBuffer;
|
||||
ID3D10Blob* pixelShaderBuffer;
|
||||
D3D11_INPUT_ELEMENT_DESC polygonLayout[2];
|
||||
unsigned int numElements;
|
||||
D3D11_BUFFER_DESC matrixBufferDesc;
|
||||
|
||||
|
||||
// Initialize the pointers this function will use to null.
|
||||
errorMessage = 0;
|
||||
vertexShaderBuffer = 0;
|
||||
pixelShaderBuffer = 0;
|
||||
|
||||
// Compile the vertex shader code.
|
||||
result = D3DCompileFromFile(vsFilename, NULL, NULL, "ColorVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0,
|
||||
&vertexShaderBuffer, &errorMessage);
|
||||
if (FAILED(result))
|
||||
{
|
||||
// If the shader failed to compile it should have writen something to the error message.
|
||||
if (errorMessage)
|
||||
{
|
||||
OutputShaderErrorMessage(errorMessage, hwnd, vsFilename);
|
||||
}
|
||||
// If there was nothing in the error message then it simply could not find the shader file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compile the pixel shader code.
|
||||
result = D3DCompileFromFile(psFilename, NULL, NULL, "ColorPixelShader", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0,
|
||||
&pixelShaderBuffer, &errorMessage);
|
||||
if (FAILED(result))
|
||||
{
|
||||
// If the shader failed to compile it should have writen something to the error message.
|
||||
if (errorMessage)
|
||||
{
|
||||
OutputShaderErrorMessage(errorMessage, hwnd, psFilename);
|
||||
}
|
||||
// If there was nothing in the error message then it simply could not find the file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the vertex shader from the buffer.
|
||||
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the pixel shader from the buffer.
|
||||
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the vertex input layout description.
|
||||
// This setup needs to match the VertexType stucture in the ModelClass and in the shader.
|
||||
polygonLayout[0].SemanticName = "POSITION";
|
||||
polygonLayout[0].SemanticIndex = 0;
|
||||
polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
|
||||
polygonLayout[0].InputSlot = 0;
|
||||
polygonLayout[0].AlignedByteOffset = 0;
|
||||
polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
|
||||
polygonLayout[0].InstanceDataStepRate = 0;
|
||||
|
||||
polygonLayout[1].SemanticName = "COLOR";
|
||||
polygonLayout[1].SemanticIndex = 0;
|
||||
polygonLayout[1].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
||||
polygonLayout[1].InputSlot = 0;
|
||||
polygonLayout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
|
||||
polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
|
||||
polygonLayout[1].InstanceDataStepRate = 0;
|
||||
|
||||
// Get a count of the elements in the layout.
|
||||
numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]);
|
||||
|
||||
// Create the vertex input layout.
|
||||
result = device->CreateInputLayout(polygonLayout, numElements, vertexShaderBuffer->GetBufferPointer(),
|
||||
vertexShaderBuffer->GetBufferSize(), &m_layout);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
|
||||
vertexShaderBuffer->Release();
|
||||
vertexShaderBuffer = 0;
|
||||
|
||||
pixelShaderBuffer->Release();
|
||||
pixelShaderBuffer = 0;
|
||||
|
||||
// Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
|
||||
matrixBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
matrixBufferDesc.ByteWidth = sizeof(MatrixBufferType);
|
||||
matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
||||
matrixBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
matrixBufferDesc.MiscFlags = 0;
|
||||
matrixBufferDesc.StructureByteStride = 0;
|
||||
|
||||
// Create the constant buffer pointer so we can access the vertex shader constant buffer from within this class.
|
||||
result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
56
enginecustom/Colorshaderclass.h
Normal file
56
enginecustom/Colorshaderclass.h
Normal file
@ -0,0 +1,56 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Filename: colorshaderclass.h
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef _COLORSHADERCLASS_H_
|
||||
#define _COLORSHADERCLASS_H_
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include <d3d11.h>
|
||||
#include <d3dcompiler.h>
|
||||
#include <directxmath.h>
|
||||
#include <fstream>
|
||||
using namespace DirectX;
|
||||
using namespace std;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: ColorShaderClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class ColorShaderClass
|
||||
{
|
||||
private:
|
||||
struct MatrixBufferType
|
||||
{
|
||||
XMMATRIX world;
|
||||
XMMATRIX view;
|
||||
XMMATRIX projection;
|
||||
};
|
||||
|
||||
public:
|
||||
ColorShaderClass();
|
||||
ColorShaderClass(const ColorShaderClass&);
|
||||
~ColorShaderClass();
|
||||
|
||||
bool Initialize(ID3D11Device*, HWND);
|
||||
void Shutdown();
|
||||
bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX);
|
||||
|
||||
private:
|
||||
bool InitializeShader(ID3D11Device*, HWND, WCHAR*, WCHAR*);
|
||||
void ShutdownShader();
|
||||
void OutputShaderErrorMessage(ID3D10Blob*, HWND, WCHAR*);
|
||||
|
||||
bool SetShaderParameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX);
|
||||
void RenderShader(ID3D11DeviceContext*, int);
|
||||
|
||||
private:
|
||||
ID3D11VertexShader* m_vertexShader;
|
||||
ID3D11PixelShader* m_pixelShader;
|
||||
ID3D11InputLayout* m_layout;
|
||||
ID3D11Buffer* m_matrixBuffer;
|
||||
};
|
||||
|
||||
#endif
|
@ -67,7 +67,7 @@ bool ApplicationClass::Frame()
|
||||
bool ApplicationClass::Render()
|
||||
{
|
||||
// Clear the buffers to begin the scene.
|
||||
m_Direct3D->BeginScene(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
m_Direct3D->BeginScene(255.0f, 255.0f, 0.0f, 1.0f);
|
||||
|
||||
|
||||
// Present the rendered scene to the screen.
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.220531.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220531.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
@ -20,6 +21,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="applicationclass.cpp" />
|
||||
<ClCompile Include="Colorshaderclass.cpp" />
|
||||
<ClCompile Include="d3dclass.cpp" />
|
||||
<ClCompile Include="inputclass.cpp" />
|
||||
<ClCompile Include="Main.cpp" />
|
||||
@ -27,10 +29,28 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="applicationclass.h" />
|
||||
<ClInclude Include="Colorshaderclass.h" />
|
||||
<ClInclude Include="d3dclass.h" />
|
||||
<ClInclude Include="inputclass.h" />
|
||||
<ClInclude Include="systemclass.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<FxCompile Include="Color.ps.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
|
||||
</FxCompile>
|
||||
<FxCompile Include="Color.vs.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
|
||||
</FxCompile>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
@ -141,5 +161,13 @@
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.220531.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220531.1\build\native\Microsoft.Windows.CppWinRT.targets')" />
|
||||
</ImportGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>Ce projet fait référence à des packages NuGet qui sont manquants sur cet ordinateur. Utilisez l'option de restauration des packages NuGet pour les télécharger. Pour plus d'informations, consultez http://go.microsoft.com/fwlink/?LinkID=322105. Le fichier manquant est : {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220531.1\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.220531.1\build\native\Microsoft.Windows.CppWinRT.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220531.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.220531.1\build\native\Microsoft.Windows.CppWinRT.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
@ -13,6 +13,9 @@
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="shader">
|
||||
<UniqueIdentifier>{b016e481-576e-4d99-bdde-34cc10c55b1d}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Main.cpp">
|
||||
@ -30,6 +33,9 @@
|
||||
<ClCompile Include="d3dclass.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Colorshaderclass.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="systemclass.h">
|
||||
@ -44,5 +50,19 @@
|
||||
<ClInclude Include="d3dclass.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Colorshaderclass.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<FxCompile Include="Color.ps.hlsl">
|
||||
<Filter>shader</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="Color.vs.hlsl">
|
||||
<Filter>shader</Filter>
|
||||
</FxCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
4
enginecustom/packages.config
Normal file
4
enginecustom/packages.config
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Windows.CppWinRT" version="2.0.220531.1" targetFramework="native" />
|
||||
</packages>
|
Loading…
x
Reference in New Issue
Block a user