응애맘마조
230526 강의 본문
UI를 만들고 함수 포인트를 이용해서 인식하게끔 하는 것과 텍스쳐매핑에 대해서 강의를 했었습니다.
먼저 UI 같은 경우 마우스를 주로 이용해서 사용하게 되는데 UI의 위치를 잡고 마우스를 올렸을 때, 눌렀을 때, 누르는 중일 때, 뗐을 때의 경우 4가지가 있습니다. 여기서 가장 기본은 마우스를 올렸을 때이기 때문에 마우스를 올렸을 때의 함수를 만들어서 명령어를 실행하게 만들었습니다.
if (ui->MouseOver())
{
player->rotation.z += DELTA;
}
현재는 마우스를 올렸을 때 Z값으로 돌아가도록 만들었지만 이 함수를 사용해서 많은 기능을 구현할 수 있습니다. 또한 위치를 지정할 수 있도록 ImGui 내에서 구현할 수 있도록 했습니다.
if (ImGui::BeginTabItem("UI"))
{
if (ImGui::Button("LT"))
{
pivot = Vector2(0.5f, -0.5f);
}
ImGui::SameLine();
if (ImGui::Button("T"))
{
pivot = Vector2(0.0f, -0.5f);
}
ImGui::SameLine();
if (ImGui::Button("RT"))
{
pivot = Vector2(-0.5f, -0.5f);
}
if (ImGui::Button("L "))
{
pivot = Vector2(0.5f, 0.0f);
}
ImGui::SameLine();
if (ImGui::Button("N"))
{
pivot = Vector2(0.0f, 0.0f);
}
ImGui::SameLine();
if (ImGui::Button("R "))
{
pivot = Vector2(-0.5f, 0.0f);
}
if (ImGui::Button("LB"))
{
pivot = Vector2(0.5f, 0.5f);
}
ImGui::SameLine();
if (ImGui::Button("B"))
{
pivot = Vector2(0.0f, 0.5f);
}
ImGui::SameLine();
if (ImGui::Button("RB"))
{
pivot = Vector2(-0.5f, 0.5f);
}
다음은 텍스쳐입니다. 프레임워크 내에 새롭게 클래스를 추가했습니다.
#pragma once
class Texture
{
ID3D11SamplerState* Sampler;
public:
ID3D11ShaderResourceView* srv;
string file;
D3D11_SAMPLER_DESC SamplerDesc;
Texture();
~Texture();
void LoadFile(string file);
void RenderDetail();
void CreateSampler();
void Set(int slot);
};
#include "Framework.h"
Texture::Texture()
{
Sampler = nullptr;
srv = nullptr;
//기본 샘플러 값
SamplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
SamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
SamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
SamplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
SamplerDesc.MipLODBias = 0.0f;
SamplerDesc.MaxAnisotropy = 1;
SamplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
SamplerDesc.MinLOD = -FLT_MAX;
SamplerDesc.MaxLOD = FLT_MAX;
CreateSampler();
}
Texture::~Texture()
{
SafeRelease(srv);
SafeRelease(Sampler);
}
void Texture::RenderDetail()
{
ImGui::Text(file.c_str());
ImVec2 size(400, 400);
ImGui::Image((void*)srv, size);
ImGui::PushID(this);
if (ImGui::Button("SamplerButton"))
{
ImGui::OpenPopup("Sampler");
}
if (ImGui::BeginPopup("Sampler"))
{
if (ImGui::Button("Filter POINT"))
{
SamplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
CreateSampler();
}
if (ImGui::Button("Filter LINEAR"))
{
SamplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
CreateSampler();
}
if (ImGui::Button("AddressU Clamp"))
{
SamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
CreateSampler();
}
if (ImGui::Button("AddressU Wrap"))
{
SamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
CreateSampler();
}
if (ImGui::Button("AddressU Mirror"))
{
SamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_MIRROR;
CreateSampler();
}
if (ImGui::Button("AddressV Clamp"))
{
SamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
CreateSampler();
}
if (ImGui::Button("AddressV Wrap"))
{
SamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
CreateSampler();
}
if (ImGui::Button("AddressV Mirror"))
{
SamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_MIRROR;
CreateSampler();
}
ImGui::EndPopup();
}
ImGui::PopID();
}
void Texture::LoadFile(string file)
{
this->file = file;
size_t index = file.find_last_of('.');
//확장자 문자열 자르기
string format = file.substr(index + 1, file.length());
wstring path = L"../Contents/Texture/" + Util::ToWString(file);
//wstring path = L"D:/Song/DX/Contents/Texture/" + Util::ToWString(file);
ScratchImage image;
HRESULT hr;
if (format == "tga")
hr = LoadFromTGAFile(path.c_str(), nullptr, image);
else if (format == "dds")
hr = LoadFromDDSFile(path.c_str(), DDS_FLAGS_NONE, nullptr, image);
else
hr = LoadFromWICFile(path.c_str(), WIC_FLAGS_NONE, nullptr, image);
Check(hr);
CreateShaderResourceView(D3D->GetDevice(), image.GetImages(), image.GetImageCount(),
image.GetMetadata(), &srv);
}
void Texture::CreateSampler()
{
SafeRelease(Sampler);
HRESULT hr;
hr = D3D->GetDevice()->CreateSamplerState(&SamplerDesc, &Sampler);
Check(hr);
}
void Texture::Set(int slot)
{
D3D->GetDC()->PSSetShaderResources(slot,// 연결될레지스터 번호 0
1,//리소스갯수
&srv);
D3D->GetDC()->PSSetSamplers(slot, 1, &Sampler);
}
위와 같이 해서 이미지 파일도 불러올 수 있게 했습니다.
읽어주셔서 감사합니다.