Engine
The Game Engine for Ian Parberry's "Introduction to Game Physics with Box2D"
|
The renderer. More...
#include <renderer.h>
Public Member Functions | |
CRenderer () | |
Constructor. | |
void | Initialize () |
Initialize Direct3D. | |
BOOL | BeginScene () |
Start of frame. | |
void | DrawBackground () |
Draw the background to the screen. | |
void | EndScene () |
End of frame. | |
void | End () |
Release all DirectX resources. | |
void | Load (int sprite, char *name) |
Load sprite. | |
void | draw (int sprite, float x, float y, float angle=0.0f, float xsize=1.0f, float ysize=1.0f) |
Draw sprite. | |
void | drawtop (int sprite, float x, float y, float angle=0.0f, float size=1.0f) |
Draw sprite at top of screen. | |
void | GetWorldSize (int &x, int &y) |
Get the Render World width and height. | |
Protected Member Functions | |
HRESULT | CreateD3DDevice (HWND hwnd) |
Create D3D device. | |
void | SetWorldMatrix (float dx=0.0f) |
Set the world matrix. | |
void | SetViewMatrix (float x, float y, float z) |
Set the view matrix. | |
void | SetProjectionMatrix () |
Set the projection matrix. | |
void | SetAmbientLighting () |
Set ambient lighting. | |
void | SetTextureStates () |
Set texture stage states. | |
void | SetD3dStates () |
Set D3D states. | |
BOOL | RestoreDevice () |
Restore lost device. | |
BOOL | DeviceLost () |
Check for lost device. | |
void | ReleaseD3D () |
Release the D3D object. | |
void | LoadTexture (LPDIRECT3DTEXTURE9 &texture, char *filename) |
Load a texture. | |
BOOL | PageFlip () |
Graphics device page flip. | |
void | GetTextDC (COLORREF color) |
Get Windows device context. | |
void | ReleaseTextDC () |
Release device context. | |
void | TextWrite (char *string, COLORREF color=RGB(255, 255, 255)) |
Write text to screen. | |
void | InitBackgroundVertexBuffer () |
Initialize vertex buffer for background. | |
void | LoadBackground () |
Load the background image. | |
Protected Attributes | |
D3DPRESENT_PARAMETERS | m_d3dpp |
Device specifications. | |
IDirect3D9 * | m_d3d |
D3D object. | |
IDirect3DSurface9 * | m_d3dbackbuffer |
Back buffer for rendering. | |
CTextManager | m_cTextManager |
Text manager. | |
LPDIRECT3DVERTEXBUFFER9 | m_pBackgroundVB |
Vertex buffer for background. | |
LPDIRECT3DTEXTURE9 | m_pBackgroundTexture |
Texture for background. | |
IDirect3DDevice9 * | m_d3ddevice |
Graphics device. | |
CSpriteManager | m_cSpriteManager |
Sprite manager. | |
int | m_nScreenWidth |
Screen width in pixels. | |
int | m_nScreenHeight |
Screen height in pixels. | |
Friends | |
void | InitGame () |
The renderer.
The renderer class handles all the nasty Direct3D details that I don't want readers to get into, or even be distracted by.
BOOL CRenderer::BeginScene | ( | ) |
Start of frame.
Start the render pipeline.
|
protected |
Create D3D device.
hwnd | Window handle. |
|
protected |
Check for lost device.
void CRenderer::draw | ( | int | sprite, |
float | x, | ||
float | y, | ||
float | angle = 0.0f , |
||
float | xsize = 1.0f , |
||
float | ysize = 1.0f |
||
) |
Draw sprite.
Draw a sprite, using the Sprite Manager to do the heavy lifting.
sprite | Index of sprite in Sprite Manager. |
x | Horizontal coordinate in screen space. |
y | Vertical coordinate in screen space. |
angle | Orientation in radians. |
xsize | Width of sprite, 1.0 is actual size. |
ysize | Height of sprite, 1.0 is actual size. |
void CRenderer::drawtop | ( | int | sprite, |
float | x, | ||
float | y, | ||
float | angle = 0.0f , |
||
float | size = 1.0f |
||
) |
Draw sprite at top of screen.
Draw a sprite, using the Sprite Manager to do the heavy lifting. This time the vertical coordinate is measured down from top of screen.
sprite | Index of sprite in Sprite Manager. |
x | Horizontal coordinate in screen space. |
y | Vertical coordinate in screen space, measured from top of screen. |
angle | Orientation in radians. |
size | Size of sprite, 1.0 is actual size. |
void CRenderer::End | ( | ) |
Release all DirectX resources.
Release game textures. All textures used in the game are released - the release function is kind of like a destructor for DirectX entities, which are COM objects.
void CRenderer::EndScene | ( | ) |
End of frame.
Stop the render pipeline.
|
protected |
Get Windows device context.
Get device context for drawing screen text.
color | Color to draw text in. |
void CRenderer::GetWorldSize | ( | int & | w, |
int & | h | ||
) |
Get the Render World width and height.
w | Width. |
h | Height. |
|
protected |
Initialize vertex buffer for background.
Create and set up a vertex buffer for the background image.
void CRenderer::Initialize | ( | ) |
Initialize Direct3D.
Initialize the renderer. Create a D3D object, set the graphics mode, create a vertex buffer, get a pointer to the back buffer, squirrel away the screen width and height.
void CRenderer::Load | ( | int | sprite, |
char * | name | ||
) |
Load sprite.
Load a sprite using the Sprite Manager to do the heavy lifting.
sprite | Index of sprite in Sprite Manager. |
name | Name of sprite in GameSettings.xml |
|
protected |
Load the background image.
Load the background image after getting the file name from g_xmlSettings.
|
protected |
Load a texture.
Load a texture from a file. Loads an image from a file into a D3D texture. Aborts if the file doesn't exist.
texture | pointer to D3D texture to receive the image |
filename | name of the fle containing the texture |
|
protected |
Graphics device page flip.
Show the back buffer. If we are fullscreen, flip back buffer to front to show next frame of animation. If we are windowed, blit the back buffer to the front instead. D3D takes care of the details.
|
protected |
Release the D3D object.
Release the D3D object after releasing the background vertex buffer and D3D device, and D3D object. D3D requires that it be done in this order.
|
protected |
Restore lost device.
Restore the D3D device. The D3D device can be lost, for example, by the use alt+tabbing out of the app. This function restores the device, resets the default states that we initially set, and tests the result.
|
protected |
Set ambient lighting.
Set the ambient lighting and the material to bright white.
|
protected |
Set D3D states.
Set the D3D render states (texture states, world matrix, view matrix, projection matrix, background vertex buffer) to useful values for the game.
|
protected |
Set the projection matrix.
Set the projection matrix to orthogonal projection with the window aspect ratio and a 90 degree field of view.
|
protected |
Set texture stage states.
Set the D3D texture states to useful defaults.
|
protected |
Set the view matrix.
Set the view matrix's orientation to default, position to parameters.
x | x-coordinate of camera position |
y | y-coordinate of camera position |
z | z-coordinate of camera position |
|
protected |
Set the world matrix.
Set the world matrix to a translation matrix a given distance along the X-axis.
dx | distance along the X-axis |
|
protected |
Write text to screen.
Use the Text Manager to draw colored text to the back buffer.
string | Text to display. |
color | Color to display it in. |