Game Development Reference
In-Depth Information
t=0;
}
}
}
InitD3D —This function initializes a main application window and
implements the Direct3D initialization code discussed in section
1.4. It outputs a pointer to a created IDirect3DDevice9 inter-
face if the function returns successfully. Observe that the parame-
ters allow us to specify the window's dimensions and whether it
should run in windowed mode or full-screen mode. See the sample
code for further details on its implementation.
EnterMsgLoop —This function wraps the application message
loop. It takes a pointer to a function that is to be the display func-
tion . The display function is the function that implements the sam-
ple's drawing code. The message loop function needs to know the
display function so that it can call it and display the scene during
idle processing:
int d3d::EnterMsgLoop( bool (*ptr_display)(float timeDelta) )
{
MSG msg;
::ZeroMemory(&msg, sizeof(MSG));
static float lastTime = (float)timeGetTime();
while(msg.message != WM_QUIT)
{
if(::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
else
{
float currTime = (float)timeGetTime();
float timeDelta = (currTime -
lastTime)*0.001f;
ptr_display(timeDelta); // call display function
lastTime = currTime;
}
}
return msg.wParam;
}
The “time” code is used to calculate the time elapsed between calls
to ptr_display , that is, the time between frames.
Release —This template function is designed as a convenience
function to release COM interfaces and set them to null.
Search WWH ::




Custom Search