source: GTP-Internal/trunk/App/Demos/Illum/Ocean/Ocean.cpp @ 1777

Revision 1777, 6.1 KB checked in by szirmay, 18 years ago (diff)
Line 
1//--------------------------------------------------------------------------------------
2// File: Ocean.cpp
3//
4// Empty starting point for new Direct3D applications
5//
6// Copyright (c) Microsoft Corporation. All rights reserved.
7//--------------------------------------------------------------------------------------
8#include "dxstdafx.h"
9#include "resource.h"
10
11#include "OceanEffect.h"
12
13OceanEffect* oceanEffect = NULL;
14
15//--------------------------------------------------------------------------------------
16// Rejects any devices that aren't acceptable by returning false
17//--------------------------------------------------------------------------------------
18bool CALLBACK IsDeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat,
19                                  D3DFORMAT BackBufferFormat, bool bWindowed, void* pUserContext )
20{
21    // Typically want to skip backbuffer formats that don't support alpha blending
22    IDirect3D9* pD3D = DXUTGetD3DObject();
23    if( FAILED( pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType,
24                    AdapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING,
25                    D3DRTYPE_TEXTURE, BackBufferFormat ) ) )
26        return false;
27
28    return true;
29}
30
31
32//--------------------------------------------------------------------------------------
33// Before a device is created, modify the device settings as needed
34//--------------------------------------------------------------------------------------
35bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, const D3DCAPS9* pCaps, void* pUserContext )
36{
37        pDeviceSettings->pp.Flags &= ~D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
38    return true;
39}
40
41
42//--------------------------------------------------------------------------------------
43// Create any D3DPOOL_MANAGED resources here
44//--------------------------------------------------------------------------------------
45HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
46{
47
48    return S_OK;
49}
50
51
52//--------------------------------------------------------------------------------------
53// Create any D3DPOOL_DEFAULT resources here
54//--------------------------------------------------------------------------------------
55HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice,
56                                const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
57{
58        oceanEffect = new OceanEffect(pd3dDevice);
59    return S_OK;
60}
61
62
63//--------------------------------------------------------------------------------------
64// Handle updates to the scene
65//--------------------------------------------------------------------------------------
66void CALLBACK OnFrameMove( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
67{
68        if(oceanEffect)
69                oceanEffect->move(fTime, fElapsedTime);
70}
71
72
73//--------------------------------------------------------------------------------------
74// Render the scene
75//--------------------------------------------------------------------------------------
76void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
77{
78    HRESULT hr;
79
80    // Clear the render target and the zbuffer
81    V( pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 45, 50, 170), 1.0f, 0) );
82
83    // Render the scene
84        if(oceanEffect)
85                oceanEffect->render();
86}
87
88
89//--------------------------------------------------------------------------------------
90// Handle messages to the application
91//--------------------------------------------------------------------------------------
92LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
93                          bool* pbNoFurtherProcessing, void* pUserContext )
94{
95        if(oceanEffect)
96                oceanEffect->message(hWnd, uMsg, wParam, lParam);
97    return 0;
98}
99
100
101//--------------------------------------------------------------------------------------
102// Release resources created in the OnResetDevice callback here
103//--------------------------------------------------------------------------------------
104void CALLBACK OnLostDevice( void* pUserContext )
105{
106        delete oceanEffect;
107        oceanEffect = NULL;
108}
109
110
111//--------------------------------------------------------------------------------------
112// Release resources created in the OnCreateDevice callback here
113//--------------------------------------------------------------------------------------
114void CALLBACK OnDestroyDevice( void* pUserContext )
115{
116
117}
118
119
120
121//--------------------------------------------------------------------------------------
122// Initialize everything and go into a render loop
123//--------------------------------------------------------------------------------------
124INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
125{
126    // Enable run-time memory check for debug builds.
127#if defined(DEBUG) | defined(_DEBUG)
128    _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
129#endif
130
131    // Set the callback functions
132    DXUTSetCallbackDeviceCreated( OnCreateDevice );
133    DXUTSetCallbackDeviceReset( OnResetDevice );
134    DXUTSetCallbackDeviceLost( OnLostDevice );
135    DXUTSetCallbackDeviceDestroyed( OnDestroyDevice );
136    DXUTSetCallbackMsgProc( MsgProc );
137    DXUTSetCallbackFrameRender( OnFrameRender );
138    DXUTSetCallbackFrameMove( OnFrameMove );
139   
140    // TODO: Perform any application-level initialization here
141
142    // Initialize DXUT and create the desired Win32 window and Direct3D device for the application
143    DXUTInit( true, true, true ); // Parse the command line, handle the default hotkeys, and show msgboxes
144    DXUTSetCursorSettings( true, true ); // Show the cursor and clip it when in full screen
145    DXUTCreateWindow( L"Ocean" );
146    DXUTCreateDevice( D3DADAPTER_DEFAULT, true, 640, 480, IsDeviceAcceptable, ModifyDeviceSettings );
147
148    // Start the render loop
149    DXUTMainLoop();
150
151    // TODO: Perform any application-level cleanup here
152
153    return DXUTGetExitCode();
154}
155
156
Note: See TracBrowser for help on using the repository browser.