[DirectX11] 008 User Interface
목차
User Interface
파이프라인
Vertex -> IA -> VS -> RS -> PS -> Pixel
IA (Input Assembler) | 스테이지를 이용해 렌더링 데이터 세팅 |
VS(Vertex Shader) | W, V, P. 정점의 위치 변환. NDC 공간의 사용. |
RS(Rasterization Shader) | 정점을 픽셀로 바꿔준다. 픽셀로 채워주는 과정 |
PS(Pixel Shader) | 한점 한점을 어떻게 처리할 것인가? 픽셀 하나하나를 처리하는 과정. 색을 결정하는 과정에 쓰인다. |
User Interface
UserInterfaceDemo.h
더보기
#pragma once
#include "Systems/IExecute.h"
class UserInterfaceDemo : public IExecute
{
public:
virtual void Initialize() override;
virtual void Ready() 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:
Shader* shader;
Vertex vertices[6];
ID3D11Buffer* vertexBuffer;
};
UserInterfaceDemo.cpp
더보기
#include "stdafx.h"
#include "UserInterfaceDemo.h"
void UserInterfaceDemo::Initialize()
{
shader = new Shader(L"07_Rect.fx");
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 subResource = { 0 };
subResource.pSysMem = vertices;
Check(D3D::GetDevice()->CreateBuffer(&desc, &subResource, &vertexBuffer));
}
void UserInterfaceDemo::Destroy()
{
SafeDelete(shader);
SafeRelease(vertexBuffer);
}
void UserInterfaceDemo::Update()
{
// 왼쪽아래 vertex 좌우 이동
if (Keyboard::Get()->Press(VK_RIGHT))
{
vertices[0].Position.x += 2.0f * Time::Delta();
}
else if (Keyboard::Get()->Press(VK_LEFT))
{
vertices[0].Position.x -= 2.0f * Time::Delta();
}
static float y = 0.5f;
ImGui::SliderFloat("V", &y, -1, +1);
vertices[1].Position.y = y;
D3D::GetDC()->UpdateSubresource(vertexBuffer, 0, NULL, vertices, sizeof(Vertex) * 6, 0);
}
void UserInterfaceDemo::Render()
{
// ImGui 구현
static bool bOpen = true;
if (Keyboard::Get()->Down(VK_SPACE))
{
bOpen = !bOpen;
}
if (bOpen)
{
ImGui::ShowDemoWindow(&bOpen);
}
// 방향키 누를 때 좌측 상단에 "Right" "Left" 출력
string text = "";
if (Keyboard::Get()->Press(VK_RIGHT))
{
text += "Right";
}
else if (Keyboard::Get()->Press(VK_LEFT))
{
text += "Left";
}
Gui::Get()->RenderText(10, 60, 1, 0, 0, text);
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, 6);
}
Main.cpp
더보기
#include "stdafx.h"
#include "Main.h"
#include "Systems/Window.h"
#include "UserInterfaceDemo.h"
#include "TriangleList.h"
#include "Vertex_Line2.h"
#include "Vertex_Line.h"
void Main::Initialize()
{
Push(new UserInterfaceDemo());
}
void Main::Ready()
{
}
void Main::Destroy()
{
for (IExecute* exe : executes)
{
exe->Destroy();
SafeDelete(exe);
}
}
void Main::Update()
{
for (IExecute* exe : executes)
exe->Update();
}
void Main::PreRender()
{
for (IExecute* exe : executes)
exe->PreRender();
}
void Main::Render()
{
for (IExecute* exe : executes)
exe->Render();
}
void Main::PostRender()
{
for (IExecute* exe : executes)
exe->PostRender();
}
void Main::ResizeScreen()
{
for (IExecute* exe : executes)
exe->ResizeScreen();
}
void Main::Push(IExecute * execute)
{
executes.push_back(execute);
execute->Initialize();
}
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR param, int command)
{
D3DDesc desc;
desc.AppName = L"D3D Game";
desc.Instance = instance;
desc.bFullScreen = false;
desc.bVsync = false;
desc.Handle = NULL;
desc.Width = 1280;
desc.Height = 720;
desc.Background = Color(0.3f, 0.3f, 0.3f, 1.0f);
D3D::SetDesc(desc);
Main* main = new Main();
WPARAM wParam = Window::Run(main);
SafeDelete(main);
return wParam;
}
UserInterface 실행화면
'⭐ DirectX > DirectX11 3D' 카테고리의 다른 글
[DirectX11] 011 Index (0) | 2023.01.10 |
---|---|
[DirectX11] 010 World (0) | 2023.01.09 |
[DirectX11] 009 World Matrix (0) | 2023.01.08 |
[DirectX11] 006~007 사각형 띄우기 (0) | 2023.01.06 |
[DirectX11] 001~005 DirectX11 기초, NDC 좌표계 (0) | 2023.01.04 |
댓글
이 글 공유하기
다른 글
-
[DirectX11] 010 World
[DirectX11] 010 World
2023.01.09 -
[DirectX11] 009 World Matrix
[DirectX11] 009 World Matrix
2023.01.08 -
[DirectX11] 006~007 사각형 띄우기
[DirectX11] 006~007 사각형 띄우기
2023.01.06 -
[DirectX11] 001~005 DirectX11 기초, NDC 좌표계
[DirectX11] 001~005 DirectX11 기초, NDC 좌표계
2023.01.04