728x90
TriangleListDemo.cpp, h
더보기
#include "stdafx.h" #include "TriangleListDemo.h" void TriangleListDemo::Initialize() { shader = new Shader(L"02_Pass.fx"); //triangle 1 { vertices[0].Position = Vector3(-0.5f, +0.0f, 0); vertices[1].Position = Vector3(+0.0f, +0.5f, 0); vertices[2].Position = Vector3(+0.5f, +0.0f, 0); D3D11_BUFFER_DESC desc; ZeroMemory(&desc, sizeof(D3D11_BUFFER_DESC)); desc.ByteWidth = sizeof(Vertex) * 3; desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; D3D11_SUBRESOURCE_DATA data = { 0 }; data.pSysMem = vertices; Check(D3D::GetDevice()->CreateBuffer(&desc, &data, &vertexBuffer)); } //triangle 2 { vertices2[0].Position = Vector3(-0.5f, -0.5f, 0); vertices2[1].Position = Vector3(+0.0f, +0.0f, 0); vertices2[2].Position = Vector3(+0.5f, -0.5f, 0); D3D11_BUFFER_DESC desc; ZeroMemory(&desc, sizeof(D3D11_BUFFER_DESC)); desc.ByteWidth = sizeof(Vertex) * 3; desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; D3D11_SUBRESOURCE_DATA data = { 0 }; data.pSysMem = vertices2; Check(D3D::GetDevice()->CreateBuffer(&desc, &data, &vertexBuffer2)); } } void TriangleListDemo::Destroy() { SafeDelete(shader); SafeRelease(vertexBuffer); SafeRelease(vertexBuffer2); } void TriangleListDemo::Update() { } void TriangleListDemo::Render() { UINT stride = sizeof(Vertex); UINT offset = 0; D3D::GetDC()->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); D3D::GetDC()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); shader->Draw(0, 0, 3); static Color Color = D3DXCOLOR(1, 1, 1, 1); static UINT Pass = 0; ImGui::InputInt("Pass", (int*)&Pass); Pass = (UINT)Math::Clamp((float)Pass, 0, 3); ImGui::ColorEdit3("Color", (float*)&Color); shader->AsVector("Color")->SetFloatVector(Color); D3D::GetDC()->IASetVertexBuffers(0, 1, &vertexBuffer2, &stride, &offset); shader->Draw(0, Pass, 3); }
#pragma once #include "Systems/IExecute.h" class TriangleListDemo : public IExecute { public: virtual void Initialize() override; virtual void Destroy() override; virtual void Update() override; virtual void PreRender() override {}; virtual void Render() override; virtual void PostRender() override {}; virtual void ResizeScreen() override {}; private: struct Vertex { Vector3 Position; }; private: Shader* shader; Vertex vertices[3]; ID3D11Buffer* vertexBuffer; Vertex vertices2[3]; ID3D11Buffer* vertexBuffer2; };
RectDemo.cpp, h
더보기
#include "stdafx.h" #include "RectDemo.h" void RectDemo::Initialize() { //Performance per; //per.Start(); shader = new Shader(L"03_Rect.fxo"); //float t = per.End(); //wstring str = to_wstring(t); //MessageBox(D3D::GetDesc().Handle, str.c_str(), L"", MB_OK); //triangle 1 { vertices[0].Position = Vector3(+0.0f, +0.0f, +0.0f); vertices[1].Position = Vector3(+0.0f, +0.5f, +0.0f); vertices[2].Position = Vector3(+0.5f, +0.0f, +0.0f); vertices[3].Position = Vector3(+0.5f, +0.0f, +0.0f); vertices[4].Position = Vector3(+0.0f, +0.5f, +0.0f); vertices[5].Position = Vector3(+0.5f, +0.5f, +0.0f); D3D11_BUFFER_DESC desc; ZeroMemory(&desc, sizeof(D3D11_BUFFER_DESC)); desc.ByteWidth = sizeof(Vertex) * 6; desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; D3D11_SUBRESOURCE_DATA data = { 0 }; data.pSysMem = vertices; Check(D3D::GetDevice()->CreateBuffer(&desc, &data, &vertexBuffer)); } } void RectDemo::Destroy() { SafeDelete(shader); SafeRelease(vertexBuffer); } void RectDemo::Update() { if (Keyboard::Get()->Press(VK_RIGHT)) vertices[0].Position.x += 2.0f * Time::Delta(); if (Keyboard::Get()->Press(VK_LEFT)) vertices[0].Position.x -= 2.0f * Time::Delta(); D3D::GetDC()->UpdateSubresource(vertexBuffer, NULL, NULL, &vertices, 0, 0); } void RectDemo::Render() { UINT stride = sizeof(Vertex); UINT offset = 0; D3D::GetDC()->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); D3D::GetDC()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); static UINT Pass = 0; ImGui::InputInt("Pass", (int*)&Pass); Pass = (UINT)Math::Clamp((float)Pass, 0, 1); shader->Draw(0, Pass, 6); }
#pragma once #include "Systems/IExecute.h" class RectDemo : public IExecute { public: virtual void Initialize() override; virtual void Destroy() override; virtual void Update() override; virtual void PreRender() override {}; virtual void Render() override; virtual void PostRender() override {}; virtual void ResizeScreen() override {}; private: struct Vertex { Vector3 Position; }; private: Shader* shader; Vertex vertices[6]; ID3D11Buffer* vertexBuffer; };
03_Rect.fx
더보기
struct VertexInput { float4 Position : Position; }; struct VertexOutput { float4 Position : SV_Position; }; //RS 셋팅 RasterizerState RS { Fillmode = WireFrame; // Wire(선) }; VertexOutput VS(VertexInput input) { VertexOutput output; output.Position = input.Position; return output; } float4 PS(VertexOutput input) : SV_Target { return float4(1, 0, 0, 1); } technique11 T0 { pass P0 { SetVertexShader(CompileShader(vs_5_0, VS())); SetPixelShader(CompileShader(ps_5_0, PS())); } pass P1 { SetRasterizerState(RS); SetVertexShader(CompileShader(vs_5_0, VS())); SetPixelShader(CompileShader(ps_5_0, PS())); } }
Main.cpp
실행 1
실행 2
추가
2D에선 좌표계를 오른손 좌표계를 사용 했지만
3D에선 왼손 좌표계를 사용함
fx파일을 fxo 파일로 바꿔주는 셋팅 구현
효과 : 실행 할떄 마다 fx파일을 다시 읽고 컴파일 한다면 fxo파일은 미리헤더 컴파일 처럼 사용하게 되서
읽어지는 속도가 상승
'DirectX > DirectX 3D_(구)' 카테고리의 다른 글
07_Camera (0) | 2021.06.30 |
---|---|
06_Grid (0) | 2021.06.30 |
05_Index (0) | 2021.06.30 |
04_World (0) | 2021.06.28 |
01_셋팅 및 02_Vertex (0) | 2021.06.28 |