1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
//-----------------------------------------------------------------------------
// Nom: main.cpp
// Date: 09/04/07
// Description: Initialisation Direct 3D
//-----------------------------------------------------------------------------
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <d3dx9.h>
#define SCREEN_WIDTH 1024
#define SCREEN_HEIGHT 768
//-----------------------------------------------------------------------------
// Déclarations globales
//-----------------------------------------------------------------------------
HDC hdc;
HWND hwnd;
MSG uMsg;
LPDIRECT3D9 D3D = NULL;
LPDIRECT3DDEVICE9 D3DDevice = NULL;
//-----------------------------------------------------------------------------
// PROTOTYPES
//-----------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow);
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void Init ();
void Render ();
void ShutDown ();
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Point d'entrée du programme
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
WNDCLASSEX winClass;
memset(&uMsg,0,sizeof(uMsg));
winClass.lpszClassName = "MY_WINDOWS_CLASS"; // The name of our new window class
winClass.cbSize = sizeof(WNDCLASSEX); // Specifies the size, in bytes, of this structure
winClass.style = CS_HREDRAW | CS_VREDRAW; // Specifies the class style(s)
winClass.lpfnWndProc = WindowProc; // The name of our call back function
winClass.hInstance = hInstance; // Instance of this application
winClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // Don't set any icons
winClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // We'll use the defaults
winClass.hCursor = LoadCursor(NULL, IDC_ARROW); // Use the standard arrow cursor
winClass.hbrBackground = NULL; // Fill client-area with black
winClass.lpszMenuName = NULL; // Our application has no menu
winClass.cbClsExtra = 0; // Specifies the number of extra bytes to allocate following the window-class structure
winClass.cbWndExtra = 0; // Specifies the number of extra bytes to allocate following the window instance
if( RegisterClassEx( &winClass) == 0 )
return E_FAIL;
hwnd = CreateWindowEx( NULL, // Extended Styles (If Any)
"MY_WINDOWS_CLASS", // Class Identifier
"Game", // Application Title
WS_EX_TOPMOST | WS_POPUP, // Window properties
0,0, // Initial x,y position of the window's upper-left corner
SCREEN_WIDTH, SCREEN_HEIGHT, // Window width and height
NULL, // Handle to parent (If Any)
NULL, // Handle to menu (If Any)
hInstance, // Instance of this application
NULL ); // Extra creation parameters (If Any)
if( hwnd == NULL )
return E_FAIL;
ShowWindow( hwnd, nCmdShow );
UpdateWindow( hwnd );
Init ();
while( uMsg.message != WM_QUIT )
{
if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &uMsg );
DispatchMessage( &uMsg );
}
else
Render();
}
ShutDown ();
UnregisterClass( "MY_WINDOWS_CLASS", winClass.hInstance );
return 0;
}
//-----------------------------------------------------------------------------
// Name: WindowProc()
// Desc: Structure de gestions des messages Windows
//-----------------------------------------------------------------------------
LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam ) // second message parameter
{
switch( uMsg )
{
case WM_KEYDOWN:
{
switch( wParam )
{
case VK_ESCAPE:
PostQuitMessage(0);
break;
}
}
break;
case WM_CREATE:
{
}
break;
case WM_CLOSE:
{
DestroyWindow( hwnd );
}
case WM_DESTROY:
{
PostQuitMessage(0);
}
break;
default:
{
return DefWindowProc( hwnd, uMsg, wParam, lParam );
}
break;
}
return 0;
}
//-----------------------------------------------------------------------------
// Name: Init()
// Desc: This is where we'll initialize and setup OpenGL/Direct3D.
// This function will only be called once.
//-----------------------------------------------------------------------------
void Init( void )
{
D3D = Direct3DCreate9 (D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferWidth = SCREEN_WIDTH;
d3dpp.BackBufferHeight = SCREEN_HEIGHT;
D3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &D3DDevice );
D3DXMATRIX matWorld;
D3DXMatrixRotationY( &matWorld, timeGetTime()/150.0f );
D3DDevice>SetTransform( D3DTS_WORLD, &matWorld );
D3DXVECTOR3 vEyePt ( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUpVec ( 0.0f, 1.0f, 0.0f );
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
D3DDevice->SetTransform( D3DTS_VIEW, &matView );
D3DXMATRIX matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
D3DDevice->SetTransform( D3DTS_PROJECTION, &matProj );
LPD3DXSPRITE sprite = NULL;
LPDIRECT3DTEXTURE9 texture;
D3DXCreateSprite(&D3DDevice, &sprite);
D3DXCreateTextureFromFile (&D3DDevice, "image.bmp", &texture);
}
//-----------------------------------------------------------------------------
// Name: ShutDown()
// Desc: This is where we'll cleanup and shutdown OpenGL/Direct3D.
// This function will only be called once.
//-----------------------------------------------------------------------------
void ShutDown( void )
{
sprite->Release;
texture->Release;
}
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: This is where we'll actually use OpenGL/Direct3D to render to the
// frame buffer.
//-----------------------------------------------------------------------------
void Render( void )
{
D3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255,128,0), 1.0f, 0 );
D3DDevice->BeginScene();
//**********************************************************************************
D3DXVECTOR3 center(0.0f, 0.0f, 0.0f); // center at the upper-left corner
D3DXVECTOR3 position(50.0f, 50.0f, 0.0f); // position at 50, 50 with no depth
sprite->Draw(&texture, NULL, ¢er, &position, D3DCOLOR_XRGB(255, 255, 255));
//**********************************************************************************
D3DDevice->EndScene();
D3DDevice->Present( NULL, NULL, NULL, NULL );
} |
Partager