Directx 11 with rastertek
Tutorial 13: Direct Input 연습문제
코다람쥐
2022. 9. 14. 23:56
To Do Exercises
1. Recompile and run the program. Move the mouse around the screen and watch the text position update.
2. Use the information from the 2D Rendering tutorial and combine it with this one to create your own mouse cursor that moves with the mouse movement.
3. Implement a function that reads the keyboard buffer and displays what you type on the screen.
1. 프로그램을 다시 컴파일하고 실행해 보십시오. 마우스를 화면 내에서 이동하고 위치를 표시하는 글자가 바뀌는 것을 확인해 보십시오.

2. 2D 렌더링 튜토리얼의 내용을 활용하여 마우스 이동이 반영되는 마우스 커서를 만들어 보십시오.
graphicsclass.cpp
bool GraphicsClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
{
................................생략............................
// Create the bitmap object.
m_Bitmap = new BitmapClass;
if (!m_Bitmap)
{
return false;
}
// Initialize the bitmap object.
result = m_Bitmap->Initialize(m_D3D->GetDevice(), screenWidth, screenHeight,
L"../rastertek/data/Cursor.dds", 32, 32);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the bitmap object.", L"Error", MB_OK);
return false;
}
................................생략............................
}
먼저 Initialize함수에서 비트맵 객체를 생성하고 초기화.
Cursor.dds
0.00MB
위의 파일은 작성자가 그림판으로 그린 Cursor.dds 파일입니다.
graphicsclass.cpp
void GraphicsClass::Shutdown()
{
.......................생략...................
if (m_Bitmap)
{
m_Bitmap->Shutdown();
delete m_Bitmap;
m_Bitmap = 0;
}
.......................생략...................
}
비트맵 객체 메모리 해제
graphicsclass.cpp
bool GraphicsClass::Render(int mouseX, int mouseY)
{
..........................생략............................
result = m_Bitmap->Render(m_D3D->GetDeviceContext(), mouseX, mouseY);
if (!result)
{
return false;
}
..........................생략............................
}
Render함수의 인자로 mouseX와 mouseY를 주어서 랜더링 할 때 마우스 포인터의 위치를 따라다니도록 만들었다.

회색 배경색이 거슬리긴하지만 아직 투명도를 배우지 않았기 때문에 패스~
3. 키보드 버퍼를 읽고 입력한 내용을 화면에 표시하는 기능을 구현하십시오.

키보드로 B를 누르면 'Pressed Key: b'가 뜨게했는데 사실 코드가 완벽하지 않아서 올리지는 않는다.