diff --git a/GDP/D3D11/D3D11.vcxproj b/GDP/D3D11/D3D11.vcxproj
index 9b1df36..0ddb611 100644
--- a/GDP/D3D11/D3D11.vcxproj
+++ b/GDP/D3D11/D3D11.vcxproj
@@ -199,6 +199,26 @@
+
+
+ Pixel
+ Pixel
+ Pixel
+ Pixel
+ Pixel
+ Pixel
+ %(Filename).cso
+
+
+ Vertex
+ Vertex
+ Vertex
+ Vertex
+ Vertex
+ Vertex
+ %(Filename).cso
+
+
diff --git a/GDP/D3D11/D3D11.vcxproj.filters b/GDP/D3D11/D3D11.vcxproj.filters
index d3ddd1e..446ecb5 100644
--- a/GDP/D3D11/D3D11.vcxproj.filters
+++ b/GDP/D3D11/D3D11.vcxproj.filters
@@ -78,4 +78,12 @@
Header Files
+
+
+ Resource Files
+
+
+ Resource Files
+
+
\ No newline at end of file
diff --git a/GDP/D3D11/Direct3D.cpp b/GDP/D3D11/Direct3D.cpp
index 1bc4d0c..d16c435 100644
--- a/GDP/D3D11/Direct3D.cpp
+++ b/GDP/D3D11/Direct3D.cpp
@@ -5,62 +5,98 @@ INT Direct3D::init(HWND hWnd, UINT width, UINT height, BOOL isFullscreen)
{
HRESULT hr = {};
- // 1. create connection to Direct3D API
- IDirect3D9* pD3D = Direct3DCreate9(D3D_SDK_VERSION);
- if (pD3D == nullptr) return 200;
+ // 1. define presentation parameters
+ DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
+ swapChainDesc.OutputWindow = hWnd; // target window
+ swapChainDesc.Windowed = !isFullscreen; // window mode yes or no
+ swapChainDesc.BufferCount = 1;
+ swapChainDesc.BufferDesc.Width = width;
+ swapChainDesc.BufferDesc.Height = height;
+ swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+ swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // how to use/access the back buffer
+ swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
+ swapChainDesc.SampleDesc.Count = 1; // at least set to one
- // 2. check compatibility
- D3DCAPS9 caps = {};
- UINT adapter = D3DADAPTER_DEFAULT; // graphic card index, 0 -> primary
- D3DDEVTYPE devType = D3DDEVTYPE_HAL; // hardware or software renderer, here hardware
- hr = pD3D->GetDeviceCaps(adapter, devType, &caps);
- CheckFailed(hr, 210);
+ // 2. create Direct3D device, device context & swap chain
+ D3D_FEATURE_LEVEL supportedFeatureLevels[] =
+ {
+ D3D_FEATURE_LEVEL_11_1,
+ D3D_FEATURE_LEVEL_11_0,
+ };
+ D3D_FEATURE_LEVEL chosenFeatureLevel = {};
- DWORD vertexProcessing = D3DCREATE_SOFTWARE_VERTEXPROCESSING; // fallback if hardware processing is not available
- if (caps.VertexProcessingCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
- vertexProcessing = D3DCREATE_HARDWARE_VERTEXPROCESSING; // hardware processing is available
+ hr = D3D11CreateDeviceAndSwapChain(
+ nullptr, // graphic card adapter
+ D3D_DRIVER_TYPE_HARDWARE, // hardware or software rendering
+ nullptr, // software rendering module
+ 0, // optional flags
+ supportedFeatureLevels, std::size(supportedFeatureLevels), // supported D3D api versions
+ D3D11_SDK_VERSION,
+ &swapChainDesc, &_pDXGISwapChain, &_pD3DDevice, &chosenFeatureLevel, &_pD3DDeviceContext
+ );
+ CheckFailed(hr, 200);
- // 3. define presentation parameters
- D3DPRESENT_PARAMETERS pp = {};
- pp.hDeviceWindow = hWnd; // target window
- pp.Windowed = !isFullscreen; // window mode yes or no
- pp.BackBufferCount = 1;
- pp.BackBufferWidth = width;
- pp.BackBufferHeight = height;
- pp.BackBufferFormat = D3DFMT_A8R8G8B8; // 4 channels, each channel 8bit
- pp.SwapEffect = D3DSWAPEFFECT_DISCARD; // what happens with the front buffer after a swap
-
- // 4. create Direct3D device
- hr = pD3D->CreateDevice(adapter, devType, hWnd, vertexProcessing, &pp, &_pD3DDevice);
+ // 3. create render target view
+ ID3D11Texture2D* pBackBuffer = nullptr;
+ hr = _pDXGISwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
CheckFailed(hr, 220);
- // 5. tidy up
- safeRelease(pD3D);
+ hr = _pD3DDevice->CreateRenderTargetView(pBackBuffer, nullptr, &_pRenderTargetView);
+ CheckFailed(hr, 225);
+
+ safeRelease(pBackBuffer);
+
+ // 4. create rasterizer state
+
+ //d3d.getDevice()->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
+
+ //d3d.getDevice()->SetRenderState(D3DRS_LIGHTING, TRUE);
+ //d3d.getDevice()->SetRenderState(D3DRS_SPECULARENABLE, TRUE);
+ //d3d.getDevice()->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
+ //d3d.getDevice()->SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);
+ //d3d.getDevice()->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
+ //d3d.getDevice()->SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL);
+
+
+ // 5. create depth stencil view & state
+
+ // 6. define view port
+ D3D11_VIEWPORT viewPort = {};
+ viewPort.Width = width;
+ viewPort.Height = height;
+ viewPort.MinDepth = 0.0f;
+ viewPort.MaxDepth = 1.0f;
+
+ // 7. setup render pipeline
+ _pD3DDeviceContext->RSSetViewports(1, &viewPort);
+ _pD3DDeviceContext->OMSetRenderTargets(1, &_pRenderTargetView, nullptr);
return 0;
}
void Direct3D::beginScene()
{
- _pD3DDevice->BeginScene();
-
// clear buffers
- _pD3DDevice->Clear(
- 0, nullptr, // clear regions, here clear everything
- D3DCLEAR_TARGET, // which buffers to clear
- D3DCOLOR_XRGB(100, 100, 100), 1.0f, 0xffffffff // clear values
- );
+ FLOAT backgroundColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
+ _pD3DDeviceContext->ClearRenderTargetView(_pRenderTargetView, backgroundColor);
}
void Direct3D::endScene()
{
- _pD3DDevice->EndScene();
-
// present frame
- _pD3DDevice->Present(nullptr, nullptr, nullptr, nullptr);
+ _pDXGISwapChain->Present(
+ 0, // 0 -> vsync deactivated, 1,2,3,4 -> vsync activated with x frames
+ 0 // optional flags
+ );
}
void Direct3D::deInit()
{
+ safeRelease(_pDepthStencilState);
+ safeRelease(_pDepthStencilView);
+ safeRelease(_pRasterizerState);
+ safeRelease(_pRenderTargetView);
+ safeRelease(_pDXGISwapChain);
+ safeRelease(_pD3DDeviceContext);
safeRelease(_pD3DDevice);
}
diff --git a/GDP/D3D11/Direct3D.h b/GDP/D3D11/Direct3D.h
index f8c0a26..7d33f0d 100644
--- a/GDP/D3D11/Direct3D.h
+++ b/GDP/D3D11/Direct3D.h
@@ -1,7 +1,7 @@
#pragma once
-#include
+#include
-#pragma comment(lib, "d3d9.lib")
+#pragma comment(lib, "d3d11.lib")
class Direct3D
{
@@ -11,9 +11,16 @@ public:
void endScene();
void deInit();
- IDirect3DDevice9* getDevice() const { return _pD3DDevice; }
+ ID3D11Device* getDevice() const { return _pD3DDevice; }
+ ID3D11DeviceContext* getDeviceContext() const { return _pD3DDeviceContext; }
private:
- IDirect3DDevice9* _pD3DDevice = nullptr; // our interface for api communication
+ ID3D11Device* _pD3DDevice = nullptr; // create other api objects, e.g. buffer
+ ID3D11DeviceContext* _pD3DDeviceContext = nullptr; // customize render pipeline, e.g. set buffer or make draw calls
+ IDXGISwapChain* _pDXGISwapChain = nullptr; // holds references to front and back buffer and swap them
+ ID3D11RenderTargetView* _pRenderTargetView = nullptr; // back buffer
+ ID3D11RasterizerState* _pRasterizerState = nullptr; // customize rasterizer stage
+ ID3D11DepthStencilView* _pDepthStencilView = nullptr; // depth & stencil buffer
+ ID3D11DepthStencilState* _pDepthStencilState = nullptr; // customize depth stencil buffering
};
diff --git a/GDP/D3D11/Material.cpp b/GDP/D3D11/Material.cpp
index d357fec..e504ae4 100644
--- a/GDP/D3D11/Material.cpp
+++ b/GDP/D3D11/Material.cpp
@@ -1,9 +1,9 @@
#include "Material.h"
#include "Utilities.h"
-#include "WICTextureLoader9.h"
+//#include "WICTextureLoader9.h"
-UINT Material::init(IDirect3DDevice9* pD3DDevice, LPCTSTR textureFileName)
+UINT Material::init(ID3D11Device* pD3DDevice, LPCTSTR textureFileName)
{
HRESULT hr = DirectX::CreateWICTextureFromFile(pD3DDevice, textureFileName, &_pTexture, 0, DirectX::WIC_LOADER_MIP_AUTOGEN);
CheckFailed(hr, 600);
@@ -11,7 +11,7 @@ UINT Material::init(IDirect3DDevice9* pD3DDevice, LPCTSTR textureFileName)
return 0;
}
-void Material::render(IDirect3DDevice9* pD3DDevice)
+void Material::render(ID3D11DeviceContext* pD3DDeviceContext)
{
// set texture
pD3DDevice->SetTexture(0, _pTexture);
@@ -39,3 +39,60 @@ void Material::render(IDirect3DDevice9* pD3DDevice)
void Material::deInit()
{
}
+
+UINT Material::createVertexShader(ID3D11Device* pD3DDevice)
+{
+ HRESULT hr = {};
+ ID3DBlob* pCompiledShaderCode = nullptr;
+
+ // two options to get compiled shader code
+ // option 1: compile at runtime
+ //hr = D3DCompileFromFile(
+ // L"VertexShader.hlsl", // shader filename
+ // nullptr, nullptr, // shared shader code
+ // "main", // shader entry function
+ // "vs_4_0", // shader type & model (version)
+ // 0, 0, // optional flags
+ // &pCompiledShaderCode,
+ // nullptr // optional blob for compiler error messages
+ //);
+
+ // option 2: load compiled code from file
+ hr = D3DReadFileToBlob(L"VertexShader.cso", &pCompiledShaderCode);
+
+ CheckFailed(hr, 600);
+
+ hr = pD3DDevice->CreateVertexShader(
+ pCompiledShaderCode->GetBufferPointer(), pCompiledShaderCode->GetBufferSize(), // compiled shader code
+ nullptr, // shared code code
+ &_pVertexShader
+ );
+ CheckFailed(hr, 605);
+
+ safeRelease(pCompiledShaderCode);
+
+ return 0;
+}
+
+UINT Material::createPixelShader(ID3D11Device* pD3DDevice)
+{
+ HRESULT hr = {};
+ ID3DBlob* pCompiledShaderCode = nullptr;
+
+ hr = D3DReadFileToBlob(L"PixelShader.cso", &pCompiledShaderCode);
+ CheckFailed(hr, 620);
+
+ hr = pD3DDevice->CreatePixelShader(
+ pCompiledShaderCode->GetBufferPointer(), pCompiledShaderCode->GetBufferSize(), // compiled shader code
+ nullptr, // shared code code
+ &_pPixelShader
+ );
+ CheckFailed(hr, 625);
+
+ return 0;
+}
+
+UINT Material::createInputLayout(ID3D11Device* pD3DDevice, ID3DBlob* pCompiledVertexShader)
+{
+ return 0;
+}
diff --git a/GDP/D3D11/Material.h b/GDP/D3D11/Material.h
index d86b24c..1186fce 100644
--- a/GDP/D3D11/Material.h
+++ b/GDP/D3D11/Material.h
@@ -1,14 +1,25 @@
#pragma once
-#include
+#include
+#include
+
+#pragma comment(lib, "d3dcompiler.lib")
class Material
{
public:
- UINT init(IDirect3DDevice9* pD3DDevice, LPCTSTR textureFileName);
- void render(IDirect3DDevice9* pD3DDevice);
+ UINT init(ID3D11Device* pD3DDevice, LPCTSTR textureFileName);
+ void render(ID3D11DeviceContext* pD3DDeviceContext);
void deInit();
private:
- IDirect3DTexture9* _pTexture = {};
+ UINT createVertexShader(ID3D11Device* pD3DDevice);
+ UINT createPixelShader(ID3D11Device* pD3DDevice);
+ UINT createInputLayout(ID3D11Device* pD3DDevice, ID3DBlob* pCompiledVertexShader);
+
+ ID3D11VertexShader* _pVertexShader = nullptr;
+ ID3D11PixelShader* _pPixelShader = nullptr;
+ ID3D11InputLayout* _pInputLayout = nullptr;
+
+ //IDirect3DTexture9* _pTexture = nullptr;
};
diff --git a/GDP/D3D11/Mesh.cpp b/GDP/D3D11/Mesh.cpp
index 120629c..5c8b61b 100644
--- a/GDP/D3D11/Mesh.cpp
+++ b/GDP/D3D11/Mesh.cpp
@@ -2,11 +2,7 @@
#include "Utilities.h"
#include "Vertex.h"
-#include
-
-using namespace DirectX;
-
-UINT Mesh::init(IDirect3DDevice9* pD3DDevice)
+UINT Mesh::init(ID3D11Device* pD3DDevice)
{
UINT error = 0;
@@ -16,10 +12,7 @@ UINT Mesh::init(IDirect3DDevice9* pD3DDevice)
error = createIndexBuffer(pD3DDevice);
CheckError(error);
- XMMATRIX identity = XMMatrixIdentity();
- XMFLOAT4X4 w;
- XMStoreFloat4x4(&w, identity);
- _worldMatrix = *reinterpret_cast(&w);
+ XMStoreFloat4x4(&_worldMatrix, XMMatrixIdentity());
return 0;
}
@@ -48,25 +41,25 @@ void Mesh::update(FLOAT dt)
XMMATRIX rotation = XMMatrixRotationRollPitchYaw(0.0f, rotY, rotZ);
XMMATRIX scale = XMMatrixScaling(1.0f, 1.0f, 1.0f);
- XMStoreFloat4x4(reinterpret_cast(&_worldMatrix), scale * rotation * translation);
+ XMStoreFloat4x4(&_worldMatrix, scale * rotation * translation);
}
-void Mesh::render(IDirect3DDevice9* pD3DDevice)
+void Mesh::render(ID3D11DeviceContext* pD3DDeviceContext)
{
// setup pipeline
- pD3DDevice->SetStreamSource(0, _pVertexBuffer, 0, _vertexStride);
- pD3DDevice->SetIndices(_pIndexBuffer);
- pD3DDevice->SetFVF(FVF);
- pD3DDevice->SetTransform(D3DTS_WORLD, &_worldMatrix);
+ UINT offset = 0;
+ pD3DDeviceContext->IASetVertexBuffers(
+ 0, // which vertex buffer should be set (Startslot)
+ 1, &_pVertexBuffer, // buffers to set
+ &_vertexStride, // vertex size for each buffer
+ &offset // offset for each buffer
+ );
+
+ pD3DDeviceContext->IASetIndexBuffer(_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
+ pD3DDeviceContext->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
// draw call
- pD3DDevice->DrawIndexedPrimitive(
- D3DPT_TRIANGLELIST, // primitive type
- 0, 0, // vertex buffer offsets
- _vertexCount,
- 0, // index buffer offset
- _indexCount / 3 // primitive count
- );
+ pD3DDeviceContext->DrawIndexed(_indexCount, 0, 0);
}
void Mesh::deInit()
@@ -75,88 +68,54 @@ void Mesh::deInit()
safeRelease(_pVertexBuffer);
}
-UINT Mesh::createVertexBuffer(IDirect3DDevice9* pD3DDevice)
+UINT Mesh::createVertexBuffer(ID3D11Device* pD3DDevice)
{
// define values
- _vertexCount = 4;
+ Vertex vertices[] =
+ {
+ Vertex(-0.5f, 0.5f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f),
+ Vertex(0.5f, 0.5f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f),
+ Vertex(0.5f, -0.5f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f),
+ Vertex(-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f),
+ };
+
+ _vertexCount = std::size(vertices);
_vertexStride = sizeof(Vertex);
// describe & create vertex buffer
- HRESULT hr = pD3DDevice->CreateVertexBuffer(
- _vertexCount * _vertexStride, // total size of content
- D3DUSAGE_WRITEONLY, // read and/or write access
- FVF, // FVF - Flexible Vertex Format -> vertex structure
- D3DPOOL_MANAGED, // memmory management
- &_pVertexBuffer,
- nullptr // deprecated, always nullptr
- );
+ D3D11_BUFFER_DESC desc = {};
+ desc.ByteWidth = _vertexCount * _vertexStride; // total size of content
+ desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; // buffer type
+ desc.Usage = D3D11_USAGE_IMMUTABLE; // https://learn.microsoft.com/en-us/windows/win32/api/d3d11/ne-d3d11-d3d11_usage
+
+ D3D11_SUBRESOURCE_DATA data = {};
+ data.pSysMem = vertices;
+
+ HRESULT hr = pD3DDevice->CreateBuffer(&desc, &data, &_pVertexBuffer);
CheckFailed(hr, 300);
- // populate vertex buffer
- Vertex* pVertices = nullptr;
- hr = _pVertexBuffer->Lock(
- 0, 0, // offset & size to lock, here everything
- reinterpret_cast(&pVertices),
- 0 // optional flags
- );
- CheckFailed(hr, 310);
+ return 0;
+}
- // triangle
- //pVertices[0] = Vertex(0.0f, 1.0f, 0.0f);
- //pVertices[1] = Vertex(1.0f, -1.0f, 0.0f);
- //pVertices[2] = Vertex(-1.0f, -1.0f, 0.0f);
+UINT Mesh::createIndexBuffer(ID3D11Device* pD3DDevice)
+{
+ unsigned short indices[] =
+ {
+ 0, 1, 2,
+ 0, 2, 3
+ };
+ _indexCount = std::size(indices);
- // quad
- //pVertices[0] = Vertex(-0.5f, 0.5f, 0.0f);
- //pVertices[1] = Vertex(0.5f, 0.5f, 0.0f);
- //pVertices[2] = Vertex(0.5f, -0.5f, 0.0f);
- //pVertices[3] = Vertex(-0.5f, -0.5f, 0.0f);
+ D3D11_BUFFER_DESC desc = {};
+ desc.ByteWidth = _indexCount * sizeof(unsigned short); // total size of content
+ desc.BindFlags = D3D11_BIND_INDEX_BUFFER; // buffer type
+ desc.Usage = D3D11_USAGE_IMMUTABLE; // https://learn.microsoft.com/en-us/windows/win32/api/d3d11/ne-d3d11-d3d11_usage
- // quad with color
- //pVertices[0] = Vertex(-0.5f, 0.5f, 0.0f, 255, 0, 0);
- //pVertices[1] = Vertex(0.5f, 0.5f, 0.0f, 0, 255, 0);
- //pVertices[2] = Vertex(0.5f, -0.5f, 0.0f, 255, 0, 255);
- //pVertices[3] = Vertex(-0.5f, -0.5f, 0.0f, 0, 0, 255);
+ D3D11_SUBRESOURCE_DATA data = {};
+ data.pSysMem = indices;
- // quad with uvs & normals
- pVertices[0] = Vertex(-0.5f, 0.5f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f);
- pVertices[1] = Vertex(0.5f, 0.5f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f);
- pVertices[2] = Vertex(0.5f, -0.5f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f);
- pVertices[3] = Vertex(-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f);
-
- hr = _pVertexBuffer->Unlock();
+ HRESULT hr = pD3DDevice->CreateBuffer(&desc, &data, &_pIndexBuffer);
CheckFailed(hr, 320);
- pVertices = nullptr;
-
- return 0;
-}
-
-UINT Mesh::createIndexBuffer(IDirect3DDevice9* pD3DDevice)
-{
- _indexCount = 6;
-
- HRESULT hr = pD3DDevice->CreateIndexBuffer(_indexCount * sizeof(unsigned short),
- D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &_pIndexBuffer, nullptr);
- CheckFailed(hr, 330);
-
- unsigned short* pIndices = nullptr;
- hr = _pIndexBuffer->Lock(0, 0, reinterpret_cast(&pIndices), 0);
- CheckFailed(hr, 340);
-
- // triangle
- //pIndices[0] = 0;
- //pIndices[1] = 1;
- //pIndices[2] = 2;
-
- // quad
- pIndices[0] = 0; pIndices[1] = 1; pIndices[2] = 2;
- pIndices[3] = 0; pIndices[4] = 2; pIndices[5] = 3;
-
- hr = _pIndexBuffer->Unlock();
- CheckFailed(hr, 350);
-
- pIndices = nullptr;
-
return 0;
}
diff --git a/GDP/D3D11/Mesh.h b/GDP/D3D11/Mesh.h
index 29b5afb..7601877 100644
--- a/GDP/D3D11/Mesh.h
+++ b/GDP/D3D11/Mesh.h
@@ -1,25 +1,28 @@
#pragma once
-#include
+#include
+#include
+
+using namespace DirectX;
class Mesh
{
public:
- UINT init(IDirect3DDevice9* pD3DDevice);
+ UINT init(ID3D11Device* pD3DDevice);
void update(FLOAT dt);
- void render(IDirect3DDevice9* pD3DDevice);
+ void render(ID3D11DeviceContext* pD3DDeviceContext);
void deInit();
private:
- UINT createVertexBuffer(IDirect3DDevice9* pD3DDevice);
- UINT createIndexBuffer(IDirect3DDevice9* pD3DDevice);
+ UINT createVertexBuffer(ID3D11Device* pD3DDevice);
+ UINT createIndexBuffer(ID3D11Device* pD3DDevice);
- IDirect3DVertexBuffer9* _pVertexBuffer = nullptr; // dumps mesh vertices
- IDirect3DIndexBuffer9* _pIndexBuffer = nullptr; // dumps mesh indices
+ ID3D11Buffer* _pVertexBuffer = nullptr; // dumps mesh vertices
+ ID3D11Buffer* _pIndexBuffer = nullptr; // dumps mesh indices
UINT _vertexCount = 0; // amount of vertices
UINT _vertexStride = 0; // size of one vertex in bytes
UINT _indexCount = 0; // amount of indices
- D3DMATRIX _worldMatrix = {};
+ XMFLOAT4X4 _worldMatrix = {};
};
diff --git a/GDP/D3D11/PixelShader.hlsl b/GDP/D3D11/PixelShader.hlsl
new file mode 100644
index 0000000..68075ef
--- /dev/null
+++ b/GDP/D3D11/PixelShader.hlsl
@@ -0,0 +1,4 @@
+float4 main() : SV_TARGET
+{
+ return float4(1.0f, 1.0f, 1.0f, 1.0f);
+}
\ No newline at end of file
diff --git a/GDP/D3D11/VertexShader.hlsl b/GDP/D3D11/VertexShader.hlsl
new file mode 100644
index 0000000..94efe03
--- /dev/null
+++ b/GDP/D3D11/VertexShader.hlsl
@@ -0,0 +1,4 @@
+float4 main( float4 pos : POSITION ) : SV_POSITION
+{
+ return pos;
+}
\ No newline at end of file
diff --git a/GDP/D3D11/Window.cpp b/GDP/D3D11/Window.cpp
index 4000e2d..2b07c7b 100644
--- a/GDP/D3D11/Window.cpp
+++ b/GDP/D3D11/Window.cpp
@@ -5,7 +5,7 @@ INT Window::init(HINSTANCE hInstance, UINT width, UINT height)
// 1. describe window class
WNDCLASS wc = {};
wc.hInstance = hInstance;
- wc.lpszClassName = TEXT("D3D9"); // class name
+ wc.lpszClassName = TEXT("D3D11"); // class name
wc.lpfnWndProc = WindowProc; // callback function for windows to communicate with our application
wc.hbrBackground = CreateSolidBrush(RGB(0, 255, 0));
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
diff --git a/GDP/D3D11/main.cpp b/GDP/D3D11/main.cpp
index e9cb7ea..8674c7b 100644
--- a/GDP/D3D11/main.cpp
+++ b/GDP/D3D11/main.cpp
@@ -32,24 +32,15 @@ int WINAPI WinMain(
error = d3d.init(window.getWindowHandle(), width, height, isFullscreen);
CheckError(error);
- d3d.getDevice()->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
-
- d3d.getDevice()->SetRenderState(D3DRS_LIGHTING, TRUE);
- d3d.getDevice()->SetRenderState(D3DRS_SPECULARENABLE, TRUE);
- d3d.getDevice()->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
- d3d.getDevice()->SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);
- d3d.getDevice()->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
- d3d.getDevice()->SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL);
-
// 3. create a mesh
Mesh mesh = {};
error = mesh.init(d3d.getDevice());
CheckError(error);
- // 4. create a camera
- Camera camera = {};
- error = camera.init(d3d.getDevice(), width, height);
- CheckError(error);
+ //// 4. create a camera
+ //Camera camera = {};
+ //error = camera.init(d3d.getDevice(), width, height);
+ //CheckError(error);
// 5. create time
Time time = {};
@@ -61,22 +52,22 @@ int WINAPI WinMain(
error = material.init(d3d.getDevice(), TEXT("wall.jpg"));
CheckError(error);
- // 7. create light source
- Light light = {};
+ //// 7. create light source
+ //Light light = {};
- D3DLIGHT9 lightData = {};
- lightData.Type = D3DLIGHT_POINT;
- lightData.Direction = { -1.0f, -1.0f, 1.0f };
- lightData.Position = { 1.0f, 1.0f, -1.0f };
- lightData.Diffuse = { 0.7f, 0.7f, 0.7f };
- lightData.Specular = { 1.0f, 1.0f, 1.0f };
- lightData.Range = 100.0f;
- lightData.Attenuation0 = 1.0f;
- lightData.Attenuation1 = 0.2f;
- lightData.Attenuation2 = 0.1f;
+ //D3DLIGHT9 lightData = {};
+ //lightData.Type = D3DLIGHT_POINT;
+ //lightData.Direction = { -1.0f, -1.0f, 1.0f };
+ //lightData.Position = { 1.0f, 1.0f, -1.0f };
+ //lightData.Diffuse = { 0.7f, 0.7f, 0.7f };
+ //lightData.Specular = { 1.0f, 1.0f, 1.0f };
+ //lightData.Range = 100.0f;
+ //lightData.Attenuation0 = 1.0f;
+ //lightData.Attenuation1 = 0.2f;
+ //lightData.Attenuation2 = 0.1f;
- error = light.init(lightData);
- CheckError(error);
+ //error = light.init(lightData);
+ //CheckError(error);
// 8. run application
while (window.run())
@@ -84,24 +75,24 @@ int WINAPI WinMain(
// 8.1. update objects
time.update();
mesh.update(time.getDeltaTime());
- camera.update(time.getDeltaTime());
- light.update(time.getDeltaTime());
+ //camera.update(time.getDeltaTime());
+ //light.update(time.getDeltaTime());
// 8.2. render objects
d3d.beginScene();
- light.render(d3d.getDevice());
+ //light.render(d3d.getDevice());
material.render(d3d.getDevice());
- mesh.render(d3d.getDevice());
+ mesh.render(d3d.getDeviceContext());
d3d.endScene();
}
// 9. tidy up
- light.deInit();
- time.deInit();
- camera.deInit();
+ //light.deInit();
material.deInit();
+ time.deInit();
+ //camera.deInit();
mesh.deInit();
d3d.deInit();
window.deInit();