[DirectX11] 006~007 사각형 띄우기
목차
Vertex Buffer 세팅
디바이스 구조 기초
두르기 순서
왼손 좌표계의 경우 시계 방향으로 감긴다. 반면에 오른손 좌표계의 경우 반시계 방향으로 감긴다.
DX9 - 왼손 좌표계
Unreal, Unity - 왼손 좌표계
DX10, 11, 12, GL - 오른손 좌표계이지만 기존의 컨벤션을 유지하기 위해 왼손 좌표계 방식으로 코팅을 한다.
사각형 출력하기
07_Rect.fx
더보기
struct VertexInput
{
float4 Position : Position;
};
struct VertexOutput
{
float4 Position : SV_Position;
};
VertexOutput VS(VertexInput input)
{
VertexOutput output;
output.Position = input.Position;
return output;
}
float4 PS_R(VertexOutput input) : SV_Target
{
return float4(1, 0, 0, 1);
}
RasterizerState FillMode_Wireframe
{
FillMode = Wireframe;
};
technique11 T0
{
pass P0
{
SetVertexShader(CompileShader(vs_5_0, VS()));
SetPixelShader(CompileShader(ps_5_0, PS_R()));
}
pass P1
{
SetRasterizerState(FillMode_Wireframe);
SetVertexShader(CompileShader(vs_5_0, VS()));
SetPixelShader(CompileShader(ps_5_0, PS_R()));
}
}
RectDemo.h
더보기
#pragma once
#include "Systems/IExecute.h"
class RectDemo : 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;
};
RectDemo.cpp
더보기
#include "stdafx.h"
#include "RectDemo.h"
void RectDemo::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 RectDemo::Destroy()
{
SafeDelete(shader);
SafeRelease(vertexBuffer);
}
void RectDemo::Update()
{
}
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);
shader->Draw(0, 1, 6);
}
실행화면
'⭐ 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] 008 User Interface (1) | 2023.01.07 |
[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] 008 User Interface
[DirectX11] 008 User Interface
2023.01.07 -
[DirectX11] 001~005 DirectX11 기초, NDC 좌표계
[DirectX11] 001~005 DirectX11 기초, NDC 좌표계
2023.01.04