Main Page | Class List | File List | Class Members | File Members

Main.cpp File Reference

Performs DirectX initialization via DXUT callback functions. Adds some additional helper functions to support screenshot capturing. More...

#include "dxstdafx.h"
#include "resource.h"
#include <math.h>
#include <stdio.h>
#include <time.h>
#include "Cube.h"
#include "Mesh.h"
#include "Parameters.h"
#include "EnvMap.h"

Defines

#define FX_FILENAME   L"EnvMap.fx"
 File containing the shader code.

Functions

bool CALLBACK IsDeviceAcceptable (D3DCAPS9 *pCaps, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, bool bWindowed, void *pUserContext)
 DXUT callback (Rejects any devices that aren't acceptable by returning false).
bool CALLBACK ModifyDeviceSettings (DXUTDeviceSettings *pDeviceSettings, const D3DCAPS9 *pCaps, void *pUserContext)
 DXUT callback (Before a device is created, modifies the device settings as needed).
HRESULT CALLBACK OnCreateDevice (IDirect3DDevice9 *g_pd3dDevice, const D3DSURFACE_DESC *pBackBufferSurfaceDesc, void *pUserContext)
 DXUT callback (You should create any D3DPOOL_MANAGED resources here).
HRESULT CALLBACK OnResetDevice (IDirect3DDevice9 *g_pd3dDevice, const D3DSURFACE_DESC *pBackBufferSurfaceDesc, void *pUserContext)
 DXUT callback (You should create any D3DPOOL_DEFAULT resources here).
void CALLBACK OnFrameMove (IDirect3DDevice9 *g_pd3dDevice, double fTime, float fElapsedTime, void *pUserContext)
 DXUT callback (Handle updates to the scene).
void CALLBACK OnFrameRender (IDirect3DDevice9 *g_pd3dDevice, double fTime, float fElapsedTime, void *pUserContext)
 DXUT callback (Render the scene). Also responsible for screenshot taking.
LRESULT CALLBACK MsgProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool *pbNoFurtherProcessing, void *pUserContext)
 DXUT callback (Message processing).
void CALLBACK KeyboardProc (UINT nChar, bool bKeyDown, bool bAltDown, void *pUserContext)
 DXUT callback (Keystroke messages).
void CALLBACK OnGUIEvent (UINT nEvent, int nControlID, CDXUTControl *pControl, void *pUserContext)
 DXUT callback (called by the framework in case of GUI events). Forwards GUI event to the parameter-manager class Parameters (see pp).
void CALLBACK OnLostDevice (void *pUserContext)
 DXUT callback (You should release resources created in the OnResetDevice callback here).
void CALLBACK OnDestroyDevice (void *pUserContext)
 DXUT callback (You should release resources created in the OnCreateDevice callback here).
void InitParams ()
 Defines application-specific parameters and creates GUI controls (sliders, checkboxes) for them. Finally, loads initial values for the parameters from file called .params0 (Reset). Use Parameters::Add to create GUI controls.
void RenderText ()
 Renders help and statistics text and displays algorithmic-specific parameters.
void SaveCameraPosition (char *fileName)
 Writes current camera settings to file.
void LoadCameraPosition (char *fileName)
 Loads camera settings from file.
int GenerateNewFileName (int &counter)
 Generates a non-existing filename to store the screenshot in the shots directory.
INT WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int)
 Entry point to the program.
void OnLoad ()
 (Load, Save, Reset are default buttons.)
void OnSave ()
 (Load, Save, Reset are default buttons.)
void OnReset ()
 (Load, Save, Reset are default buttons.)
float Exponent (float f)
 Callback of type CONVERTER.
void OnChangeCubeMap ()
 Actions to be taken when the cubemaps get invalid. Callback of type ONCHANGE_CALLBACK.
void OnChangeMesh ()
 Actions to be taken when the central mesh object is changed. Callback of type ONCHANGE_CALLBACK.
void OnChangeMeshSize ()
 Actions to be taken when the size of the central mesh is to change. Callback of type ONCHANGE_CALLBACK.
void OnChangeShininess ()
 Actions to be taken when the shininess is to change. Callback of type ONCHANGE_CALLBACK.
void OnChangeResolution ()
 Actions to be taken when the resolution is to change. Callback of type ONCHANGE_CALLBACK.

Variables

