Graphics Reference
In-Depth Information
runtime if these objects are dynamically loaded—which would almost surely cause a brief
pause in the application.
Application Loop
After initialization is complete, the application can move on to the looping portion of its
execution. This phase consists of three individual sections, which will be described in the
following sections.
Handle pending messages. After an application enters its application loop, it must re-
spond to and handle the Windows messages that it receives from the operating system.
This is performed by a callback function that is specified when the application window is
registered and created. The handling of messages is not directly relevant to Direct3D pro-
gramming, so we will skip it for now. However, all of the sample programs from this topic
implement message handling, so the fundamentals can be seen there. The message handler
can be found in the main. cpp file in the source code distribution.
Update. Our simple test application doesn't perform any simulations or implement special
physics calculations, but it does perform a simple animation to change the color of the
render target. This is performed in the Update phase of the application loop. This is a typi-
cal place to perform such updates, so that any changed state can be reflected in the current
frame's rendering, which is performed in the next step of the loop. For our sample applica-
tion, we simply calculate a sinusoidally varying value that will be used to determine the
background color of the window. This is shown in Listing 1.10.
float fBlue = sinf( m_pTimer->Runtime() * m_pTimer->Runtime() ) * 0.25f + 0.5f;
Listing 1.10. Producing a time-varying parameter for animation.
Here we see a timer class being used to acquire the amount of time that an application
has been running. This class is taken from the sample framework of this topic, and more
detail on its inner workings can be found in the source code distribution in the Timer class
files. For now, we will simply assume that it gives us the floating point number of seconds
that an application has been running.
Rendering. After updating the state of our application, we next render a representation of
our current scene for the user to see. This process begins by binding both the render target
view and the depth stencil view to the pipeline, to receive the results of any rendering
operations. Since this is a pipeline manipulation, it is performed with the device context.
Listing 1.11 shows how this is done.
Search WWH ::




Custom Search