728x90
1. 코드
Execute.cpp 파일
//Create World view Projection (공간) { D3DXMatrixIdentity(&world); //항등행열 만들어지는곳 D3DXMatrixIdentity(&view); D3DXMatrixIdentity(&projection); //가상으로 만들어지는 카메라(눈) ,왼손 좌표(LH) , 오른손(RH) //넣을 좌표, 눈의 위치, 바라볼 대상 D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(0, 0, 0), &D3DXVECTOR3(0, 0, 1), &D3DXVECTOR3(0, 1, 0)); //원근, 직교 투영 2가지 방식이 존재 현재는 직교투영 (좌표계 설정) //넣을 좌표, 윈도우사이즈 x, y, 시야 0 , 1 D3DXMatrixOrthoLH(&projection,Settings::Get().GetWidth(), Settings::Get().GetHight(), 0, 1); //dx 좌표 //D3DXMatrixOrthoOffCenterLH(&view, 0 , Settings::Get().GetWidth(), Settings::Get().GetHight(), 0 ,0 , 1); //window 좌표 //D3DXMatrixOrthoOffCenterLH(&view, 0 , Settings::Get().GetWidth(), 0, Settings::Get().GetHight(),0 , 1); //window 좌표 std::cout << "View Matrix " << std::endl; std::cout << view._11 <<" " << view._12 << " "<< view._13 << " " << view._14 <<" "<< std::endl; std::cout << view._21 <<" " << view._22 << " "<< view._23 << " " << view._24 <<" "<< std::endl; std::cout << view._31 <<" " << view._32 << " "<< view._33 << " " << view._34 <<" "<< std::endl; std::cout << view._41 <<" " << view._42 << " "<< view._43 << " " << view._44 <<" "<< std::endl; std::cout << std::endl; std::cout << "projection Matrix " << std::endl; std::cout << projection._11 << " " << projection._12 << " " << projection._13 << " " << projection._14 << " " << std::endl; std::cout << projection._21 << " " << projection._22 << " " << projection._23 << " " << projection._24 << " " << std::endl; std::cout << projection._31 << " " << projection._32 << " " << projection._33 << " " << projection._34 << " " << std::endl; std::cout << projection._41 << " " << projection._42 << " " << projection._43 << " " << projection._44 << " " << std::endl; // world 크기, 사이즈 별도로 넣고 결합 D3DXMATRIX S; D3DXMATRIX T; D3DXMATRIX R; D3DXMatrixScaling(&S, 100, 100 , 1); D3DXMatrixTranslation(&T, 100, 100, 0); D3DXMatrixRotationZ(&R, static_cast<float>(D3DXToRadian(45))); // 곱하는 순서 주의 해야함 위치부터 곱하면 크기가 생략이됨 //스 * 자 * 이 * 공전 * 부모 // S 크기 * R 회전 * T 위치 world = S /** R*/ * T; } //create constant buffer {. . . } //create rasterizer state (좌표계를 변동) { D3D11_RASTERIZER_DESC desc; ZeroMemory(&desc, sizeof(D3D11_RASTERIZER_DESC)); desc.FillMode = D3D11_FILL_SOLID; // 내부 다 채움 //desc.FillMode = D3D11_FILL_WIREFRAME; // 테두리만 보임 desc.CullMode = D3D11_CULL_BACK; // 뒷면을 자름 //desc.CullMode = D3D11_CULL_FRONT; // 앞면을 자름 (window 좌표) //desc.CullMode = D3D11_CULL_NONE; // 앞면 뒷면 다 자름 desc.FrontCounterClockwise = false; // 앞면, 뒷면 여부 //cliping //그리기 전에 자름 //culling //그리고 후에 자름 auto hr = graphics->GetDevice()->CreateRasterizerState(&desc, &raterizer_state); } } void Execute::Render() { UINT stride = sizeof(VertexColor); // 정점의 하나의 크기 UINT offset = 0; //그려질 시간 graphics->Begin(); { //IA graphics->GetDeviceContext()->IASetVertexBuffers(0, 1, &vertexbuffer, &stride, &offset); // Vertexbuffer 용 graphics->GetDeviceContext()->IASetIndexBuffer(index_buffer, DXGI_FORMAT_R32_UINT, 0); // indexbuffer 용 graphics->GetDeviceContext()->IASetInputLayout(input_layout); graphics->GetDeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); //그렬질 용도 //VS 정점의 갯수 만큼만 돌아감 (정점이 많이 있으면 오래 걸리지만 GPU는 병렬 형식) graphics->GetDeviceContext()->VSSetShader(vertex_shader, nullptr, 0); graphics->GetDeviceContext()->VSSetConstantBuffers(0, 1, &gpu_buffer); //PS graphics->GetDeviceContext()->PSSetShader(pixel_shader, nullptr, 0); //RS graphics->GetDeviceContext()->RSSetState(raterizer_state); //Pipe line 끝나면 Draw 함수로 그려줘야함 (Vs 변경하면 여기도 갯수 수정) //graphics->GetDeviceContext()->Draw(6, 0); graphics->GetDeviceContext()->DrawIndexed(6, 0, 0); //인덱스용 , (인덱스 갯수, 몇번 부터 시작, 기본 시작) } //삭제 graphics->End(); }
2. 추가 및 요약
1. D3D11_RASTERIZER_DESC 함수
FillMode : 정점들로 인해 만들어진 영역을 어떻게 채울 것인가에 대한 정보
CullMode : 어떤 면을 보이지 않게 할 것인가에 대한 정보
FrontCounterClockwise : 정점이 그려지는 순서에 따라 앞면과 뒷면을 정해주는 값
2. RS : Rasterizer
clipping : 자르기
ndc : 정규화
back-face culling : 보이지 않는 면을 제거
viewport transform : 다시 늘려줌
scan transfrom : 다시 색깔 칠하는 영역 정함
3. 한번 파이프 라인에 세팅한 경우 다른 세팅이 없다면 값은 변하지 않는다
'DirectX > DirectX 2D_(구)' 카테고리의 다른 글
총정리 (0) | 2020.11.09 |
---|---|
DX sampler_state (0) | 2020.11.06 |
DX 공간 결합 (0) | 2020.11.05 |
DX 공간 변환 (0) | 2020.11.05 |
DX indexbuffer, 공간변환(이론) (0) | 2020.11.05 |