Main Page | Class List | Directories | 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"

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).
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.
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 ()
void OnSave ()
void OnReset ()
float Exponent (float f)
void OnChangeCubeMap ()
void OnChangeShininess ()
IDirect3DTexture9 * CreateTexture (int size, D3DFORMAT Format)
 Util function. Creates an empty texture that shall be used as render target.
IDirect3DCubeTexture9 * CreateCubeTexture (int size, D3DFORMAT Format)
 Util function. Creates an empty cubemap texture that shall be used as render target.

Variables

const int WIDTH = 640
const int HEIGHT = 640
const int CHARBUFFER_SIZE = 200
IDirect3DDevice9 * g_pd3dDevice
ID3DXEffect * g_pEffect
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
EnvMapenvmapRenderer = new EnvMap()
 problem-specific stuff
Parameters pp
 managing parameters of the algorithm
CModelViewerCamera camera
 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

Function Documentation

IDirect3DCubeTexture9* CreateCubeTexture int  size,
D3DFORMAT  Format
 

Util function. Creates an empty cubemap texture that shall be used as render target.

Parameters:
size size of the new texture
format format of the new texture (eg. D3DFMT_A32B32G32R32F)

IDirect3DTexture9* CreateTexture int  size,
D3DFORMAT  Format
 

Util function. Creates an empty texture that shall be used as render target.

Note that render targets (D3DUSAGE_RENDERTARGET) must be created in the default memory pool (D3DPOOL_DEFAULT).

Parameters:
size size of the new texture
format format of the new texture (eg. D3DFMT_A32B32G32R32F)

float Exponent float  f  ) 
 

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).

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  ) 
 

void OnChangeShininess  ) 
 

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).

void OnLoad  ) 
 

void CALLBACK OnLostDevice void *  pUserContext  ) 
 

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

void OnReset  ) 
 

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  ) 
 

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
 

camera

const int CHARBUFFER_SIZE = 200
 

int counter = 0
 

counter for screenshots (see GenerateNewFileName())

EnvMap* envmapRenderer = new EnvMap()
 

problem-specific stuff

CDXUTDialogResourceManager g_DialogResourceManager
 

Manager for shared resources of dialogs.

CDXUTDialog g_HUD
 

Dialog for sample specific controls.

IDirect3DDevice9* g_pd3dDevice
 

ID3DXEffect* g_pEffect
 

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 = 640
 

HRESULT hr
 

Parameters pp
 

managing parameters of the algorithm

const int WIDTH = 640
 


Generated on Thu Apr 27 11:58:00 2006 for gyak by  doxygen 1.4.2