1
DirectX를 사용하므로 directxtutorial.com 자습서를 사용하고 있습니다. 내 게임을 실행할 때 CPU 사용량이 매우 높습니다. 그것은 내 프로세서의 첫 번째 코어의 모든 힘을 필요로합니다. 셀러론 e3400 있습니다. 내게 아무것도없이 내 게임을 실행하는 것보다 훨씬 더 많은 일이라고 생각합니다.CPU 사용량이 매우 높습니다. 9
죄송합니다. 나는 무엇이 잘못 될 수 있는지 전혀 모른다. 다음과 같이 처리 할 메시지가 없을 때
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#pragma (lib, "d3d9.lib")
#define Width_X 1024
#define Height_Y 768
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3d_device;
void d3d_initialize(HWND hWnd);
void render_frame();
void d3d_clear();
void d3d_initialize(HWND hWnd)
{
d3d = Direct3DCreate9(32); // value for dx9 = 32, i think
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp,sizeof(d3dpp));
d3dpp.Windowed = false;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; // set the back buffer format to 32-bit
d3dpp.BackBufferWidth = Width_X; // set the width of the buffer
d3dpp.BackBufferHeight = Height_Y;
d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3d_device);
}
void render_frame()
{
d3d_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(54, 222, 10), 1.0f, 0);
d3d_device->BeginScene();
d3d_device->EndScene();
d3d_device->Present(NULL, NULL, NULL, NULL);
}
void cleanD3D(void)
{
d3d_device->Release(); // close and release the 3D device
d3d->Release(); // close and release Direct3D
}
LRESULT CALLBACK WindowProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
//wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = "WindowClass1";
RegisterClassEx(&wc);
hWnd = CreateWindowExW(NULL,
L"WindowClass1", // name of the window class
L"Test", // title of the window
WS_EX_TOPMOST ,//| WS_POPUP, // window style //
0, // x-position of the window
0, // y-position of the window
Width_X, // width of the window
Height_Y, // height of the window
NULL, // we have no parent window, NULL
NULL, // we aren't using menus, NULL
hInstance, // application handle
NULL); // used with multiple windows, NULL
ShowWindow(hWnd, nCmdShow);
d3d_initialize(hWnd);
MSG msg;
while(TRUE)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(msg.message == WM_QUIT)
break;
render_frame();
}
return msg.wParam;
cleanD3D();
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
}
return DefWindowProc (hWnd, message, wParam, lParam);
}
directx 앱은 프로세서를 100 % 사용하여 가능한 초당 많은 프레임을 렌더링합니다. – GSerg
오. 그런 다음 2 가지 더 궁금한 점이 있습니다. 어떻게하면 내 fps를 볼 수 있습니까? 어떻게 제한합니까? 고맙습니다. – Jancis
다음을 참조하십시오. http://stackoverflow.com/q/5508922/11683. – GSerg