tailieunhanh - Beginning Game Programming (phần 4)

Tham khảo tài liệu 'beginning game programming (phần 4)', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 130 Chapter 7 Drawing Animated Sprites Figure The Anim_Sprite project now includes . int Init_Direct3D HWND hwnd int width int height int fullscreen initialize Direct3D d3d Direct3DCreate9 D3D_SDK_VERSION if d3d NULL MessageBox hwnd Error initializing Direct3D Error MB_OK return 0 set Direct3D presentation parameters D3DPRESENT_PARAMETERS d3dpp ZeroMemory d3dpp sizeof d3dpp fullscreen Drawing Animated Sprites 131 D3DSWAPEFFECT_COPY D3DFMT_X8R8G8B8 1 width height hwnd TRUE D3DFMT_D16 D3DPRESENT_INTERVAL_IMMEDIATE create Direct3D device d3d- CreateDevice D3DADAPTER_DEFAULT D3DDEVTYPE_HAL hwnd D3DCREATE_SOFTWARE_VERTEXPROCESSING d3dpp d3ddev if d3ddev NULL MessageBox hwnd Error creating Direct3D device Error MB_OK return 0 clear the backbuffer to black d3ddev- Clear 0 NULL D3DCLEAR_TARGET D3DCOLOR_XRGB 0 0 0 0 create pointer to the back buffer d3ddev- GetBackBuffer 0 0 D3DBACKBUFFER_TYPE_MONO backbuffer return 1 LPDIRECT3DSURFACE9 LoadSurface char filename D3DCOLOR transcolor LPDIRECT3DSURFACE9 image NULL D3DXIMAGE_INFO info HRESULT result get width and height from bitmap file result D3DXGetImageInfoFromFile filename info if result D3D_OK return NULL 132 Chapter 7 Drawing Animated Sprites create surface result d3ddev- CreateOffscreenPlainSurface D3DFMT_X8R8G8B8 D3DPOOL_DEFAULT image NULL width of the surface height of the surface surface format memory pool to use pointer to the surface reserved always NULL if result D3D_OK return NULL load surface from file into newly created surface result D3DXLoadSurfaceFromFile image NULL NULL filename NULL D3DX_DEFAULT transcolor NULL destination surface destination palette destination rectangle source filename source rectangle controls how image is filtered for .