C++
-
[DirectX] QPC로 FPS(프레임 레이트) 구현하기C++/미분류 2024. 2. 20. 16:06
QPC란 Query Performance Counter로, Windows에서 사용되는 시간 측정을 위한 기능입니다. 이번 글에서는 QPC를 이용해서 함수의 호출 주기를 구하는 방법을 살펴보고, 프레임마다 호출되는 함수에 이 방법을 적용하여 FPS를 구해보도록 하겠습니다. 이번 글은 이전 글의 코드([WinAPI] 로그 출력하기 (Console, TRACE))의 예제를 기반으로 작성되었습니다. 1. 살펴보기 WinAPI를 이용한 이전 프로젝트는 화면을 그리기 위해 OnRender함수를 매 프레임마다 호출합니다. 따라서, 매 프레임마다 호출되는 OnRender함수의 호출 주기를 알 수 있다면, 프레임 레이트를 구할 수 있습니다. 2. QPC 사용하기 더보기 QPC에서 주로 사용되는 함수는 다음과 같습니다. ..
-
[WinAPI] 로그 출력하기 (Console, TRACE)C++/미분류 2024. 2. 16. 16:25
로그는 프로그램의 상태를 확인할 때 사용하는 가장 직관적인 방법 중 하나입니다. WinAPI는 자체적인 로그를 출력하는 기능을 제공하지 않기 때문에, 로그를 출력할 방법이 필요합니다. 이번 글에서는 로그를 출력하는 여러 방법 중, Console창을 추가로 띄우는 방법과 MFC에서 사용하는 방법을 살펴보도록 하겠습니다. 이번 글은 Visual Studio 2022환경에서 작성되었습니다. 0. 시작하기 전에 더보기 이번 글은 프로그램 실행 환경을 디버그와 릴리즈 두 가지를 번갈아 가며 확인할 예정입니다. 따라서, 디버그와 릴리즈 환경에서의 진입점 및 라이브러리 의존성을 동일하게 할 필요가 있습니다. 프로젝트 우클릭 후 Properties로 진입합니다. 진입한 Property Page의 Configuratio..
-
[Direct2D] 도형 그려보기C++/미분류 2024. 2. 8. 17:53
지난 글 (Windows application 만들기)에서 WinAPI를 이용해 빈 윈도우를 만드는 방법을 알아봤습니다. 이번 글에서는 위 글의 내용에 이어, 빈 윈도우에 Direct2D(이하 D2D)로 도형을 그려보도록 하겠습니다. 이번 글은 MSDN을 참고하여 작성되었습니다. 간단한 Direct2D 애플리케이션 만들기 : Microsoft Learn 0. 라이브러리 추가 더보기 Direct2D 라이브러리를 추가하는 작업이 선행되어야 합니다. 프로젝트 우클릭, Properties로 진입합니다. Properties의 Linker->Input 항목의 Additional Dependencies에 다음과 같이 라이브러리를 추가합니다. 추가되는 항목은 다음과 같습니다. d2d1.lib dwrite.lib Win..
-
[WinAPI] 메시지 루프에 대한 간단한 고찰C++/C++ 자문자답 2024. 1. 25. 20:01
DirectX에 대한 공부 이전에, WinAPI에 대한 학습이 부족했습니다. 이에 몇 가지 공부했습니다. Q1. WinAPI의 메시지 루프 A1. Windows 응용 프로그램은 사용자의 입력, OS의 이벤트를 메시지 큐에 저장합니다. 저장된 메시지 루프는 GetMessage, TranslateMessage, DispatchMessage등의 함수에 의해 확인, 수정, 전달될 수 있습니다. Q2. 메시지 루프는 비동기인가? A2. 메시지 루프에 여러 스레드를 접근시켜 성능을 향상시킬 수 있는지에 대한 의문이었습니다. 메시지 루프가 비동기인지는 아직 확실하지 않지만, 이에 대한 글을 볼 수 있었습니다. Why does the win32 message loop stop working when threaded? ..
-
[Win32] Windows application 만들기C++/미분류 2024. 1. 25. 19:35
Win32 API(이하 WinAPI)는 C++에서 GUI개발을 위해 사용되는 대표적인 라이브러리 중 하나입니다. 이번 글에서는 WinAPI를 이용해 간단한 Window하나를 만들어보도록 하겠습니다. 이번 글에서는 Visual Studio 2022 (v143)를 사용합니다. 1. 프로젝트 생성 및 초기설정 더보기 위와 같이 새 프로젝트를 생성합니다. 이후, Visual Studio창에서 Alt + Enter 혹은 위와 같이 Project 우클릭으로 Property Page로 들어갑니다. Property Page 의 Linker-System에서 SubSystem을 Windows로 변경합니다. 이는 exe파일의 진입점을 명시하는 작업입니다. (Console과 Windows는 main함수에 차이가 있습니다.) ..
-
[Effective Modern C++] insert와 emplaceC++/Effective Modern C++ 2023. 6. 13. 16:07
C++의 여러 컨테이너는 여러 종류의 삽입 함수를 지원합니다. 컨테이너의 종류에 따라 다르지만, 대부분 push혹은 insert라는 이름을 취하고 있습니다. 이러한 컨테이너에 자료를 삽입하는 경우를 생각해보도록 하겠습니다. std::vector vec; vec.push_back("asdf"); 위 코드의 push_back부분을 자세히 들여다보도록 하겠습니다. 위 삽입 과정은 다음과 같이 진행됩니다. 삽입하는 인자 "asdf"로부터 임시 std::string 객체가 생성됩니다. 이 객체에는 이름이 없지만, 지금은 temp라고 명명하도록 하겠습니다. temp가 push_back에 전달 R-value reference로 전달됩니다. 전달된 R-value reference를 통해 std::string 객체가 생..
-
[Effective Modern C++] 값 전달을 고려할만한 상황C++/Effective Modern C++ 2023. 6. 9. 14:04
값 전달(Pass by value)은 C++에서 기피되는 방식입니다. 전달 과정에서 이미 복사(이동)연산이 추가적으로 발생하며, 그 외에도 일어날 수 있는 추가적인 문제가 있기 때문입니다. 이에 권장되는 전달 방식은 참조 전달(Pass by reference)입니다. 하지만, 이번 글에서는 그럼에도 불구하고 값 전달을 고려할 수 있는 경우를 살펴볼 것 입니다. 이번 글에서 살펴 볼 예제 코드의 시나리오는 다음과 같습니다. MyClass라는 클래스 내의 멤버 함수를 다룹니다. 이 함수는 문자열을 받아서 자신의 문자열 배열 멤버 변수에 저장합니다. 위 내용의, 멤버 함수를 제외한 클래스 구현은 다음과 같습니다. class MyClass { public: // Function private: std::vect..
-
[Effective Modern C++] std::atomic VS volatileC++/Effective Modern C++ 2023. 5. 12. 18:32
volatile과 std::atomic은 서로 다른 기능을 하는 도구입니다. 그러나 두 도구 모두 변수에 특정 속성을 부여하고, 최적화, 동기화와 관련된 도구이다보니 그 사용처가 혼동되고는 합니다. 이번 글에서는 두 도구의 차이를 중점적으로 살펴보도록 하겠습니다. 1. RMW(Read-Modify-Write) operation 더보기 다음 예제를 보도록 하겠습니다. std::atomic ai(0); // ai = 0 ai = 10; // ai = 10 ++ai; // ai = 11 --ai; // ai = 10 위 코드의 std::atomic객체 ai에 대한 연산에 대하여, 관측 가능한 ai의 값은 주석과 동일한 0, 10, 11입니다. std::atmoic객체는 객체에 대한 연산을 원자적으로 (더 이상..