誰かがこのコードセクションの欠陥を見つけてください。私は何が間違っているのか把握しようと時間を費やしました。私は基本的なDirectXアプリケーションの大規模な遅れを蓄えています。なぜこれが原因ですか?欠陥C++コードを見つけよう
#include <Windows.h>
#include <d3d9.h>
// Function Prototypes
LRESULT CALLBACK MsgProc(HWND Wnd,UINT message,WPARAM wParam,LPARAM lParam);
INT CreateAndRegisterWindow(HINSTANCE hInst);
INT initilizeD3D(HWND hWnd);
VOID Render();
//Globals
HWND GlobalWindowHandle;
LPDIRECT3D9 lpD3D9;
LPDIRECT3DDEVICE9 lpD3DDevice9;
const wchar_t ClassName[] = L"Tutorial";
//Entry Point
INT WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpCmdLine,INT CmdShow)
{
// Register the window class
WNDCLASSEX wc =
{
sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
L"D3D Tutorial", NULL
};
RegisterClassEx(&wc);
// Create the application's window
GlobalWindowHandle = CreateWindow(L"D3D Tutorial", L"D3D Tutorial 01: CreateDevice",
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
NULL, NULL, wc.hInstance, NULL);
initilizeD3D(GlobalWindowHandle);
ShowWindow(GlobalWindowHandle,SW_SHOW);
UpdateWindow(GlobalWindowHandle);
MSG msg;
while(GetMessage(&msg,NULL,NULL,NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
INT CreateAndRegisterWindow(HINSTANCE hInst)
{
WNDCLASSEX wcex;
ZeroMemory(&wcex, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.hbrBackground = (HBRUSH)COLOR_WINDOW;
wcex.hCursor = LoadCursor(0,IDC_ARROW);
wcex.hInstance = hInst;
wcex.lpfnWndProc = (WNDPROC)MsgProc;
wcex.lpszClassName = ClassName;
if(FAILED(RegisterClassEx(&wcex)))
{
MessageBoxA(GetForegroundWindow(),"Failed to register class.","Error",MB_ICONERROR);
return EXIT_FAILURE;
}
GlobalWindowHandle = CreateWindow(ClassName,L"Tutorial",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,300,350,NULL,NULL,0,NULL);
if(!GlobalWindowHandle)
MessageBoxA(GetForegroundWindow(),"Failed to create window.","Error",MB_ICONERROR);
return EXIT_SUCCESS;
}
LRESULT CALLBACK MsgProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_PAINT:
UpdateWindow(hWnd);
Render();
return 0;
case WM_DESTROY:
PostQuitMessage(EXIT_SUCCESS);
return 0;
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}
INT initilizeD3D(HWND hWnd)
{
if(NULL==(lpD3D9 = Direct3DCreate9(D3D_SDK_VERSION)))
MessageBoxA(GetForegroundWindow(),"Failed to create direct3d device","Error",MB_ICONERROR);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
if(FAILED(lpD3D9->CreateDevice (D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&lpD3DDevice9)))
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
VOID Render()
{
if(NULL == lpD3DDevice9)
return;
// Clear the backbuffer to a blue color
lpD3DDevice9->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
// Begin the scene
if(SUCCEEDED(lpD3DDevice9->BeginScene()))
{
// Rendering of scene objects can happen here
// End the scene
lpD3DDevice9->EndScene();
}
// Present the backbuffer contents to the display
lpD3DDevice9->Present(NULL, NULL, NULL, NULL);
}
すごい私はちょうどValidateRectがそれを原因といくつかの奇妙な理由で間違っているものを見てきました方法をスピードアップする??? –
うーん、わかりません。その情報で元の質問を編集できますか?多分誰かがそれを見て、返信します。関数に関する情報は次のとおりです:http://msdn.microsoft.com/en-us/library/dd145194(v=vs.85).aspx - この人は同じ問題がありましたが、答えは答えられませんでした:http:// stackoverflow .com/questions/9281479/why-does-not-having-validaterect-a-directx-application-to-slow-down-tremen – David