const int WIDTH = 800
 screen width
const int HEIGHT = 800
 screen height
const int CHARBUFFER_SIZE = 200
 length of the buffer (one line to be saved to file)
IDirect3DDevice9 * g_pd3dDevice
 THE D3D DEVICE.
ID3DXEffect * g_pEffect
 THE EFFECT FILE.
EnvMapenvmapRenderer
 PROBLEM-SPECIFIC CLASS.
Parameters pp
 HELPER CLASS TO MANAGE VARIOUS PARAMETERS.
CDXUTDialogResourceManager g_DialogResourceManager
 Manager for shared resources of dialogs.
CD3DSettingsDlg g_SettingsDlg
 Device settings dialog.
CDXUTDialog g_HUD
 Dialog for sample specific controls.
ID3DXFont * g_pFont
 Font for drawing text.
ID3DXSprite * g_pTextSprite
 Sprite for batching draw text calls.
IDirect3DSurface9 * g_pSaveSurface
 surface for screenshot capturing
bool bSavingScreenshot = false
 boolean for screenshot capturing
int counter = 0
 counter for screenshots (see GenerateNewFileName())
HRESULT hr
CModelViewerCamera camera
 the camera


Detailed Description

Performs DirectX initialization via DXUT callback functions. Adds some additional helper functions to support screenshot capturing.

Author:
Istvan Lazanyi, TU Budapest
Date:
2006-04-26

Define Documentation

#define FX_FILENAME   L"EnvMap.fx"
 

File containing the shader code.


Function Documentation

float Exponent float  f  ) 
 

Callback of type CONVERTER.

int GenerateNewFileName int &  counter  ) 
 

Generates a non-existing filename to store the screenshot in the shots directory.

Generated file names are shots/000.png, shots/001.png, ...

void InitParams  ) 
 

Defines application-specific parameters and creates GUI controls (sliders, checkboxes) for them. Finally, loads initial values for the parameters from file called .params0 (Reset). Use Parameters::Add to create GUI controls.

bool CALLBACK IsDeviceAcceptable D3DCAPS9 *  pCaps,
D3DFORMAT  AdapterFormat,
D3DFORMAT  BackBufferFormat,
bool  bWindowed,
void *  pUserContext
 

DXUT callback (Rejects any devices that aren't acceptable by returning false).

DXUT callback. Rejects any devices that aren't acceptable by returning false.

void CALLBACK KeyboardProc UINT  nChar,
bool  bKeyDown,
bool  bAltDown,
void *  pUserContext
 

DXUT callback (Keystroke messages).

void LoadCameraPosition char *  fileName  ) 
 

Loads camera settings from file.

Loads camera settings (world matrix and camera position) from an existing file. Useful when capturing multiple screenshots from the same view.

Parameters:
fileName the name of the file to load from.

bool CALLBACK ModifyDeviceSettings DXUTDeviceSettings *  pDeviceSettings,
const D3DCAPS9 *  pCaps,
void *  pUserContext
 

DXUT callback (Before a device is created, modifies the device settings as needed).

LRESULT CALLBACK MsgProc HWND  hWnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
bool *  pbNoFurtherProcessing,
void *  pUserContext
 

DXUT callback (Message processing).

Forwards messages to the DirectX settings window, the GUI controls or the camera, respecively.

void OnChangeCubeMap  ) 
 

Actions to be taken when the cubemaps get invalid. Callback of type ONCHANGE_CALLBACK.

void OnChangeMesh  ) 
 

Actions to be taken when the central mesh object is changed. Callback of type ONCHANGE_CALLBACK.

void OnChangeMeshSize  ) 
 

Actions to be taken when the size of the central mesh is to change. Callback of type ONCHANGE_CALLBACK.

void OnChangeResolution  ) 
 

Actions to be taken when the resolution is to change. Callback of type ONCHANGE_CALLBACK.

void OnChangeShininess  ) 
 

Actions to be taken when the shininess is to change. Callback of type ONCHANGE_CALLBACK.

HRESULT CALLBACK OnCreateDevice IDirect3DDevice9 *  pd3dDevice,
const D3DSURFACE_DESC *  pBackBufferSurfaceDesc,
void *  pUserContext
 

DXUT callback (You should create any D3DPOOL_MANAGED resources here).

