为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

游戏2D图片场景

2017-11-18 5页 doc 22KB 26阅读

用户头像

is_281650

暂无简介

举报
游戏2D图片场景游戏2D图片场景 / WinMain.cpp Chapter 2 Billboard Demo Required libraries: D3D9.LIB and D3DX9.LIB / // Include files include include include d3d9.h include d3dx9.h // Window handles class and caption text HWND g_hWnd HINSTANCE g_hInst static char g_szClass BillboardClass ...
游戏2D图片场景
游戏2D图片场景 / WinMain.cpp Chapter 2 Billboard Demo Required libraries: D3D9.LIB and D3DX9.LIB / // Include files include include include d3d9.h include d3dx9.h // Window handles class and caption text HWND g_hWnd HINSTANCE g_hInst static char g_szClass BillboardClass static char g_szCaption Billboard Demo // The Direct3D and Device object IDirect3D9 g_pD3D NULL IDirect3DDevice9 g_pD3DDevice NULL // The 3D vertex format and descriptor typedef struct FLOAT x y z // 3D coordinates FLOAT u v // Texture coordinates s3DVertex define FVF3D D3DFVF_XYZ D3DFVF_TEX1 // The billboard vertex buffer and texture IDirect3DVertexBuffer9 g_pBillboardVB NULL IDirect3DTexture9 g_pBillboardTexture NULL // The floor vertex buffer and texture IDirect3DVertexBuffer9 g_pFloorVB NULL IDirect3DTexture9 g_pFloorTexture NULL // Function prototypes int PASCAL WinMainHINSTANCE hInst HINSTANCE hPrev LPSTR szCmdLine int nCmdShow long FAR PASCAL WindowProcHWND hWnd UINT uMsg WPARAM wParam LPARAM lParam BOOL DoInit BOOL DoShutdown BOOL DoFrame BOOL SetupMeshes int PASCAL WinMainHINSTANCE hInst HINSTANCE hPrev LPSTR szCmdLine int nCmdShow WNDCLASSEX wcex MSG Msg g_hInst hInst // Create the window class here and register it wcex.cbSize sizeofwcex wcex.style CS_CLASSDC wcex.lpfnWndProc WindowProc wcex.cbClsExtra 0 wcex.cbWndExtra 0 wcex.hInstance hInst wcex.hIcon LoadIconNULL IDI_APPLICATION wcex.hCursor LoadCursorNULL IDC_ARROW wcex.hbrBackground NULL wcex.lpszMenuName NULL wcex.lpszClassName g_szClass wcex.hIconSm LoadIconNULL IDI_APPLICATION ifRegisterClassExwcex return FALSE // Create the Main Window g_hWnd CreateWindowg_szClass g_szCaption WS_CAPTION WS_SYSMENU 0 0 400 400 NULL NULL hInst NULL ifg_hWnd return FALSE ShowWindowg_hWnd SW_NORMAL UpdateWindowg_hWnd // Run init function and return on error ifDoInit FALSE return FALSE // Start message pump waiting for signal to quit ZeroMemoryMsg sizeofMSG whileMsg.message WM_QUIT ifPeekMessageMsg NULL 0 0 PM_REMOVE TranslateMessageMsg DispatchMessageMsg ifDoFrame FALSE break // Run shutdown function DoShutdown UnregisterClassg_szClass hInst return Msg.wParam long FAR PASCAL WindowProcHWND hWnd UINT uMsg WPARAM wParam LPARAM lParam switchuMsg case WM_DESTROY: PostQuitMessage0 return 0 return DefWindowProchWnd uMsg wParam lParam BOOL DoInit D3DPRESENT_PARAMETERS d3dpp D3DDISPLAYMODE d3ddm D3DXMATRIX matView matProj // Do a windowed mode initialization of Direct3D ifg_pD3D Direct3DCreate9D3D_SDK_VERSION NULL return FALSE ifFAILEDg_pD3D-GetAdapterDisplayModeD3DADAPTER_DEFAULT d3ddm return FALSE ZeroMemoryd3dpp sizeofd3dpp d3dpp.Windowed TRUE d3dpp.SwapEffect D3DSWAPEFFECT_DISCARD d3dpp.BackBufferFormat d3ddm.Format d3dpp.EnableAutoDepthStencil TRUE d3dpp.AutoDepthStencilFormat D3DFMT_D16 ifFAILEDg_pD3D-CreateDeviceD3DADAPTER_DEFAULT D3DDEVTYPE_HAL g_hWnd D3DCREATE_SOFTWARE_VERTEXPROCESSING d3dpp g_pD3DDevice return FALSE // Set the render states g_pD3DDevice-SetRenderStateD3DRS_LIGHTING FALSE g_pD3DDevice-SetRenderStateD3DRS_ZENABLE D3DZB_TRUE g_pD3DDevice-SetRenderStateD3DRS_ALPHABLENDENABLE FALSE g_pD3DDevice-SetRenderStateD3DRS_ALPHAREF 0x01 g_pD3DDevice-SetRenderStateD3DRS_ALPHAFUNC D3DCMP_GREATEREQUAL // Create and set the projection transformation D3DXMatrixPerspectiveFovLHmatProj D3DX_PI/4 1.0f 1.0f 1000.0f g_pD3DDevice-SetTransformD3DTS_PROJECTION matProj // Create the meshes SetupMeshes return TRUE BOOL DoShutdown // Release textures and vertex buffers ifg_pBillboardTexture NULL g_pBillboardTexture-Release ifg_pBillboardVB NULL g_pBillboardVB-Release ifg_pFloorTexture NULL g_pFloorTexture-Release ifg_pFloorVB NULL g_pFloorVB-Release // Release device and 3D objects ifg_pD3DDevice NULL g_pD3DDevice-Release ifg_pD3D NULL g_pD3D-Release return TRUE BOOL DoFrame D3DXMATRIX matView matWorld float Angle short i j // Clear device backbuffer g_pD3DDevice-Clear0 NULL D3DCLEAR_TARGET D3DCLEAR_ZBUFFER D3DCOLOR_RGBA064128255 1.0f 0 // Update the view position Angle floattimeGetTime / 2000.0f D3DXMatrixLookAtLHmatView D3DXVECTOR3floatcosAngle 200.0f 200.0f floatsinAngle 200.0f D3DXVECTOR30.0f 0.0f 0.0f D3DXVECTOR30.0f 1.0f 0.0f g_pD3DDevice-SetTransformD3DTS_VIEW matView ifSUCCEEDEDg_pD3DDevice-BeginScene // Draw the floor g_pD3DDevice-SetStreamSource0 g_pFloorVB 0 sizeofs3DVertex g_pD3DDevice-SetFVFFVF3D g_pD3DDevice-SetTexture0 g_pFloorTexture D3DXMatrixIdentitymatWorld g_pD3DDevice-SetTransformD3DTS_WORLD matWorld g_pD3DDevice-DrawPrimitiveD3DPT_TRIANGLESTRIP 0 2 // Draw the billboards g_pD3DDevice-SetStreamSource0 g_pBillboardVB 0 sizeofs3DVertex g_pD3DDevice-SetTexture0 g_pBillboardTexture g_pD3DDevice-SetRenderStateD3DRS_ALPHATESTENABLE TRUE D3DXMatrixTransposematWorld matView fori0iDrawPrimitiveD3DPT_TRIANGLESTRIP 0 2 g_pD3DDevice-SetRenderStateD3DRS_ALPHATESTENABLE FALSE // Clear the texture usage g_pD3DDevice-SetTexture0 NULL // End the scene g_pD3DDevice-EndScene // Display the scene g_pD3DDevice-PresentNULL NULL NULL NULL return TRUE BOOL SetupMeshes BYTE Ptr s3DVertex BillboardVerts4 -42.0f 80.0f 0.0f 0.0f 0.0f 40.0f 80.0f 0.0f 1.0f 0.0f -40.0f 0.0f 0.0f 0.0f 1.0f 40.0f 0.0f 0.0f 1.0f 1.0f s3DVertex FloorVerts4 -100.0f 0.0f 100.0f 0.0f 0.0f 100.0f 0.0f 100.0f 1.0f 0.0f -100.0f 0.0f -100.0f 0.0f 1.0f 100.0f 0.0f -100.0f 1.0f 1.0f // Create vertex buffers and stuff in data // Billboard ifFAILEDg_pD3DDevice-CreateVertexBuffer sizeofBillboardVerts 0 FVF3D D3DPOOL_DEFAULT g_pBillboardVB NULL return FALSE ifFAILEDg_pBillboardVB-Lock00 voidPtr 0 return FALSE memcpyPtr BillboardVerts sizeofBillboardVerts g_pBillboardVB-Unlock // Floor ifFAILEDg_pD3DDevice-CreateVertexBuffer sizeofFloorVerts 0 FVF3D D3DPOOL_DEFAULT g_pFloorVB NULL return FALSE ifFAILEDg_pFloorVB-Lock00 voidPtr 0 return FALSE memcpyPtr FloorVerts sizeofFloorVerts g_pFloorVB-Unlock // Get textures D3DXCreateTextureFromFileg_pD3DDevice Floor.bmp g_pFloorTexture D3DXCreateTextureFromFileExg_pD3DDevice Billboard.bmp D3DX_DEFAULT D3DX_DEFAULT D3DX_DEFAULT 0 D3DFMT_A1R5G5B5 D3DPOOL_MANAGED D3DX_FILTER_TRIANGLE D3DX_FILTER_TRIANGLE D3DCOLOR_RGBA000255 NULL NULL g_pBillboardTexture return TRUE
/
本文档为【游戏2D图片场景】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索