Directx 11 with rastertek
Tutorial 12: Font Engine 연습문제
코다람쥐
2022. 9. 14. 13:09
To Do Exercises
1. Recompile the code and ensure you get a white "Hello" written to 100x100 on your screen as well as a yellow "Goodbye" beneath it.
2. Change the pixel color, location, and content of the sentences.
3. Create a third sentence structure and have it render also.
4. Comment out the blending calls in the GraphicsClass::Render function and set m_D3D->BeginScene(0.0f, 0.0f, 1.0f, 1.0f); in the GraphicsClass::Render function. This will show why blending is needed.
5. Add the blending calls back into the GraphicsClass::Render function and keep m_D3D->BeginScene(0.0f, 0.0f, 1.0f, 1.0f); in the GraphicsClass::Render function to see the difference.
1. 프로그램을 다시 컴파일하여 "Hello"라는 글자가 100, 100 위치에 나타나고 "Goodbye"라는 글자가 그 아래 생기는지 확인해 보십시오.

2. 문장의 색상, 위치, 내용을 바꿔 보십시오.
textclass.cpp
bool TextClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, HWND hwnd, int screenWidth, int screenHeight,
D3DXMATRIX baseViewMatrix)
{
.........................생략.........................
result = UpdateSentence(m_sentence1, "Hi", 200, 100, 1.0f, 0.0f, 0.0f, deviceContext);
if (!result)
{
return false;
}
.........................생략.........................
result = UpdateSentence(m_sentence2, "badbye", 200, 200, 0.0f, 1.0f, 0.0f, deviceContext);
if (!result)
{
return false;
}
.........................생략.........................
}

3. 세 번째 문장 구조체를 만들어 화면에 그려 보십시오.
textclass.h
class TextClass
{
..............생략.............
SentenceType* m_sentence3;
};
textclass.cpp
bool TextClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext,
HWND hwnd, int screenWidth, int screenHeight, D3DXMATRIX baseViewMatrix)
{
............................................생략............................................
result = InitializeSentence(&m_sentence3, 16, device);
if (!result)
{
return false;
}
result = UpdateSentence(m_sentence3, "Yes, sir", 200, 300, 0.0f, 0.0f, 1.0f, deviceContext);
if (!result)
{
return false;
}
............................................생략............................................
}
void TextClass::Shutdown()
{
............................................생략............................................
ReleaseSentence(&m_sentence3);
............................................생략............................................
}
bool TextClass::Render(ID3D11DeviceContext* deviceContext, D3DXMATRIX worldMatrix, D3DXMATRIX orthoMatrix)
{
............................................생략............................................
result = RenderSentence(deviceContext, m_sentence3, worldMatrix, orthoMatrix);
if (!result)
{
return false;
}
............................................생략............................................
}

4. GraphicsClass::Render 함수에서 블렌딩과 관련된 호출을 주석 처리하고 m_D3D->BeginScene(0.0f, 0.0f, 1.0f, 1.0f); 로 고쳐 보십시오. 이렇게 하면 왜 블렌딩 처리가 필요한지 보여줄 것입니다.
graphicsclass.cpp
bool GraphicsClass::Render()
{
D3DXMATRIX worldMatrix, viewMatrix, projectionMatrix, orthoMatrix;
bool result;
// Clear the buffers to begin the scene.
m_D3D->BeginScene(0.0f, 0.0f, 1.0f, 1.0f);
// Generate the view matrix based on the camera's position.
m_Camera->Render();
// Get the view, projection, and world matrices from the camera and D3D objects.
m_Camera->GetViewMatrix(viewMatrix);
m_D3D->GetWorldMatrix(worldMatrix);
m_D3D->GetProjectionMatrix(projectionMatrix);
m_D3D->GetOrthoMatrix(orthoMatrix);
// Turn off the Z buffer to begin all 2D rendering.
m_D3D->TurnZBufferOff();
// Turn on the alpha blending before rendering the text.
//m_D3D->TurnOnAlphaBlending();
// Render the text strings.
result = m_Text->Render(m_D3D->GetDeviceContext(), worldMatrix, orthoMatrix);
if (!result)
{
return false;
}
// Turn off alpha blending after rendering the text.
//m_D3D->TurnOffAlphaBlending();
// Turn the Z buffer back on now that all 2D rendering has completed.
m_D3D->TurnZBufferOn();
// Present the rendered scene to the screen.
m_D3D->EndScene();
return true;
}

5. GraphicsClass::Render 함수에서 주석 처리된 블렌딩 호출을 주석 해제하고 m_D3D->BeginScene(0.0f, 0.0f, 1.0f, 1.0f); 로 고쳐서 무엇이 달라졌는지 확인해 보십시오.
graphicsclass.cpp
bool GraphicsClass::Render()
{
D3DXMATRIX worldMatrix, viewMatrix, projectionMatrix, orthoMatrix;
bool result;
// Clear the buffers to begin the scene.
m_D3D->BeginScene(0.0f, 0.0f, 1.0f, 1.0f);
// Generate the view matrix based on the camera's position.
m_Camera->Render();
// Get the view, projection, and world matrices from the camera and D3D objects.
m_Camera->GetViewMatrix(viewMatrix);
m_D3D->GetWorldMatrix(worldMatrix);
m_D3D->GetProjectionMatrix(projectionMatrix);
m_D3D->GetOrthoMatrix(orthoMatrix);
// Turn off the Z buffer to begin all 2D rendering.
m_D3D->TurnZBufferOff();
// Turn on the alpha blending before rendering the text.
m_D3D->TurnOnAlphaBlending();
// Render the text strings.
result = m_Text->Render(m_D3D->GetDeviceContext(), worldMatrix, orthoMatrix);
if (!result)
{
return false;
}
// Turn off alpha blending after rendering the text.
m_D3D->TurnOffAlphaBlending();
// Turn the Z buffer back on now that all 2D rendering has completed.
m_D3D->TurnZBufferOn();
// Present the rendered scene to the screen.
m_D3D->EndScene();
return true;
}

참고로 'yes, sir'는 배경색이랑 겹쳐서 안보임.
font.dds
0.06MB
fontdata.txt
0.00MB