Compiles the effect file (EnvMap.fx) and displays error message if compilation fails. Finally, forwards call to EnvMap::OnCreateDevice.

void CALLBACK OnDestroyDevice void *  pUserContext  ) 
 

DXUT callback (You should release resources created in the OnCreateDevice callback here).

Forwards call to EnvMap::OnDestroyDevice.

void CALLBACK OnFrameMove IDirect3DDevice9 *  g_pd3dDevice,
double  fTime,
float  fElapsedTime,
void *  pUserContext
 

DXUT callback (Handle updates to the scene).

void CALLBACK OnFrameRender IDirect3DDevice9 *  g_pd3dDevice,
double  fTime,
float  fElapsedTime,
void *  pUserContext
 

DXUT callback (Render the scene). Also responsible for screenshot taking.

If a screenshot is being taken (bSavingScreenshot), sets g_pSaveSurface as the render target and saves it to a non-existent file (GenerateNewFileName()). Also saves current camera parameters (SaveCameraPosition()).

To perform actual rendering, it forwards call to EnvMap::OnFrameRender with current camera matrices.

void CALLBACK OnGUIEvent UINT  nEvent,
int  nControlID,
CDXUTControl *  pControl,
void *  pUserContext
 

DXUT callback (called by the framework in case of GUI events). Forwards GUI event to the parameter-manager class Parameters (see pp).

Parameters:
nControlID id of the adjusted GUI control

void OnLoad  ) 
 

(Load, Save, Reset are default buttons.)

void CALLBACK OnLostDevice void *  pUserContext  ) 
 

DXUT callback (You should release resources created in the OnResetDevice callback here).

void OnReset  ) 
 

(Load, Save, Reset are default buttons.)

HRESULT CALLBACK OnResetDevice IDirect3DDevice9 *  g_pd3dDevice,
const D3DSURFACE_DESC *  pBackBufferSurfaceDesc,
void *  pUserContext
 

DXUT callback (You should create any D3DPOOL_DEFAULT resources here).

Resets camera and HUD elements. Initializes g_pSaveSurface according to the current screen resolution. Then it forwards call to EnvMap::OnResetDevice.

void OnSave  ) 
 

(Load, Save, Reset are default buttons.)

void RenderText  ) 
 

Renders help and statistics text and displays algorithmic-specific parameters.

  • Statistics: FPS value, screen resolution

  • Help: displays avaliable keyboard shortcuts after the user presses F1.

  • Algorithmic-specific parameters: describes the currently selected method and displays its most important parameters.

void SaveCameraPosition char *  fileName  ) 
 

Writes current camera settings to file.

Writes current camera settings (world matrix and camera position) to file. Useful when capturing multiple screenshots from the same view.

Parameters:
fileName the name of the file to be created

INT WINAPI WinMain HINSTANCE  ,
HINSTANCE  ,
LPSTR  ,
int 
 

Entry point to the program.

Initializes everything and goes into a message processing loop. Idle time is used to render the scene.


Variable Documentation

bool bSavingScreenshot = false
 

boolean for screenshot capturing

CModelViewerCamera camera
 

the camera

const int CHARBUFFER_SIZE = 200
 

length of the buffer (one line to be saved to file)

int counter = 0
 

counter for screenshots (see GenerateNewFileName())

EnvMap* envmapRenderer
 

PROBLEM-SPECIFIC CLASS.

CDXUTDialogResourceManager g_DialogResourceManager
 

Manager for shared resources of dialogs.

CDXUTDialog g_HUD
 

Dialog for sample specific controls.

IDirect3DDevice9* g_pd3dDevice
 

THE D3D DEVICE.

ID3DXEffect* g_pEffect
 

THE EFFECT FILE.

ID3DXFont* g_pFont
 

Font for drawing text.

IDirect3DSurface9* g_pSaveSurface
 

surface for screenshot capturing

ID3DXSprite* g_pTextSprite
 

Sprite for batching draw text calls.

CD3DSettingsDlg g_SettingsDlg
 

Device settings dialog.

const int HEIGHT = 800
 

screen height

HRESULT hr
 

Parameters pp
 

HELPER CLASS TO MANAGE VARIOUS PARAMETERS.

const int WIDTH = 800
 

screen width


Generated on Wed Aug 23 00:00:39 2006 for Indirect Environment Mapping by  doxygen 1.4.2